From f6b077a30a1fcf196a67dcbf5152faaf809ff554 Mon Sep 17 00:00:00 2001 From: Ishuah Kariuki Date: Mon, 27 May 2019 19:10:44 +0300 Subject: [PATCH 1/2] Update README.md --- README.md | 39 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index dac713a..cbe80b9 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,41 @@ # preact-rails Preact integration for Ruby on Rails. -Under active development. +## Getting started + +1. Add `webpacker` and `preact-rails` to your Gemfile +``` +gem 'webpacker' +gem 'preact-rails' +``` +2. Install the gems by running `bundle install` +3. Install the Preact UJS driver by running `yarn add preact_ujs` or `npm i preact_ujs` +4. Include your Preact components in your application.js + Update `app/javascript/packs/application.js`, add the following lines: + ``` + var componentRequireContext = require.context("components", true); + var PreactRailsUJS = require("preact_ujs"); + + PreactRailsUJS.useContext(componentRequireContext) + ``` +5. Create the directory `app/javascript/components`. That's where your Preact components will reside. +6. Create your first Preact component - create the file `app/javascript/components/Button.js` and add the following lines: + ``` + import { h, Component } from "preact" + + class Button extends Component { + render (props, state) { + return ( + + ); + } + } + + export default Button + ``` + 7. Link the javascript Pack in Rails, add `<%= javascript_pack_tag 'application' %>` to `app/views/layouts/application.html.erb` + 8. Render your Preact component in a view + ``` + <%= preact_component('Button', { type: 'submit', label: 'Get started!'}) %> + ``` + From e5f7a9b1bee5e938b58f90fad7ca5f7243510b7f Mon Sep 17 00:00:00 2001 From: Ishuah Kariuki Date: Mon, 27 May 2019 19:13:15 +0300 Subject: [PATCH 2/2] Create README.md --- preact_ujs/README.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 preact_ujs/README.md diff --git a/preact_ujs/README.md b/preact_ujs/README.md new file mode 100644 index 0000000..e846009 --- /dev/null +++ b/preact_ujs/README.md @@ -0,0 +1,12 @@ +# Preact UJS + +UJS driver for [preact-rails](https://github.com/UseHover/preact-rails). + +## Install +``` +npm i preact_ujs +``` +or +``` +yarn add preact_ujs +```