Skip to content

Commit d2683f8

Browse files
committed
updated installers and instructions
1 parent 6abc21d commit d2683f8

File tree

13 files changed

+260
-387
lines changed

13 files changed

+260
-387
lines changed

docs/installation/installation.md

Lines changed: 32 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ gem 'rails-hyperstack',
5858

5959
These are the steps to manually install Hyperstack in an existing Rails app:
6060

61-
+ Insure yarn is loaded
61+
1. Insure yarn is loaded
6262
+ Add the gems
6363
+ Update the `application.js` file
6464
+ Add the `hyperstack` directories
@@ -256,7 +256,7 @@ included) in the asset manifest.
256256
The `on_error` method defines what you want to do when errors occur. In production
257257
you will may want to direct the output to a dedicated log file for example.
258258

259-
### Integrate with webpacker
259+
### 9. Integrate with webpacker
260260

261261
The Rails webpacker gem will bundle up all your javascript assets including those used by Hyperstack such as React, and React-Router.
262262

@@ -275,7 +275,7 @@ Once you have the pack files setup you will also need to fetch the packages, plu
275275
>
276276
> 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.
277277
278-
#### Add the `client_and_server.js` pack file
278+
##### Add the `client_and_server.js` pack file
279279

280280
* Note that this goes in a new directory: `app/javascripts/packs` *
281281

@@ -290,7 +290,7 @@ ReactRailsUJS = require('react_ujs'); // interface to react-rails
290290
// to add additional NPM packages run add yarn package-name@version
291291
// then add the require here.
292292
```
293-
#### Add the `client_only.js` pack file
293+
##### Add the `client_only.js` pack file
294294

295295
```javascript
296296
//app/javascript/packs/client_only.js
@@ -301,7 +301,7 @@ jQuery = require('jquery');
301301
// then add the require here.
302302
```
303303

304-
#### Add the packages using `yarn`
304+
##### Add the packages using `yarn`
305305

306306
First you need make sure you have `yarn` installed:
307307
[Yarn install for any system](https://yarnpkg.com/en/docs/install)
@@ -317,13 +317,25 @@ yarn add react_ujs@^2.5.0
317317
yarn add jquery@^3.4.1
318318
```
319319

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.
323321

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
324336
325337

326-
### Add the Hyperstack engine to the routes file
338+
### 10. Add the Hyperstack engine to the routes file
327339

328340
At the beginning of the `config/routes.rb` file mount the Hyperstack engine:
329341

@@ -337,7 +349,7 @@ Rails.application.routes.draw do
337349
end
338350
```
339351

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.
341353

342354
>Note: You can also directly ask Hyperstack to mount your top level components
343355
via the routes file. For example
@@ -347,13 +359,17 @@ Rails.application.routes.draw do
347359
get '/(*other)', to: 'hyperstack#app'
348360
```
349361
> 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
351363
mount point (i.e. `hyperstack` in this case) is what you direct the requests to.
352364
>
353365
> 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.
355371
356-
### Add/Update the Procfile
372+
### 11. Add/Update the Procfile
357373

358374
If you are using the Hotloader, then you will also want to use the `foreman` gem.
359375
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.
373389

374390
> Note when running foreman with the above Procfile your port will be 5000 instead of the usual 3000.
375391
376-
### Using generators
392+
### 12. Using generators
377393

378394
No matter which way you installed Hyperstack you can use the included generators to add new components.
379395

@@ -382,7 +398,7 @@ skeleton top level (router) component named App.
382398

383399
`bundle exec rails g hyper:component Index` will create a skeleton component named Index.
384400

385-
### Adding a test component
401+
### 13. Adding a test component
386402

387403
Once you have installed Hyperstack you have a couple of options to see how things work.
388404

@@ -398,7 +414,7 @@ and then route everything to this component from your routes file:
398414

399415
##### Mounting a component from an existing page
400416

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:
402418

403419
`bundle exec rails g hyper:component HyperTest`
404420

ruby/hyper-component/lib/hyperstack/internal/component/rails/railtie.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@ class Railtie < ::Rails::Railtie
1212
end
1313
config.after_initialize do
1414
class ::HyperstackController < ::ApplicationController
15-
def action_missing(_name)
16-
render_component
15+
def action_missing(*)
16+
parts = params[:action].split('__')
17+
render_component (parts[0..-2]+[parts.last.camelize]).join('::')
1718
end
1819
end
1920
end

