react_on_rails 0.1.0 → 0.1.1

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: f3d6a3770f22b5c124f17556203f1b1a74fd550b
4
- data.tar.gz: 779c9ccbca94e36754c0fa90d60ab12aa8bf4785
3
+ metadata.gz: c32d5d1549cefdb05c11593b8fc46357c3a2b51a
4
+ data.tar.gz: c9a61af04d0b81767c48e155a6cd8af8e9081cc4
5
5
  SHA512:
6
- metadata.gz: 47688d10f95c09bc2b9dcdb86744319c9e15b071d7c10de1c204c3a1815b793089ef2da7699a15a4bb7f314796e8d8dd7f608bdc43bc401497e2f9e61d239806
7
- data.tar.gz: 5701bc9218429a92987a9160de14cd37a8965b5298bc2535eb632adb1639087afde627136a7a11f938bfa7cfa898b89631094f334dd25b5bb29a34ae5365c61a
6
+ metadata.gz: ebc8347894681090d81c8e1580aebadaf36fc0465ac9635e054362584c737d22d8d659ec4bd8412bd914cd7adb5b1a3a8cdf880fa5ea6db8ff3a3550d39a21a2
7
+ data.tar.gz: ff1e4ab63b241615882224a88666f8c2dc04ea29133881649ba31f539e816a638851924b85c45003e2dfdfd73506336e428f1cdbfbcc36daff7905a7b3286bbf
data/.gitignore CHANGED
@@ -7,7 +7,7 @@
7
7
  /pkg/
8
8
  /spec/reports/
9
9
  /tmp/
10
-
10
+ *.gem
11
11
 
12
12
  /spec/dummy/client/node_modules
13
13
  /spec/dummy/app/assets/javascripts/generated/
@@ -15,3 +15,4 @@
15
15
  # RVM
16
16
  .ruby-version
17
17
  .ruby-gemset
18
+
data/README.md CHANGED
@@ -1,7 +1,11 @@
1
- # ReactOnRails
1
+ # React On Rails
2
2
 
3
3
  Published: https://rubygems.org/gems/react_on_rails
4
4
 
