File tree Expand file tree Collapse file tree 4 files changed +18
-3
lines changed Expand file tree Collapse file tree 4 files changed +18
-3
lines changed Original file line number Diff line number Diff line change 11require 'execjs'
2+ require 'react/jsx/processor'
23require 'react/jsx/template'
34require 'react/jsx/jsx_transformer'
45require 'react/jsx/babel_transformer'
Original file line number Diff line number Diff line change 1+ module React
2+ module JSX
3+ class Processor
4+ def self . call ( input )
5+ JSX ::transform ( input [ :data ] )
6+ end
7+ end
8+ end
9+ end
Original file line number Diff line number Diff line change @@ -3,7 +3,12 @@ module Rails
33 class Engine < ::Rails ::Engine
44 initializer "react_rails.setup_engine" , :group => :all do |app |
55 sprockets_env = app . assets || Sprockets # Sprockets 3.x expects this in a different place
6- sprockets_env . register_engine ( ".jsx" , React ::JSX ::Template )
6+ if Gem ::Version . new ( Sprockets ::VERSION ) >= Gem ::Version . new ( "3.0.0" )
7+ sprockets_env . register_mime_type ( "application/jsx" , extensions : [ ".jsx" , ".js.jsx" ] )
8+ sprockets_env . register_transformer ( "application/jsx" , "application/javascript" , React ::JSX ::Processor )
9+ else
10+ sprockets_env . register_engine ( ".jsx" , React ::JSX ::Template )
11+ end
712 end
813 end
914 end
Original file line number Diff line number Diff line change @@ -19,7 +19,7 @@ class JSXTransformerTest < ActionDispatch::IntegrationTest
1919 FileUtils . rm replacing_path
2020
2121 assert_response :success
22- assert_equal 'test_confirmation_token_jsx_transformed;' , @response . body
22+ assert_equal 'test_confirmation_token_jsx_transformed;' , @response . body . strip
2323 end
2424
2525 test 'accepts harmony: true option' do
@@ -52,7 +52,7 @@ class JSXTransformerTest < ActionDispatch::IntegrationTest
5252
5353 FileUtils . rm_rf custom_path
5454 assert_response :success
55- assert_equal 'test_confirmation_token_jsx_transformed;' , @response . body
55+ assert_equal 'test_confirmation_token_jsx_transformed;' , @response . body . strip
5656 end
5757
5858end
You can’t perform that action at this time.
0 commit comments