reactssr-rails 1.0.0 → 2.0.0

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: b2e420b41a0ac2cbd7a80791eac20d8e54656917
4
- data.tar.gz: 182e72687c06107c02c01322ee64a23277ba5564
3
+ metadata.gz: e93f6c82f62a5c0a757c3beb5072a96ffa6523b8
4
+ data.tar.gz: d8e84513f4ceff020915b18de88e9814571aa645
5
5
  SHA512:
6
- metadata.gz: 0239fd847a61cac5c7b901075b8946585ed4bd82fa637eab8ef7cb9da40ecfd4dadcdef33cc4607adf02ae2598a85d022904f78858f1b97cf58c10180d6ff496
7
- data.tar.gz: 9f8f6a3980afa5e3c21e7fb043e2fc5deae38bc628f89843a7138e51dc3c4a619d3ab15e6a146b41c183b1ac1a71e69821859d1ae625a1e6256816bf0a0fafd5
6
+ metadata.gz: 63064cfd641cfca26faa3746693ce39c1b38fcf7747b51aa3191b07f76d045853a4deaa63607799cc57489b7639b6f9330b51e3e7ec0885248c05f54f5831666
7
+ data.tar.gz: 2526c7ff49391813c491b7079b31127064061038faaa101f1e72ae776ce57a42006b85ffdeb2986d664fc214f539b061abce1c1c104d6f5b7d16cb8afdf1f008
data/README.md CHANGED
@@ -56,6 +56,15 @@ up a ssr file in components named `home.ssr.js`, just like below:
56
56
  Components.IndexView = require('./IndexView.jsx');
57
57
  ```
58
58
 
59
+ ### Make events work
60
+
61
+ Put this in your `application.js`: `//= require react_ssr` that below your Components.
62
+ This scripts will remount the component on client side so the event will be working.
63
+
64
+ According to React document, if remount the component on a markup that has been
65
+ mounted on the server side, the React will remount it in an efficient way on the
66
+ client side.
67
+
59
68
  ## Example
60
69
 
61
70
  http://github.com/towry/reactssr-rails-example
@@ -0,0 +1,73 @@
1
+ /*! (c) 2015 @tovvry */
2
+
3
+ window.Components = window.Components || {};
4
+
5
+ (function (undefined) {
6
+ function ready () {
7
+ var scripts = document.getElementsByTagName('script');
8
+ Components.__loaded = Components.__loaded || {};
9
+ var _ = Components.__loaded;
10
+
11
+ if (!scripts.length) return;
12
+ if (typeof Components === 'undefined') typeof console !== 'undefined' && console.error && console.error("`Components` global object not found.");
13
+
14
+ for (var i = 0, script; i < scripts.length; i++) {
15
+ script = scripts[i];
16
+
17
+ var view;
18
+ var node;
19
+ var props;
20
+
21
+ var lastView, len;
22
+ if (script.hasAttribute && script.hasAttribute('data-reactssr-class')) {
23
+ view = script.getAttribute('data-reactssr-class');
24
+ _[view] = _[view] || [];
25
+ len = (_[view]).length;
26
+ lastView = (_[view])[len - 1];
27
+ if (!lastView) {
28
+ lastView = {};
29
+ _[view].push(lastView);
30
+ }
31
+ lastView.script = script;
32
+ } else {
33
+ continue;
34
+ }
35
+
36
+ node = script.previousSibling;
37
+ lastView.node = node;
38
+
39
+ if (!(view in Components)) {
40
+ continue;
41
+ }
42
+
43
+ view = Components[view];
44
+ if (!view) return;
45
+
46
+ if (!node.hasAttribute('data-react-props')) {
47
+ continue;
48
+ } else {
49
+ props = node.getAttribute('data-react-props');
50
+ }
51
+
52
+ if (props) {
53
+ props = JSON.parse(props);
54
+ } else {
55
+ props = {};
56
+ }
57
+
58
+ React.render(React.createElement(view, props), node);
59
+ }
60
+ }
61
+
62
+ if (document.addEventListener) {
63
+ document.addEventListener('DOMContentLoaded', ready);
64
+ } else if (document.attachEvent) {
65
+ var whenReady = function () {
66
+ if (document.readyState === 'complete') {
67
+ document.detachEvent('onreadystatechange', whenReady);
68
+ ready();
69
+ }
70
+ };
71
+ document.attachEvent('onreadystatechange', whenReady);
72
+ }
73
+ }());
@@ -1,6 +1,8 @@
1
1
  module Reactssr
2
2
  module Rails
3
3
  class Railtie < ::Rails::Railtie
4
+ GEM_ROOT = Pathname.new('../../../../').expand_path(__FILE__)
5
+
4
6
  config.reactssr = ActiveSupport::OrderedOptions.new
5
7
 
6
8
  # The folder that contains all the stuff
@@ -14,6 +16,9 @@ module Reactssr
14
16
 
15
17
  config.before_initialize do |app|
16
18
  app.config.react.server_renderer = ::Reactssr::ServerRendering::SsrRenderer
19
+
20
+ our_asset_path = GEM_ROOT.join('lib/assets/').to_s
21
+ app.config.assets.paths << our_asset_path
17
22
  end
18
23
  end
19
24
  end
@@ -1,5 +1,5 @@
1
1
  module Reactssr
2
2
  module Rails
3
- VERSION = "1.0.0"
3
+ VERSION = "2.0.0"
4
4
  end
5
5
  end
@@ -8,7 +8,9 @@ module Reactssr
8
8
  def react_ssr(name, props = {}, options = {}, &block)
9
9
  options = {:tag => options} if options.is_a?(Symbol)
10
10
 
11
- prerender_options = true
11
+ prerender_options = options.fetch(:prerender, true)
12
+
13
+ prerender_options = true if prerender_options == false
12
14
 
13
15
  # All the below stuff is to send the `controller_name`
14
16
  # and `action_name` to our ssr_renderer.
@@ -16,13 +18,15 @@ module Reactssr
16
18
  # way, please contribute!
17
19
 
18
20
  # Let reactssr-rails handle that.
21
+
19
22
  pre_options = {
20
23
  prerender_options: prerender_options,
21
24
  controller_path: controller_path,
22
25
  action_name: action_name
23
26
  }
27
+ options.merge!(pre_options)
24
28
 
25
- block = Proc.new { concat ::React::ServerRendering.render(name, props, pre_options) }
29
+ block = Proc.new { concat ::React::ServerRendering.render(name, props, options) }
26
30
 
27
31
  html_options = options.reverse_merge(:data => {})
28
32
  html_options[:data].tap do |data|
@@ -31,9 +35,15 @@ module Reactssr
31
35
  html_tag = html_options[:tag] || :div
32
36
 
33
37
  # remove internally used properties so they aren't rendered to DOM
34
- html_options.except!(:tag, :prerender)
38
+ html_options.except!(:tag, :rerender, :prerender_options, :controller_path, :action_name)
39
+
40
+ output = content_tag(html_tag, '', html_options, &block)
41
+
42
+ if options.fetch(:rerender, false)
43
+ output << content_tag(:script, '', :data => {:reactssr_class => name.to_s})
44
+ end
35
45
 
36
- content_tag(html_tag, '', html_options, &block)
46
+ output
37
47
  end
38
48
  end
39
49
  end
@@ -103,7 +103,8 @@ module Reactssr
103
103
 
104
104
  def entry
105
105
  components = ::Rails.application.config.reactssr.assets_base || 'components'
106
- entry = File.join(components, "#{@controller_path}.ssr.js")
106
+ path = @controller_path.to_s.split('.').join('_')
107
+ entry = File.join(components, "#{path}.ssr.js")
107
108
  end
108
109
 
109
110
  private
metadata CHANGED
@@ -1,69 +1,69 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: reactssr-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - towry
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-08-19 00:00:00.000000000 Z
11
+ date: 2015-08-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ~>
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
19
  version: '1.9'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ~>
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.9'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ~>
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
33
  version: '10.0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ~>
38
+ - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '10.0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: react-rails
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - '>='
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
47
  version: 1.1.0
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - '>='
52
+ - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: 1.1.0
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: multi_json
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - '>='
59
+ - - ">="
60
60
  - !ruby/object:Gem::Version
61
61
  version: '1.0'
62
62
  type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - '>='
66
+ - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '1.0'
69
69
  description: |-
@@ -75,8 +75,8 @@ executables: []
75
75
  extensions: []
76
76
  extra_rdoc_files: []
77
77
  files:
78
- - .gitignore
79
- - .travis.yml
78
+ - ".gitignore"
79
+ - ".travis.yml"
80
80
  - CODE_OF_CONDUCT.md
81
81
  - Gemfile
82
82
  - LICENSE.txt
@@ -84,6 +84,7 @@ files:
84
84
  - Rakefile
85
85
  - bin/console
86
86
  - bin/setup
87
+ - lib/assets/react_ssr.js
87
88
  - lib/reactssr/assets/before_render.js
88
89
  - lib/reactssr/rails.rb
89
90
  - lib/reactssr/rails/engine.rb
@@ -103,18 +104,19 @@ require_paths:
103
104
  - lib
104
105
  required_ruby_version: !ruby/object:Gem::Requirement
105
106
  requirements:
106
- - - '>='
107
+ - - ">="
107
108
  - !ruby/object:Gem::Version
108
109
  version: '0'
109
110
  required_rubygems_version: !ruby/object:Gem::Requirement
110
111
  requirements:
111
- - - '>='
112
+ - - ">="
112
113
  - !ruby/object:Gem::Version
113
114
  version: '0'
114
115
  requirements: []
115
116
  rubyforge_project:
116
- rubygems_version: 2.4.6
117
+ rubygems_version: 2.4.8
117
118
  signing_key:
118
119
  specification_version: 4
119
120
  summary: React SSR in Rails
120
121
  test_files: []
122
+ has_rdoc: