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
+36-29Lines changed: 36 additions & 29 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -14,7 +14,7 @@ And for a full system that includes Webpack for managing javascript assets you w
14
14
15
15
## Creating a Test Rails App
16
16
17
-
You can install Hyperstack in an existing Rails apps, or you can create a new Rails app using the Rails `new` command. For example to create a new app called `MyApp` you would run
17
+
You can install Hyperstack in existing Rails apps, or you can create a new Rails app using the Rails `new` command. For example to create a new app called `MyApp` you would run
18
18
19
19
```
20
20
rails new MyApp -T
@@ -26,7 +26,7 @@ which will create a new directory called `MyApp`. *Be sure to cd into the new d
26
26
27
27
## Adding the Hyperstack gem
28
28
29
-
Add the rails-hyperstack gem to your Gemfile, and then bundle install. This can be done in one step by running:
29
+
Once you have a new (or existing) Rails app, add the rails-hyperstack gem to your Gemfile, and then bundle install. This can be done in one step by running:
@@ -47,28 +47,32 @@ After the Hyperstack gem is installed you can do a full install by running:
47
47
bundle exec rails hyperstack:install
48
48
```
49
49
This will install the following pieces:
50
-
+ A skeleton top level router component named `App`
51
-
+ A Rails route that will send all requests to that component
50
+
+ A skeleton top level router component named `App`*(only on new apps)*
51
+
+ A Rails route that will send all requests to that component*(only on new apps)*
52
52
+ The webpacker gem and associated files to integrate Hyperstack with webpack
53
53
+ HyperModel to give your client components access to your Rails models
54
54
+ The Hotloader which will update the client when you make changes to code
55
55
56
-
Each of these pieces can be skipped or installed independently either using
56
+
Each of the above pieces can be skipped or installed independently either using
57
57
built in installers and generators, or manually as explained in the
58
58
following sections.
59
59
60
-
At this point, you're fully installed.
60
+
> The top level component, and route is only installed if a new Rails app is detected. Otherwise you will have to choose how you want to mount your components, depending on the needs of your application. See [How to add components](#<user-content-adding-a-single-component-to-your-application>) and [mount them](#<mounting-components>) for details.
61
61
62
-
If you're installing into a new rails app, you can run bundle exec foreman start
63
-
to start the server, and "app" will display on the top left hand side of the page.
64
62
65
-
If you're installing into an existing Rails apps, you can run bundle exec foreman start
66
-
to start the server, and your app should funcion exactly as it always has. From here, you'll need to
67
-
[add a Hypercomponent](#<user-content-adding-a-single-component-to-your-application>)
68
-
to have Hyperstack funcionality.
63
+
At this point you're fully installed.
64
+
65
+
If you installed into a new rails app, you can run bundle exec foreman start
66
+
to start the server, and **App** will display on the top left hand side of the page. You will find the `App` component in the `app/hyperstack/components/app.rb` file. If you edit this file and save you should see the changes reflected in the browser.
67
+
68
+
If you installed into an existing Rails apps, you can run bundle exec foreman start
69
+
to start the server, and your app should function exactly as it always has. From here, you'll need to start adding components and
70
+
and mounting them from either a view or a controller. See [How to add components](#<user-content-adding-a-single-component-to-your-application>) and [mount them](#<mounting-components>) for details.
69
71
70
72
## Summary of Installers and Generators
71
73
74
+
The following sections details the installers and generators you can use for for full control of the installation process. Details are also given on exactly what each installer and generator does if you want to manually apply the step or modify it to your needs.
75
+
72
76
```
73
77
bundle exec ... # for best results always use bundle exec!
74
78
rails hyperstack:install # full system install
@@ -135,7 +139,7 @@ The `models`, `operations`, and `shared` directories are *isomorphic*. That is t
135
139
be run on both the Rails server and on the client. All other directories (regardless of the name)
136
140
will only be visible on the client and during prerendering.
137
141
138
-
These directories will be created as needed by the installers and generators, or you can create them yourself as needed.
142
+
These directories will be created as required by the installers and generators, or you can create them yourself as needed.
139
143
140
144
## Adding a Single Component to Your Application
141
145
@@ -174,13 +178,13 @@ end
174
178
bundle exec rails g hyper:component Test --base-class=ApplicationComponent
175
179
```
176
180
> You can also override the base class for the entire application by setting
177
-
> the `component_base_class` config setting. See the last section for details.
181
+
> the `component_base_class` config setting. See [Summary of Hyperstack Configuration Switches](#<summary-of-hyperstack-configuration-switches>) for details.
178
182
179
183
## Mounting Components
180
184
181
185
Components render (or *mount*) other components in a tree-like fashion. You can mount the top level component of the tree in three different ways:
182
186
+ Render it from a controller using the `render_component` method
183
-
+ Mount it from within a view using the `render_component` view helper
187
+
+ Mount it from within a view using the `react_component` view helper
184
188
+ Route to it from the Rails router
185
189
186
190
#### Rendering from a Controller Action
@@ -205,14 +209,17 @@ and override the default layout
> Notice how `render_component` works very much like the standard Rails `render` method, except a component is rendered instead of a view.
208
213
209
-
#### Mounting from Within a View
214
+
#### Mounting from Within a View or Layout
210
215
211
216
For example
212
217
```erb
213
-
<%= react_component 'Dashboard', user: @user %>
218
+
<%= mount_component 'Dashboard', user: @user %>
214
219
```
215
-
> Note that you may have several component trees mounted in a single page using the `render_component` helper. While this is not typical for a clean sheet Hyperstack design, it is useful when mixing Hyperstack with legacy applications.
220
+
will display the `Dashboard` component at this position in the
221
+
code, very similar to displaying a view or partial.
222
+
> Note that you may have several component trees mounted in a single page using the `mount_component` helper. While this is not typical for a clean sheet Hyperstack design, it is useful when mixing Hyperstack with legacy applications.
216
223
217
224
218
225
#### Directly Routing to a Component
@@ -301,7 +308,7 @@ Using the Rails `webpacker` gem you can easily add other NPM (node package manag
301
308
For details on how to import and use NPM packages in your application see [Importing React Components](https://hyperstack.org/edge/docs/dsl-client/components#javascript-components)
302
309
303
310
To integrate webpacker with an existing Hyperstack application - for example if you just added a couple of components and now
304
-
want to try webpacker - use the hyperstack:install:webpack task:
311
+
want to try webpacker - use the `hyperstack:install:webpack` task:
Webpacker uses manifests to determine how to package up assets. Hyperstack depends on two manifests: One that builds assets that are loaded both during prerendering **and** on the client, and a second that is **only** loaded on the client.
340
347
341
-
> Prerendering builds the initial page view server side, and then delivers it to the client as a normal static HTML page. Attached to the HTML are flags that React will use update the page as components are re-rendered after the initial page load.
348
+
> Prerendering builds the initial page view server side, and then delivers it to the client as a normal static HTML page. Attached to the HTML are flags that React will use to update the page as components are re-rendered after the initial page load.
342
349
>
343
350
> This means that page load time is comparable to any other Rails view, and that Rails can cache the pages like any other view.
344
351
>
@@ -470,7 +477,9 @@ This policy specifies the following:
470
477
As your application develops you can begin defining more restrictive policies (only allowing Users to see their own data for example)
471
478
472
479
> Note: The policy mechanism does not depend on [Pundit](https://github.com/varvet/pundit) but is compatible with it. You can add pundit style
473
-
policies for legacy parts of your system.
480
+
policies for legacy parts of your system.
481
+
>
482
+
> For details on creating policies see the [policy documentation](https://github.com/hyperstack-org/hyperstack/blob/edge/docs/dsl-isomorphic/hyper-policy.md).
474
483
475
484
#### Moving the `application_record.rb` File.
476
485
@@ -498,7 +507,7 @@ So to prevent that you need to add this file to `app/models`
498
507
require'models/application_record.rb'
499
508
```
500
509
> Note that the last line is *not* a typo. Rails paths begin with
501
-
the*subdirectory* name. So `'models/application_record.rb'` means to search all directories for a file name `application_record.rb` in the`models`*subdirectory*
510
+
a*subdirectory* name. So `'models/application_record.rb'` means to search all app directories for a file name `application_record.rb` in a`models`*subdirectory*
502
511
503
512
Thus Rails will find `app/models/application_record.rb` where it expects it, but that file simply requires the real `application_record.rb` file from the `app/hyperstack/models` directory so everybody is happy.
504
513
@@ -521,7 +530,6 @@ You can manually perform these steps following these instructions.
521
530
522
531
By default the Hotloader is **not** included in the hyperstack manifest so the first step is to import it using `config/initializers/hyperstack.rb` initializer file:
523
532
524
-
Note that
525
533
```ruby
526
534
# config/initializers/hyperstack.rb
527
535
Hyperstack.configuration do |config|
@@ -563,7 +571,7 @@ Now go into your editor and make a change to a component. You should see the br
563
571
#### Adding the Foreman Gem and Procfile
564
572
565
573
Having to start (and stop) two separate shells is painful so you can add the `foreman` gem which will manage all that for you. Add
566
-
the `foreman` to the development section of your gem file and bundle install. You can do this in one step by running:
574
+
the `foreman`gem to the development section of your Gemfile and bundle install. You can do this in one step by running:
567
575
```ruby
568
576
bundle add foreman --group development
569
577
```
@@ -592,7 +600,7 @@ Hyperstack.configuration do |config|
592
600
# set the component base class
593
601
config.component_base_class ='HyperComponent'# i.e. 'ApplicationComponent'
594
602
595
-
# prerendering is default :off, you should wait until your
603
+
# prerendering is by default :off. You should wait until your
596
604
# application is relatively well debugged before turning on.
597
605
config.prerendering =:off# or :on
598
606
@@ -606,7 +614,6 @@ Hyperstack.configuration do |config|
606
614
# non-server process, Hyperstack needs to forward the change notification
607
615
# to the server for push broadcasting. This value controls how long
608
616
# Hyperstack will wait to hear back from the server.
609
-
610
617
config.send_to_server_timeout =10# seconds or nil for no timeout
611
618
612
619
# pusher specific setting. If you are already using pusher you
@@ -617,14 +624,14 @@ Hyperstack.configuration do |config|
617
624
# you may want to switch this like this: = Rails.env.debug?
618
625
config.client_logging =true
619
626
620
-
#Don't setup a session channel. This is mainly useful in test specs
627
+
#Setup a session channel. Turning this off is mainly useful in test specs
621
628
config.connect_session =true
622
629
623
630
# if you need to change the hotloader port
624
631
config.hotloader_port =25222# note also update your proc file as well
625
632
626
633
# turn pinging on if your hotloader connection keeps dropping
627
-
config.hotloader_ping =nil
634
+
config.hotloader_ping =nil# 10 seconds for example
628
635
629
636
# callback mapping allows the hotloader to reprogram callbacks
630
637
# however it adds additional overhead on first load. On large systems
@@ -646,7 +653,7 @@ end
646
653
647
654
# Hyperstack provides a hook to aid in debugging communication problems. The following
648
655
# code block adds a useful server side log message. You may want to change this to
649
-
# a specific logging location, or on occassion add a debug break point instead of logging
656
+
# a specific logging location, or on occasion add a debug break point instead of logging
0 commit comments