You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/installation/installation.md
+32-16Lines changed: 32 additions & 16 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -58,7 +58,7 @@ gem 'rails-hyperstack',
58
58
59
59
These are the steps to manually install Hyperstack in an existing Rails app:
60
60
61
-
+ Insure yarn is loaded
61
+
1. Insure yarn is loaded
62
62
+ Add the gems
63
63
+ Update the `application.js` file
64
64
+ Add the `hyperstack` directories
@@ -256,7 +256,7 @@ included) in the asset manifest.
256
256
The `on_error` method defines what you want to do when errors occur. In production
257
257
you will may want to direct the output to a dedicated log file for example.
258
258
259
-
### Integrate with webpacker
259
+
### 9. Integrate with webpacker
260
260
261
261
The Rails webpacker gem will bundle up all your javascript assets including those used by Hyperstack such as React, and React-Router.
262
262
@@ -275,7 +275,7 @@ Once you have the pack files setup you will also need to fetch the packages, plu
275
275
>
276
276
> In the JS world its a two part process. Yarn fetches packages and their dependents, and maintains a `yarn.lock` file. The pack files specify how to package up the JS code, making it ready for delivery to the client.
277
277
278
-
#### Add the `client_and_server.js` pack file
278
+
#####Add the `client_and_server.js` pack file
279
279
280
280
* Note that this goes in a new directory: `app/javascripts/packs` *
// to add additional NPM packages run add yarn package-name@version
291
291
// then add the require here.
292
292
```
293
-
#### Add the `client_only.js` pack file
293
+
#####Add the `client_only.js` pack file
294
294
295
295
```javascript
296
296
//app/javascript/packs/client_only.js
@@ -301,7 +301,7 @@ jQuery = require('jquery');
301
301
// then add the require here.
302
302
```
303
303
304
-
#### Add the packages using `yarn`
304
+
#####Add the packages using `yarn`
305
305
306
306
First you need make sure you have `yarn` installed:
307
307
[Yarn install for any system](https://yarnpkg.com/en/docs/install)
@@ -317,13 +317,25 @@ yarn add react_ujs@^2.5.0
317
317
yarn add jquery@^3.4.1
318
318
```
319
319
320
-
And now you are good to go. In the future if you want to add a new package like [react-datepicker](https://reactdatepicker.com/), you would run
321
-
322
-
`yarn add react-datepicker`
320
+
And now you are good to go.
323
321
322
+
>One of the great things about Hyperstack is that while you can code in Ruby, you have access to the thousands of predefined react component libraries.
323
+
>
324
+
>For example if you want to add a new package like [react-datepicker](https://reactdatepicker.com/), you would run
325
+
```text
326
+
yarn add react-datepicker
327
+
```
328
+
> and then add
329
+
```javascript
330
+
DatePicker =require('jquery'); // bring in the component
331
+
require("react-datepicker/dist/react-datepicker.css"); // bring in the styles
332
+
```
333
+
> to the `client_only.js` pack file. *Note that DatePicker can only be sensibly run on the client, as time on the client will be different from the server.*
334
+
>
335
+
>Finally you will have to run `bin/webpack` to rebuild everything
324
336
325
337
326
-
### Add the Hyperstack engine to the routes file
338
+
### 10. Add the Hyperstack engine to the routes file
327
339
328
340
At the beginning of the `config/routes.rb` file mount the Hyperstack engine:
329
341
@@ -337,7 +349,7 @@ Rails.application.routes.draw do
337
349
end
338
350
```
339
351
340
-
You can mount the engine under any name you please. All of internal Hyperstack requests will be prefixed with that mount point.
352
+
You can mount the engine under any name you please. All of internal Hyperstack requests will be prefixed with whatever name you use.
341
353
342
354
>Note: You can also directly ask Hyperstack to mount your top level components
343
355
via the routes file. For example
@@ -347,13 +359,17 @@ Rails.application.routes.draw do
347
359
get '/(*other)', to:'hyperstack#app'
348
360
```
349
361
> will pass all requests (i.e. `/(*other)`) to the hyperstack engine, and find
350
-
and mount a component named `App`. Whatever ever you name the engine
362
+
and mount a component named `App`. Whatever you name the engine
351
363
mount point (i.e. `hyperstack` in this case) is what you direct the requests to.
352
364
>
353
365
> Likewise `get /price-quote/(*other), to: hyperstack#price_quote` would mount
354
-
a component named `PriceQuote` when the url begins with `price-quote`.
366
+
a component named `PriceQuote` when the url begins with `price-quote`.
367
+
>
368
+
> Remember though that the first route that matches will be used, so if you had both examples in your routes, the price-quote route would be before the wildcard route.
369
+
>
370
+
> This the way you have have 2 or more single page apps served by the same Rails backend.
355
371
356
-
### Add/Update the Procfile
372
+
### 11. Add/Update the Procfile
357
373
358
374
If you are using the Hotloader, then you will also want to use the `foreman` gem.
359
375
The Hotloader runs in its own application process, and foreman will start and stop both Rails and the Hotloader together.
@@ -373,7 +389,7 @@ To run foreman simply execute `bundle exec foreman start`, and CTRL-C to quit.
373
389
374
390
> Note when running foreman with the above Procfile your port will be 5000 instead of the usual 3000.
375
391
376
-
### Using generators
392
+
### 12. Using generators
377
393
378
394
No matter which way you installed Hyperstack you can use the included generators to add new components.
379
395
@@ -382,7 +398,7 @@ skeleton top level (router) component named App.
382
398
383
399
`bundle exec rails g hyper:component Index` will create a skeleton component named Index.
384
400
385
-
### Adding a test component
401
+
### 13. Adding a test component
386
402
387
403
Once you have installed Hyperstack you have a couple of options to see how things work.
388
404
@@ -398,7 +414,7 @@ and then route everything to this component from your routes file:
398
414
399
415
##### Mounting a component from an existing page
400
416
401
-
Another approach is to add a regular component again using the generator:
417
+
Another approach is to add a simple component using the component generator:
0 commit comments