File tree 4 files changed +26
-3
lines changed
4 files changed +26
-3
lines changed Original file line number Diff line number Diff line change 1
1
require 'execjs'
2
+ require 'react/jsx/processor'
2
3
require 'react/jsx/template'
3
4
require 'react/jsx/jsx_transformer'
4
5
require '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 . instance
5
+ @instance ||= new
6
+ end
7
+
8
+ def self . call ( input )
9
+ instance . call ( input )
10
+ end
11
+
12
+ def call ( input )
13
+ { data : JSX ::transform ( input [ :data ] ) }
14
+ end
15
+ end
16
+ end
17
+ end
Original file line number Diff line number Diff line change @@ -3,7 +3,12 @@ module Rails
3
3
class Engine < ::Rails ::Engine
4
4
initializer "react_rails.setup_engine" , :group => :all do |app |
5
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
+ 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
7
12
end
8
13
end
9
14
end
Original file line number Diff line number Diff line change @@ -19,7 +19,7 @@ class JSXTransformerTest < ActionDispatch::IntegrationTest
19
19
FileUtils . rm replacing_path
20
20
21
21
assert_response :success
22
- assert_equal 'test_confirmation_token_jsx_transformed;' , @response . body
22
+ assert_equal 'test_confirmation_token_jsx_transformed;' , @response . body . strip
23
23
end
24
24
25
25
test 'accepts harmony: true option' do
@@ -52,7 +52,7 @@ class JSXTransformerTest < ActionDispatch::IntegrationTest
52
52
53
53
FileUtils . rm_rf custom_path
54
54
assert_response :success
55
- assert_equal 'test_confirmation_token_jsx_transformed;' , @response . body
55
+ assert_equal 'test_confirmation_token_jsx_transformed;' , @response . body . strip
56
56
end
57
57
58
58
end
You can’t perform that action at this time.
0 commit comments