diff --git a/README.md b/README.md index 6f8a128a4..be56b4669 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,7 @@ As with all gem dependencies, we strongly recommend adding `react-rails` to your ```ruby # Gemfile -gem 'react-rails', '~> 0.10.0.0' +gem 'react-rails', '~> 0.13.0.0' ``` @@ -46,7 +46,7 @@ Alternatively, you can include it directly as a separate script tag: ### JSX -To transform your JSX into JS, simply create `.js.jsx` files, and ensure that the file has the `/** @jsx React.DOM */` docblock. These files will be transformed on request, or precompiled as part of the `assets:precompile` task. +To transform your JSX into JS, simply create `.js.jsx` files. These files will be transformed on request, or precompiled as part of the `assets:precompile` task. ## Configuring @@ -80,13 +80,17 @@ end ## CoffeeScript -It is possible to use JSX with CoffeeScript. The caveat is that you will still need to include the docblock. Since CoffeeScript doesn't allow `/* */` style comments, we need to do something a little different. We also need to embed JSX inside backticks so CoffeeScript ignores the syntax it doesn't understand. Here's an example: +It is possible to use JSX with CoffeeScript. We need to embed JSX inside backticks so CoffeeScript ignores the syntax it doesn't understand. Here's an example: ```coffee -###* @jsx React.DOM ### - Component = React.createClass render: -> `` ``` - +You can use the `--harmony` or `--strip-types` options by adding a configuration to `application.rb`: +```ruby +config.react.jsx_transform_options = { + harmony: true, + strip_types: true, # for removing Flow type annotations +} +``` diff --git a/gemfiles/rails_3.1.gemfile b/gemfiles/rails_3.1.gemfile index 58db7a878..fac5a109b 100644 --- a/gemfiles/rails_3.1.gemfile +++ b/gemfiles/rails_3.1.gemfile @@ -4,4 +4,4 @@ source "http://rubygems.org" gem "rails", "~> 3.1" -gemspec :path=>"../" \ No newline at end of file +gemspec :path => "../" diff --git a/gemfiles/rails_3.2.gemfile b/gemfiles/rails_3.2.gemfile index 779ce7c6e..0b2047cf5 100644 --- a/gemfiles/rails_3.2.gemfile +++ b/gemfiles/rails_3.2.gemfile @@ -4,4 +4,4 @@ source "http://rubygems.org" gem "rails", "~> 3.2" -gemspec :path=>"../" \ No newline at end of file +gemspec :path => "../" diff --git a/gemfiles/rails_4.0.gemfile b/gemfiles/rails_4.0.gemfile index d54014891..a3fdee2c0 100644 --- a/gemfiles/rails_4.0.gemfile +++ b/gemfiles/rails_4.0.gemfile @@ -4,4 +4,4 @@ source "http://rubygems.org" gem "rails", "~> 4.0" -gemspec :path=>"../" \ No newline at end of file +gemspec :path => "../" diff --git a/gemfiles/rails_4.0_with_therubyracer.gemfile b/gemfiles/rails_4.0_with_therubyracer.gemfile index ce64ea2ce..a8f5be006 100644 --- a/gemfiles/rails_4.0_with_therubyracer.gemfile +++ b/gemfiles/rails_4.0_with_therubyracer.gemfile @@ -3,6 +3,6 @@ source "http://rubygems.org" gem "rails", "~> 4.0" -gem "therubyracer", "0.12.0", :platform=>:mri +gem "therubyracer", "0.12.0", :platform => :mri -gemspec :path=>"../" \ No newline at end of file +gemspec :path => "../" diff --git a/lib/react/jsx.rb b/lib/react/jsx.rb index c9cfa24c1..17e101f94 100644 --- a/lib/react/jsx.rb +++ b/lib/react/jsx.rb @@ -4,6 +4,7 @@ module React module JSX + mattr_accessor :transform_options def self.context # TODO: create React::Source::contents_for contents = @@ -14,8 +15,12 @@ def self.context @context ||= ExecJS.compile(contents) end - def self.transform(code) - result = context.call('JSXTransformer.transform', code) + def self.transform(code, options={}) + js_options = { + stripTypes: options[:strip_types], + harmony: options[:harmony], + } + result = context.call('JSXTransformer.transform', code, js_options) return result['code'] end end diff --git a/lib/react/jsx/template.rb b/lib/react/jsx/template.rb index 3118b5fb8..244bb04cf 100644 --- a/lib/react/jsx/template.rb +++ b/lib/react/jsx/template.rb @@ -10,7 +10,7 @@ def prepare end def evaluate(scopre, locals, &block) - @output ||= JSX::transform(data) + @output ||= JSX::transform(data, JSX.transform_options) end end end diff --git a/lib/react/rails/railtie.rb b/lib/react/rails/railtie.rb index d1e753ead..1681673c6 100644 --- a/lib/react/rails/railtie.rb +++ b/lib/react/rails/railtie.rb @@ -15,7 +15,7 @@ class Railtie < ::Rails::Railtie if variant = app.config.react.variant || ::Rails.env.test? variant ||= :development addons = app.config.react.addons || false - + React::JSX.transform_options = app.config.react.jsx_transform_options # Copy over the variant into a path that sprockets will pick up. # We'll always copy to 'react.js' so that no includes need to change. # We'll also always copy of JSXTransformer.js diff --git a/lib/react/rails/version.rb b/lib/react/rails/version.rb index 968450111..465028929 100644 --- a/lib/react/rails/version.rb +++ b/lib/react/rails/version.rb @@ -2,7 +2,7 @@ module React module Rails # Version numbers will track react-source, but we'll add another level so # that we can increment, but have some amount of stability. - VERSION = '0.10.0.0' + VERSION = '0.13.0.0' end end diff --git a/react-rails.gemspec b/react-rails.gemspec index c341ed92e..64d84c619 100644 --- a/react-rails.gemspec +++ b/react-rails.gemspec @@ -20,7 +20,8 @@ Gem::Specification.new do |s| s.add_dependency 'execjs' s.add_dependency 'rails', '>= 3.1' - s.add_dependency 'react-source', '0.10.0' + s.add_dependency 'react-source', '0.13.0' + s.add_dependency 'tilt' s.files = Dir[ 'lib/**/*', diff --git a/test/dummy/app/assets/javascripts/example.js.jsx b/test/dummy/app/assets/javascripts/example.js.jsx index 2611211ae..5becf72d5 100644 --- a/test/dummy/app/assets/javascripts/example.js.jsx +++ b/test/dummy/app/assets/javascripts/example.js.jsx @@ -1,2 +1 @@ -/** @jsx React.DOM */
; diff --git a/test/dummy/app/assets/javascripts/example2.js.jsx.coffee b/test/dummy/app/assets/javascripts/example2.js.jsx.coffee index 6bb2e5528..1bdfe5594 100644 --- a/test/dummy/app/assets/javascripts/example2.js.jsx.coffee +++ b/test/dummy/app/assets/javascripts/example2.js.jsx.coffee @@ -1,5 +1,3 @@ -###* @jsx React.DOM ### - Component = React.createClass render: -> `` diff --git a/test/dummy/config/application.rb b/test/dummy/config/application.rb index e619601c7..a9d08600c 100644 --- a/test/dummy/config/application.rb +++ b/test/dummy/config/application.rb @@ -26,5 +26,9 @@ class Application < Rails::Application config.react.variant = :production config.assets.enabled = true + config.react.jsx_transform_options = { + harmony: true, + strip_types: true, # for removing Flow type annotations + } end end diff --git a/test/jsxtransform_test.rb b/test/jsxtransform_test.rb index c1479fa95..16b48a352 100644 --- a/test/jsxtransform_test.rb +++ b/test/jsxtransform_test.rb @@ -2,21 +2,16 @@ # The transformer is inserting a newline after the docblock for some reason... EXPECTED_JS = < pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy