react-rails 1.1.0 → 1.2.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: 1785903da4681e238fd6ece7f7ddc357b3c680fb
4
- data.tar.gz: 10df40460f093699de10da330576134354b7513c
3
+ metadata.gz: 15df12f33d7eebb048c97c8cd0bb64e95ccce6aa
4
+ data.tar.gz: ed212e1fdfa9fd6aa5f401cf931e9d0d72a22d24
5
5
  SHA512:
6
- metadata.gz: 0da59c7aad8e5ca06a1771ffb2bf1df7cb41da8c15bb4dd62669cdd007b35997cd9d8b6e8369d2ad0cded7096ee853507c7de2c2e17fb9d313871824d1432ca2
7
- data.tar.gz: 4d07c2bc45a590aab49e9bf53410728bbedaa44157827fcced1973f267f79535414b6c73f4eea8a50deca5b9a933bc521cb583050f97681fa6e7207c76c427b2
6
+ metadata.gz: 426958555a561b2b3bd2ea3954919123b5f7cbc764892c426b3d461b43650384fc5f1d570a65eb8eec156aac9108f1917b98987cbeff71ce50ecce270220d10b
7
+ data.tar.gz: c2c7cd00745aa11c70c04295d6aeb8461777a1279dacafcc48df1ea2b4bffba025de5130953ba1c829f7c3e8350b26c79297f042d3cab42cf330b51eb3b01706
data/README.md CHANGED
@@ -129,10 +129,9 @@ The __view helper__ puts a `div` on the page with the requested component class
129
129
  ```
130
130
 
131
131
  On page load, the __`react_ujs` driver__ will scan the page and mount components using `data-react-class`
132
- and `data-react-props`. Before page unload, it will unmount components (if you want to disable this behavior,
133
- remove `data-react-class` attribute in `componentDidMount`).
132
+ and `data-react-props`.
134
133
 
135
- `react_ujs` uses Turbolinks events if they're available, otherwise, it uses native events.
134
+ If Turbolinks is present components are mounted on the `page:change` event, and unmounted on `page:before-unload`.
136
135
  __Turbolinks >= 2.4.0__ is recommended because it exposes better events.
137
136
 
138
137
  The view helper's signature is:
@@ -151,8 +150,6 @@ react_component(component_class_name, props={}, html_options={})
151
150
 
152
151
  ### Server rendering
153
152
 
154
- (This documentation is for the __`master` branch__, please check the [__`1.0.0` README__](https://github.com/reactjs/react-rails/tree/v1.0.0#server-rendering) for that API!)
155
-
156
153
  To render components on the server, pass `prerender: true` to `react_component`:
157
154
 
158
155
  ```erb
@@ -205,7 +202,7 @@ end
205
202
  ### Component generator
206
203
 
207
204
  `react-rails` ships with a Rails generator to help you get started with a simple component scaffold.
208
- You can run it using `rails generate react:component ComponentName`.
205
+ You can run it using `rails generate react:component ComponentName (--es6)`.
209
206
  The generator takes an optional list of arguments for default propTypes,
