Skip to content
This repository was archived by the owner on Oct 19, 2018. It is now read-only.

Commit 3ffaa5a

Browse files
committed
merged with v8 stable
2 parents a2ec73c + 1db5906 commit 3ffaa5a

File tree

9 files changed

+70
-18
lines changed

9 files changed

+70
-18
lines changed

Gemfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@ source 'https://rubygems.org'
33
#gem 'opal', "~> 0.9.x"
44
#gem 'opal-rails', git: "https://github.com/reactrb/opal-rails.git"
55
#gem 'opal-rspec-rails', git: 'https://github.com/reactrb/opal-rspec-rails.git'
6-
6+
gem 'pry'
77
gemspec

lib/generators/reactive_ruby/test_app/templates/views/layouts/test_layout.html.erb

Whitespace-only changes.

lib/generators/reactive_ruby/test_app/test_app_generator.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ def configure_test_app
3434
"#{test_app_path}/app/views/components/hello_world.rb", force: true
3535
template 'views/components/todo.rb',
3636
"#{test_app_path}/app/views/components/todo.rb", force: true
37+
template 'views/layouts/test_layout.html.erb',
38+
"#{test_app_path}/app/views/layouts/test_layout.html.erb", force: true
39+
template 'views/layouts/test_layout.html.erb',
40+
"#{test_app_path}/app/views/layouts/explicit_layout.html.erb", force: true
3741
end
3842

3943
def clean_superfluous_files

lib/react/top_level.rb

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,20 +71,29 @@ def self.unmount_component_at_node(node)
7171
end
7272

7373
Element.instance_eval do
74-
75-
class ::Element::DummyContext < React::Component::Base
74+
class Element
75+
class DummyContext < React::Component::Base
76+
end
7677
end
7778

7879
def self.find(selector)
79-
selector = selector.dom_node if selector.respond_to? :dom_node rescue selector
80+
selector = begin
81+
selector.dom_node
82+
rescue
83+
selector
84+
end if selector.respond_to? :dom_node
8085
`$(#{selector})`
8186
end
8287

8388
def self.[](selector)
8489
find(selector)
8590
end
8691

87-
def render(&block)
88-
React.render(React::RenderingContext.render(nil) {::Element::DummyContext.new.instance_eval &block}, self)
92+
define_method :render do |&block|
93+
React.render(
94+
React::RenderingContext.render(nil) do
95+
::Element::DummyContext.new.instance_eval(&block)
96+
end, self
97+
)
8998
end
90-
end if Object.const_defined?("Element")
99+
end if Object.const_defined?('Element')
Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
require 'action_controller'
22

3-
module ReactiveRuby
4-
module Rails
5-
class ActionController::Base
6-
def render_component(*args)
7-
@component_name = ((args[0].is_a? Hash) || args.empty?) ? params[:action].camelize : args.shift
8-
@render_params = (args[0].is_a? Hash) ? args[0] : {}
9-
render inline: '<%= react_component(@component_name, @render_params, { prerender: !params[:no_prerender] }) %>', layout: 'application'
10-
end
3+
module ActionController
4+
# adds render_component helper to ActionControllers
5+
class Base
6+
def render_component(*args)
7+
@component_name = ((args[0].is_a? Hash) || args.empty?) ? params[:action].camelize : args.shift
8+
@render_params = args.shift || {}
9+
options = args[0] || {}
10+
render inline: '<%= react_component @component_name, @render_params, '\
11+
'{ prerender: !params[:no_prerender] } %>',
12+
layout: options.key?(:layout) ? options[:layout].to_s : :default
1113
end
1214
end
1315
end

lib/reactive-ruby/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
module React
2-
VERSION = "0.8.2"
2+
VERSION = '0.8.4'
33
end

reactrb.gemspec

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ Gem::Specification.new do |s|
3232
s.add_development_dependency 'rails', '4.2.4'
3333
s.add_development_dependency 'react-rails'
3434
s.add_development_dependency 'opal-rails'
35+
s.add_development_dependency 'pry'
3536
if RUBY_PLATFORM == 'java'
3637
s.add_development_dependency 'jdbc-sqlite3'
3738
s.add_development_dependency 'activerecord-jdbcsqlite3-adapter'

spec/controller_helper_spec.rb

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,26 @@ class TestController < ActionController::Base; end
88

99
describe '#render_component' do
1010
controller do
11+
12+
layout "test_layout"
13+
1114
def index
1215
render_component
1316
end
17+
18+
def new
19+
render_component "Index", {}, layout: :explicit_layout
20+
end
1421
end
1522

16-
it 'renders the application layout' do
23+
it 'renders with the default layout' do
1724
get :index, no_prerender: true
18-
expect(response).to render_template(layout: :application)
25+
expect(response).to render_template(layout: :test_layout)
26+
end
27+
28+
it "renders with a specified layout" do
29+
get :new, no_prerender: true
30+
expect(response).to render_template(layout: :explicit_layout)
1931
end
2032
end
2133
end
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
require 'spec_helper'
2+
3+
if opal?
4+
describe 'Element' do
5+
after(:each) do
6+
React::API.clear_component_class_cache
7+
end
8+
9+
it 'responds to render' do
10+
expect(Element['body']).to respond_to :render
11+
end
12+
13+
it 'will find the DOM node given a react element' do
14+
stub_const 'Foo', Class.new(React::Component::Base)
15+
Foo.class_eval do
16+
def render
17+
div { 'hello' }
18+
end
19+
end
20+
21+
expect(Element[renderToDocument(Foo)].html).to eq('hello')
22+
end
23+
end
24+
end

0 commit comments

Comments
 (0)