ruby/hyper-operation/lib/hyper-operation/transport/client_drivers.rb

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -185,12 +185,17 @@ def self.sync_dispatch(data)
185185
# not sure why the second check is needed. It happens in the test app
186186
route.app == Hyperstack::Engine or (route.app.respond_to?(:app) and route.app.app == Hyperstack::Engine)
187187
end
188-
raise 'Hyperstack::Engine mount point not found. Check your config/routes.rb file' unless path
189-
path = path.path.spec
190-
"<script type='text/javascript'>\n"\
191-
"window.HyperstackEnginePath = '#{path}';\n"\
192-
"window.HyperstackOpts = #{config_hash.to_json}\n"\
193-
"</script>\n"
188+
if path
189+
path = path.path.spec
190+
"<script type='text/javascript'>\n"\
191+
"window.HyperstackEnginePath = '#{path}';\n"\
192+
"window.HyperstackOpts = #{config_hash.to_json}\n"\
193+
"</script>\n"
194+
else
195+
"<script type='text/javascript'>\n"\
196+
"window.HyperstackOpts = #{config_hash.to_json}\n"\
197+
"</script>\n"
198+
end
194199
end if RUBY_ENGINE != 'opal'
195200

196201
class << self
@@ -244,6 +249,9 @@ def self.initialize_client_drivers_on_boot
244249

245250
@opts = Hash.new(`window.HyperstackOpts`)
246251

252+
if opts[:transport] != :none && `typeof(window.HyperstackEnginePath) == 'undefined'`
253+
raise "No hyperstack mount point found!\nCheck your Rails routes.rb file";
254+
end
247255

248256
if opts[:transport] == :pusher
249257

ruby/hyperstack-config/lib/hyperstack/imports.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,17 @@ def import_list
66
end
77

88
def import(value, gem: nil, cancelled: nil, client_only: nil, server_only: nil, tree: nil, js_import: nil, at_head: nil)
9-
return if import_list.detect { |current_value, *_rest| value == current_value }
9+
return if imported? value
1010
new_element = [
1111
value, cancelled, !client_only, !server_only, (tree ? :tree : :gem), js_import
1212
]
1313
import_list.send(at_head ? :unshift : :push, new_element)
1414
end
1515

16+
def imported?(value)
17+
import_list.detect { |current_value, *| value == current_value }
18+
end
19+
1620
alias imports import
1721

1822
def import_tree(value, cancelled: nil, client_only: nil, server_only: nil)

ruby/rails-hyperstack/lib/generators/hyper/component_generator.rb

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,25 @@
22
module Hyper
33
class Component < Rails::Generators::Base
44
source_root File.expand_path('../templates', __FILE__)
5-
65
argument :components, type: :array
6+
class_option 'base-class', :default => 'HyperComponent'
7+
class_option 'add-route', :default => nil
8+
79
def create_component_file
10+
clear_cache
11+
insure_hyperstack_loader_installed
12+
insure_base_component_class_exists unless options['base-class'] == 'skip'
813
self.components.each do |component|
914
component_array = component.split('::')
1015
@modules = component_array[0..-2]
1116
@file_name = component_array.last
1217
@indent = 0
1318
template 'component_template.rb',
14-
File.join('app/hyperstack/components',
15-
@modules.map(&:downcase).join('/'),
19+
File.join('app', 'hyperstack', 'components',
20+
*@modules.map(&:downcase),
1621
"#{@file_name.underscore}.rb")
1722
end
23+
add_route
1824
end
1925
end
2026
end

ruby/rails-hyperstack/lib/generators/hyper/router_generator.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ def create_component_file
99
component_array = component.split('::')
1010
@modules = component_array[0..-2]
1111
@file_name = component_array.last
12+
1213
@indent = 0
1314
template 'router_template.rb',
1415
File.join('app/hyperstack/components',

ruby/rails-hyperstack/lib/generators/hyper/templates/component_template.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<%- @modules.each do |module_name| %><%= " "* @indent %>module <%= module_name.camelize %><%- @indent += 1 %>
2-
<%- end %><%=" "* @indent %>class <%= @file_name %> < Hyperstack::Component
2+
<%- end %><%=" "* @indent %>class <%= @file_name %> < <%= @component_base_class %>
33
44
<%=" "* @indent %> # param :my_param
55
<%=" "* @indent %> # param param_with_default: "default value"

0 commit comments

Comments
 (0)