reactive-ruby 0.7.6 → 0.7.7
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dd5106f762757849e6bb694e4034922250576e00
|
4
|
+
data.tar.gz: 9c20f11f028f1a31469d11d64930408eedee676a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a6cffbbb59ec3c5f575eb1a9103db358d4c45ecba1ca32aa6ca8abc097f0c92badfc6cc159576215c7a1c4456f1459fd99ecbd38eebb14c92b5cfb5628f4ebd0
|
7
|
+
data.tar.gz: d5260a35117ce9ed3f9d5a179a6d9974e054dc009b753dd6bfdfd73176927b90c63cf00576fa92ef721b0f2fd581530f9c14ad4eaabd9df9a322f752fb6807f7
|
data/README.md
CHANGED
@@ -66,27 +66,31 @@ require 'browser/interval' # for #every, and #after methods
|
|
66
66
|
|
67
67
|
Okay that is your setup.
|
68
68
|
|
69
|
-
Now for a simple component. We are going to render this from the `show` method of the home controller. We want to use convention over configuration
|
69
|
+
Now for a simple component. We are going to render this from the `show` method of the home controller. We want to use convention over configuration by default. So the component will be the "Show" class, of the "Home" module,
|
70
70
|
of the Components module.
|
71
71
|
|
72
72
|
```ruby
|
73
|
-
# app/views/components/home.rb
|
73
|
+
# app/views/components/home/show.rb
|
74
74
|
|
75
|
-
module Components
|
75
|
+
module Components
|
76
|
+
|
76
77
|
module Home
|
78
|
+
|
77
79
|
class Show
|
78
80
|
|
79
|
-
include React::Component # will create a new component named
|
80
|
-
|
81
|
-
|
81
|
+
include React::Component # will create a new component named Show
|
82
|
+
|
83
|
+
optional_param :say_hello_to
|
82
84
|
|
83
85
|
def render
|
84
86
|
puts "Rendering my first component!"
|
85
|
-
"hello"
|
87
|
+
"hello #{'there '+say_hello_to if say_hello_to}" # render "hello" with optional 'there ...'
|
86
88
|
end
|
87
89
|
|
88
90
|
end
|
91
|
+
|
89
92
|
end
|
93
|
+
|
90
94
|
end
|
91
95
|
```
|
92
96
|
|
@@ -95,7 +99,7 @@ Components work just like views so put this in your home controller
|
|
95
99
|
# controllers/home_controller.rb
|
96
100
|
class HomeController < ApplicationController
|
97
101
|
def show
|
98
|
-
render_component
|
102
|
+
render_component say_hello_to: params[:say_hello_to] # by default render_component will use the controller name to find the appropriate component
|
99
103
|
end
|
100
104
|
end
|
101
105
|
```
|
@@ -106,6 +110,19 @@ Open up the js console in the browser and you will see a log showing what went o
|
|
106
110
|
|
107
111
|
Have a look at the sources in the console, and notice your ruby code is there, and you can set break points etc.
|
108
112
|
|
113
|
+
### Changing the top level component name and search path
|
114
|
+
|
115
|
+
You can control the top level component name and search path.
|
116
|
+
|
117
|
+
You can specify the component name explicitly in the `render_component` method. `render_component "Blatz` will search the for a component class named
|
118
|
+
`Blatz` regardless of the controller method.
|
119
|
+
|
120
|
+
Searching for components normally works like this: Given a controller named "Foo" then the component should be either in the `Components::Foo` module, the
|
121
|
+
`Components` module (no controller - useful if you have just a couple of shared components) or just the outer scope (i.e. `Module`) which is useful for small apps.
|
122
|
+
|
123
|
+
Saying `render_component "::Blatz"` will only search the outer scope, while `"::Foo::Blatz"` will look only in the module `Foo` for a class named `Blatz`.
|
124
|
+
|
125
|
+
|
109
126
|
## Integration with Sinatra
|
110
127
|
|
111
128
|
See the sinatra-tutorial folder
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# controllers/home_controller.rb
|
2
2
|
class HomeController < ApplicationController
|
3
3
|
def show
|
4
|
-
render_component # by default render_component will use the controller name to find the appropriate component
|
4
|
+
render_component "::Showz", say_hello_to: params[:say_hello_to] # by default render_component will use the controller name to find the appropriate component
|
5
5
|
end
|
6
6
|
end
|
@@ -6,9 +6,11 @@ begin
|
|
6
6
|
class ActionController::Base
|
7
7
|
|
8
8
|
def render_component(*args)
|
9
|
-
component_name = ((args[0].is_a? Hash) || args.empty?) ?
|
10
|
-
|
11
|
-
|
9
|
+
component_name = ((args[0].is_a? Hash) || args.empty?) ? params[:action].camelize : args.shift
|
10
|
+
controller = params[:controller].camelize
|
11
|
+
rails_react_variables = (args[0].is_a? Hash) ? args[0] : {}
|
12
|
+
@render_params = {component_name: component_name, controller: controller, render_params: rails_react_variables}
|
13
|
+
render inline: "<%= react_component 'React.TopLevelRailsComponent', @render_params, { prerender: !params[:no_prerender] } %>", layout: 'application'
|
12
14
|
end
|
13
15
|
|
14
16
|
end
|
@@ -27,8 +29,7 @@ begin
|
|
27
29
|
|
28
30
|
alias_method :pre_opal_react_component, :react_component
|
29
31
|
|
30
|
-
def react_component(
|
31
|
-
js_name = module_style_name.gsub("::", ".")
|
32
|
+
def react_component(name, props = {}, render_options={}, &block)
|
32
33
|
if render_options[:prerender]
|
33
34
|
render_options[:prerender] = {render_options[:prerender] => true} unless render_options[:prerender].is_a? Hash
|
34
35
|
existing_context_initializer = render_options[:prerender][:context_initializer]
|
@@ -38,7 +39,7 @@ begin
|
|
38
39
|
end
|
39
40
|
|
40
41
|
end
|
41
|
-
component_rendering = raw(pre_opal_react_component(
|
42
|
+
component_rendering = raw(pre_opal_react_component(name, props.react_serializer, render_options, &block))
|
42
43
|
footers = React::IsomorphicHelpers.prerender_footers #if render_options[:prerender]
|
43
44
|
component_rendering+footers
|
44
45
|
end
|
data/lib/reactive-ruby.rb
CHANGED