210
207
  which follow the conventions set in the [Reusable Components](http://facebook.github.io/react/docs/reusable-components.html)
211
208
  section of the React documentation.
@@ -240,6 +237,18 @@ var Post = React.createClass({
240
237
  });
241
238
  ```
242
239
 
240
+ #### Options
241
+
242
+ **--es6** : Generate the same component but using cutting edge es6 class
243
+
244
+ For example:
245
+
246
+ ```shell
247
+ rails generate react:component Label label:string --es6
248
+ ```
249
+
250
+ #### Arguments
251
+
243
252
  The generator can use the following arguments to create basic propTypes:
244
253
 
245
254
  * any
@@ -89,10 +89,8 @@
89
89
  function handleNativeEvents() {
90
90
  if ($) {
91
91
  $(function() {window.ReactRailsUJS.mountComponents()});
92
- $(window).unload(function() {window.ReactRailsUJS.unmountComponents()});
93
92
  } else {
94
93
  document.addEventListener('DOMContentLoaded', function() {window.ReactRailsUJS.mountComponents()});
95
- window.addEventListener('unload', function() {window.ReactRailsUJS.unmountComponents()});
96
94
  }
97
95
  }
98
96
 
@@ -50,6 +50,11 @@ module React
50
50
  :default => [],
51
51
  :banner => "field[:type] field[:type] ..."
52
52
 
53
+ class_option :es6,
54
+ type: :boolean,
55
+ default: false,
56
+ desc: 'Output es6 class based component'
57
+
53
58
  REACT_PROP_TYPES = {
54
59
  "node" => 'React.PropTypes.node',
55
60
  "bool" => 'React.PropTypes.bool',
@@ -80,7 +85,7 @@ module React
80
85
  }
81
86
 
82
87
  def create_component_file
83
- extension = "js.jsx"
88
+ extension = options[:es6] ? "es6.jsx" : "js.jsx"
84
89
  file_path = File.join('app/assets/javascripts/components', "#{file_name}.#{extension}")
85
90
  template("component.#{extension}", file_path)
86
91
  end
@@ -0,0 +1,23 @@
1
+ class <%= file_name.camelize %> extends React.Component {
2
+ render () {
3
+ <% if attributes.size > 0 -%>
4
+ return (
5
+ <div>
6
+ <% attributes.each do |attribute| -%>
7
+ <div><%= attribute[:name].titleize %>: {this.props.<%= attribute[:name].camelize(:lower) %>}</div>
8
+ <% end -%>
9
+ </div>
10
+ );
11
+ <% else -%>
12
+ return <div />;
13
+ <% end -%>
14
+ }
15
+ }
16
+
17
+ <% if attributes.size > 0 -%>
18
+ <%= file_name.camelize %>.propTypes = {
19
+ <% attributes.each_with_index do |attribute, idx| -%>
20
+ <%= attribute[:name].camelize(:lower) %>: <%= attribute[:type] %><% if (idx < attributes.length-1) %>,<% end %>
21
+ <% end -%>
22
+ };
23
+ <% end -%>
@@ -1,4 +1,5 @@
1
1
  require 'react/rails/asset_variant'
2
2
  require 'react/rails/engine'
3
3
  require 'react/rails/railtie'
4
+ require 'react/rails/version'
4
5
  require 'react/rails/view_helper'
@@ -2,7 +2,8 @@ module React
2
2
  module Rails
3
3
  class Engine < ::Rails::Engine
4
4
  initializer "react_rails.setup_engine", :group => :all do |app|
5
- app.assets.register_engine '.jsx', React::JSX::Template
5
+ sprockets_env = app.assets || Sprockets # Sprockets 3.x expects this in a different place
6
+ sprockets_env.register_engine(".jsx", React::JSX::Template)
6
7
  end
7
8
  end
8
9
  end
@@ -38,10 +38,9 @@ module React
38
38
  addons: app.config.react.addons,
39
39
  })
40
40
 
41
- app.assets.version = [
42
- app.assets.version,
43
- "react-#{asset_variant.react_build}",
44
- ].compact.join('-')
41
+ sprockets_env = app.assets || app.config.assets # sprockets-rails 3.x attaches this at a different config
42
+ sprockets_env.version = [sprockets_env.version, "react-#{asset_variant.react_build}",].compact.join('-')
43
+
45
44
  end
46
45
 
47
46
  config.before_initialize do |app|
@@ -1,6 +1,6 @@
1
1
  module React
2
2
  module Rails
3
3
  # If you change this, make sure to update VERSIONS.md
4
- VERSION = '1.1.0'
4
+ VERSION = '1.2.0'
5
5
  end
6
6
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: react-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Paul O’Shannessy
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-07-09 00:00:00.000000000 Z
11
+ date: 2015-08-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: appraisal
@@ -263,6 +263,7 @@ files:
263
263
  - lib/assets/react-source/production-with-addons/react.js
264
264
  - lib/generators/react/component_generator.rb
265
265
  - lib/generators/react/install_generator.rb
266
+ - lib/generators/templates/component.es6.jsx
266
267
  - lib/generators/templates/component.js.jsx
267
268
  - lib/react/jsx/babel_transformer.rb
268
269
  - lib/react/jsx/jsx_transformer.rb