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: 9d77283073bcef67b2dd2440d4d03fd6801796c3
4
- data.tar.gz: 0171ca27df85f48512803a5751cf5af9ee1ed9c6
3
+ metadata.gz: dd5106f762757849e6bb694e4034922250576e00
4
+ data.tar.gz: 9c20f11f028f1a31469d11d64930408eedee676a
5
5
  SHA512:
6
- metadata.gz: bcdc79a569bb4f1925411bbe6766ab2dff05c540f14a664da69c198378f1670c081be9a5504e488c7ca7132eec5272396e5e879abdcf84a15ea39aeea6a0a43d
7
- data.tar.gz: ac5e9830df41222a51e5de8740264730a6ddd00ff402b4a07a086a57bc090b7d165351b224bd7618d73d6dd8c1e55143a6477013b284b4661d19eec973e3eb3c
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 so by default. So the component will be the "Show" class, of the "Home" module,
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 Home
80
-
81
- export_component # export the component name into the javascript space
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" # render "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 # by default render_component will use the controller name to find the appropriate 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
@@ -13,7 +13,7 @@ GIT
13
13
  PATH
14
14
  remote: ../..
15
15
  specs:
16
- reactive-ruby (0.7.5)
16
+ reactive-ruby (0.7.6)
17
17
  jquery-rails
18
18
  opal
19
19
  opal-activesupport
@@ -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?) ? "#{params[:controller].camelize.gsub("/", "::")}::#{params[:action].camelize}" : args.shift
10
- @rails_react_variables = (args[0].is_a? Hash) ? args[0] : {}
11
- render inline: "<%= react_component 'Components::#{component_name}', @rails_react_variables, { prerender: !params[:no_prerender] } %>", layout: 'application'
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(module_style_name, props = {}, render_options={}, &block)
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(js_name, props.react_serializer, render_options, &block))
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
@@ -11,6 +11,7 @@ if RUBY_ENGINE == 'opal'
11
11
  require "reactive-ruby/rendering_context"
12
12
  require "reactive-ruby/state"
13
13
  require "reactive-ruby/isomorphic_helpers"
14
+ require "rails-helpers/top_level_rails_component"
14
15
 
15
16
  else
16
17
  require "opal"
@@ -1,3 +1,3 @@
1
1
  module React
2
- VERSION = "0.7.6"
2
+ VERSION = "0.7.7"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: reactive-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.6
4
+ version: 0.7.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Chang