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

Commit 99e6b81

Browse files
committed
Merge branch '0-7-stable'. Includes JRuby Support
closes #98 Conflicts: Gemfile.lock
2 parents 0be2250 + a00003b commit 99e6b81

File tree

9 files changed

+50
-33
lines changed

9 files changed

+50
-33
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,4 @@ node_modules
3030
.bundle
3131

3232
spec/test_app
33+
Gemfile.lock

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ rvm:
33
- 1.9.3
44
- 2.0.0
55
- 2.1
6+
- jruby-19mode
67
script:
78
- bundle exec rake test_app
89
- bundle exec rake

Gemfile

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,2 @@
11
source 'https://rubygems.org'
2-
group :development, :test do
3-
gem 'therubyracer', platforms: :ruby
4-
gem 'rails'
5-
gem 'react-rails'
6-
gem 'opal-rails'
7-
end
82
gemspec

README.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ gem 'reactive-ruby'
6161
gem 'react-rails', '~> 1.3.2'
6262
gem 'opal-rails'
6363
gem 'therubyracer', platforms: :ruby # Required for prerendering
64+
# for JRuby you need the below line instead
65+
# gem 'therubyrhino, platforms: :jruby
66+
6467
```
6568

6669
Run `bundle install` and restart your rails server.
@@ -136,7 +139,7 @@ props), to render the component:
136139
class HomeController < ApplicationController
137140
def show
138141
# render_component uses the controller name to find the 'show' component.
139-
render_component say_hello_to: params[:say_hello_to]
142+
render_component say_hello_to: params[:say_hello_to]
140143
end
141144
end
142145
```
@@ -161,11 +164,11 @@ regardless of the name of the controller method.
161164

162165
Searching for components works like this: Given a controller named
163166
"Foo" then react.rb will search for a module named `Foo` containing the component.
164-
If this fails all modules will be searched (i.e. the name of the controller will be
167+
If this fails all modules will be searched (i.e. the name of the controller will be
165168
ignored.) In either case the search begins at the outer most scope until a match is made.
166169

167170
Thus for example given a controller named `Foo`, components could be found in the `Foo` module,
168-
the `Components::Foo` module, in the outer most scope, or in any nested module.
171+
the `Components::Foo` module, in the outer most scope, or in any nested module.
169172
The way the search works allows for small projects that do not need a lot
170173
of name spacing, and also allows components to be shared across several controllers.
171174

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
1-
<% if defined? application_definition %>
1+
<% if defined? application_definition -%>
2+
require File.expand_path('../boot', __FILE__)
3+
require 'rails/all'
24

3-
require File.expand_path('../boot', __FILE__)
5+
# Require the gems listed in Gemfile, including any gems
6+
# you've limited to :test, :development, or :production.
7+
Bundler.require(*Rails.groups(assets: %w(development test)))
48

5-
require 'rails/all'
9+
require 'opal-rails'
10+
require 'reactive-ruby'
611

7-
# Require the gems listed in Gemfile, including any gems
8-
# you've limited to :test, :development, or :production.
9-
Bundler.require(*Rails.groups(assets: %w(development test)))
10-
11-
require 'reactive-ruby'
12-
13-
<%= application_definition %>
14-
15-
<% end %>
12+
<%= application_definition %>
13+
<% end -%>

lib/reactive-ruby/server_rendering/contextual_renderer.rb

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,24 @@
11
module ReactiveRuby
22
module ServerRendering
3+
def self.context_instance_name
4+
return '@rhino_context' if RUBY_PLATFORM == 'java'
5+
'@v8_context'
6+
end
7+
8+
def self.context_instance_for(context)
9+
context.instance_variable_get(context_instance_name)
10+
end
11+
312
class ContextualRenderer < React::ServerRendering::SprocketsRenderer
413
def initialize(options = {})
514
super(options)
615
ComponentLoader.new(v8_context).load
716
end
817

918
def render(component_name, props, prerender_options)
10-
if prerender_options.is_a? Hash
19+
if prerender_options.is_a?(Hash)
1120
if v8_runtime? && prerender_options[:context_initializer]
12-
raise React::ServerRendering::PrerenderError.new(component_name, props, "you must use 'therubyracer' with the prerender[:context] option") unless v8_runtime?
21+
raise PrerenderError.new(component_name, props, "you must use 'therubyracer' with the prerender[:context] option") unless v8_runtime?
1322
else
1423
prerender_options[:context_initializer].call v8_context
1524
prerender_options = prerender_options[:static] ? :static : true
@@ -22,12 +31,11 @@ def render(component_name, props, prerender_options)
2231
private
2332

2433
def v8_runtime?
25-
ExecJS.runtime.name == "(V8)" || ExecJS.runtime.name == "therubyrhino (Rhino)"
34+
["(V8)", "therubyrhino (Rhino)"].include?(ExecJS.runtime.name)
2635
end
2736

2837
def v8_context
29-
@v8_context ||= @context.instance_variable_get("@v8_context")
30-
@v8_context ||= @context.instance_variable_get("@rhino_context")
38+
@v8_context ||= ReactiveRuby::ServerRendering.context_instance_for(@context)
3139
end
3240
end
3341
end

reactive-ruby.gemspec

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,25 @@ Gem::Specification.new do |s|
2020

2121

2222

23-
s.add_dependency 'opal'
23+
s.add_dependency 'opal', '0.8.0'
2424
s.add_dependency 'opal-activesupport', '>= 0.2.0'
25-
s.add_dependency 'opal-browser'
25+
s.add_dependency 'opal-browser', '0.2.0'
2626
s.add_development_dependency 'rake'
27-
s.add_development_dependency 'rspec-rails'
27+
s.add_development_dependency 'rspec-rails', '3.3.3'
2828
s.add_development_dependency 'timecop'
29-
s.add_development_dependency 'opal-rspec'
29+
s.add_development_dependency 'opal-rspec', '0.4.3'
3030
s.add_development_dependency 'sinatra'
31-
s.add_development_dependency 'sqlite3' # For Test Rails App
31+
32+
# For Test Rails App
33+
s.add_development_dependency 'rails', '4.2.4'
34+
s.add_development_dependency 'react-rails', '1.3.1'
35+
s.add_development_dependency 'opal-rails', '0.8.0'
36+
if RUBY_PLATFORM == 'java'
37+
s.add_development_dependency 'jdbc-sqlite3'
38+
s.add_development_dependency 'activerecord-jdbcsqlite3-adapter'
39+
s.add_development_dependency 'therubyrhino'
40+
else
41+
s.add_development_dependency 'sqlite3', '1.3.10'
42+
s.add_development_dependency 'therubyracer', '0.12.2'
43+
end
3244
end

spec/reactive-ruby/component_loader_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
let(:js) { ::Rails.application.assets['components'].to_s }
1212
let(:context) { ExecJS.compile(GLOBAL_WRAPPER + js) }
13-
let(:v8_context) { context.instance_variable_get(:@v8_context) }
13+
let(:v8_context) { ReactiveRuby::ServerRendering.context_instance_for(context) }
1414

1515
describe '.new' do
1616
it 'raises a meaningful exception when initialized without a context' do

spec/reactive-ruby/isomorphic_helpers_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ def test_context(files = nil)
7373
end
7474
js = "#{React::ServerRendering::ExecJSRenderer::GLOBAL_WRAPPER}#{js}"
7575
ctx = ExecJS.compile(js)
76-
ctx = ctx.instance_variable_get("@v8_context")
76+
ctx = ReactiveRuby::ServerRendering.context_instance_for(ctx)
7777
end
7878

7979
def react_context

0 commit comments

Comments
 (0)