5
+ See [Action Plan for v1.0](https://github.com/shakacode/react_on_rails/issues/1)
6
+
7
+ Feedback and pull-requests encouraged! Thanks in advance!
8
+
5
9
  Supports:
6
10
 
7
11
  1. Rails
@@ -10,6 +14,7 @@ Supports:
10
14
  4. Redux
11
15
  5. Turbolinks
12
16
  6. Server side rendering with fragment caching
17
+ 7. react-router for client side rendering (and maybe server side eventually)
13
18
 
14
19
  # Authors
15
20
  The Shaka Code team!
@@ -21,7 +26,7 @@ The Shaka Code team!
21
26
  And based on the work of the [react-rails gem](https://github.com/reactjs/react-rails)
22
27
 
23
28
  # Key Info
24
- Currently in proof of concept phase.
29
+ Currently being implemented in 3 production projects (not yet live).
25
30
 
26
31
  1. https://github.com/justin808/react-webpack-rails-tutorial/
27
32
  2. http://www.railsonmaui.com/blog/2014/10/03/integrating-webpack-and-the-es6-transpiler-into-an-existing-rails-project/
@@ -56,13 +61,25 @@ Contributions and pull requests welcome!
56
61
 
57
62
  # Key Tips
58
63
  1. See sample app in `spec/dummy` for how to set this up.
59
- 2. The file used for server rendering is hard coded as generated/server.js
60
- (assets/javascripts/generated/server.js)
61
- 3. The default for rendering right now is `prerender: true`. **NOTE:** This does not work for
62
- components, namely react-router, that use an async setup for server rendering.
64
+ 2. The file used for server rendering is hard coded as `generated/server.js`
65
+ (assets/javascripts/generated/server.js).
66
+ 3. If you're only doing client rendering, you still *MUST* create an empty version of this file. This
67
+ will soon change so that this is not necessary.
68
+ 3. The default for rendering right now is `prerender: false`. **NOTE:** Server side rendering does
69
+ not work for some components, namely react-router, that use an async setup for server rendering.
70
+ You can configure the default for prerender in your config.
63
71
  4. The API for objects exposed differs from the react-rails gem in that you expose a function that
64
72
  returns a react component. We'll be changing that to take either a function or a React component.
65
73
 
74
+ # Example Configuration, config/react_on_rails.rb
75
+ ```ruby
76
+ ReactOnRails.configure do |config|
77
+ config.bundle_js_file = "app/assets/javascripts/generated/server.js" # This is the default
78
+ config.prerender = true # default is false
79
+ end
80
+ ```
81
+
82
+
66
83
  ## References
67
84
  * [Making the helper for server side rendering work with JS created by Webpack] (https://github.com/reactjs/react-rails/issues/301#issuecomment-133098974)
68
85
  * [Add Demonstration of Server Side Rendering](https://github.com/justin808/react-webpack-rails-tutorial/issues/2)
@@ -25,9 +25,8 @@ module ReactOnRailsHelper
25
25
  # (re-hydrate the data). This enables react rendered on the client to see that the
26
26
  # server has already rendered the HTML.
27
27
  @react_component_index ||= 0
28
-
29
- prerender = options[:prerender].nil? ? true : options[:prerender]
30
- trace = options[:trace].nil? ? false : options[:trace]
28
+ prerender = options.fetch(:prerender) { ReactOnRails.configuration.prerender }
29
+ trace = options.fetch(:trace, false)
31
30
 
32
31
  dataVariable = "__#{component_name.camelize(:lower)}Data#{@react_component_index}__"
33
32
  reactComponent = component_name.camelize
@@ -49,7 +48,6 @@ module ReactOnRailsHelper
49
48
 
50
49
  # Create the HTML rendering part
51
50
  if prerender
52
-
53
51
  render_js_expression = <<-JS
54
52
  renderReactComponent(this.#{reactComponent}, #{props.to_json})
55
53
  JS
@@ -1,4 +1,7 @@
1
+ require "rails"
2
+
1
3
  require "react_on_rails/version"
4
+ require "react_on_rails/configuration"
2
5
 
3
6
  module ReactOnRails
4
7
  class Engine < ::Rails::Engine
@@ -0,0 +1,21 @@
1
+ module ReactOnRails
2
+ def self.configure
3
+ yield(configuration)
4
+ end
5
+
6
+ def self.configuration
7
+ @configuration ||= Configuration.new(
8
+ bundle_js_file: "app/assets/javascripts/generated/server.js",
9
+ prerender: false
10
+ )
11
+ end
12
+
13
+ class Configuration
14
+ attr_accessor :bundle_js_file, :prerender
15
+
16
+ def initialize(bundle_js_file:, prerender:)
17
+ self.bundle_js_file = bundle_js_file
18
+ self.prerender = prerender
19
+ end
20
+ end
21
+ end
@@ -35,10 +35,8 @@ module ReactOnRails
35
35
  private
36
36
 
37
37
  def bundle_js_code
38
- # Calling to_s to get contents of sprockets.
39
-
40
- # TODO: Make this file name configurable
41
- Rails.application.assets['generated/server.js'].to_s
38
+ js_file = Rails.root.join(ReactOnRails.configuration.bundle_js_file)
39
+ File.read(js_file)
42
40
  end
43
41
  end
44
42
  end
@@ -1,3 +1,3 @@
1
1
  module ReactOnRails
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: react_on_rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Justin Gordon
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-08-28 00:00:00.000000000 Z
11
+ date: 2015-09-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -97,6 +97,7 @@ files:
97
97
  - Rakefile
98
98
  - app/helpers/react_on_rails_helper.rb
99
99
  - lib/react_on_rails.rb
100
+ - lib/react_on_rails/configuration.rb
100
101
  - lib/react_on_rails/react_renderer.rb
101
102
  - lib/react_on_rails/version.rb
102
103
  - react_on_rails.gemspec
@@ -125,3 +126,4 @@ signing_key:
125
126
  specification_version: 4
126
127
  summary: Rails with react server rendering with webpack.
127
128
  test_files: []
129
+ has_rdoc: