File tree 4 files changed +17
-12
lines changed
4 files changed +17
-12
lines changed Original file line number Diff line number Diff line change @@ -8,13 +8,15 @@ module JSX
8
8
def self . context
9
9
# lazily loaded during first request and reloaded every time when in dev or test
10
10
unless @context && ::Rails . env . production?
11
-
12
- # TODO: create React::Source::contents_for
13
11
contents =
14
12
# If execjs uses therubyracer, there is no 'global'. Make sure
15
13
# we have it so JSX script can work properly.
16
14
'var global = global || this;' +
17
- File . read ( React ::Source . bundled_path_for ( 'JSXTransformer.js' ) )
15
+
16
+ # search for transformer file using sprockets - allows user to override
17
+ # this file in his own application
18
+ File . read ( ::Rails . application . assets . resolve ( 'JSXTransformer.js' ) )
19
+
18
20
@context = ExecJS . compile ( contents )
19
21
end
20
22
Original file line number Diff line number Diff line change @@ -8,8 +8,6 @@ class Railtie < ::Rails::Railtie
8
8
# run after all initializers to allow sprockets to pick up react.js and
9
9
# jsxtransformer.js from end-user to override ours if needed
10
10
config . after_initialize do |app |
11
- variant = app . config . react . variant
12
-
13
11
# Mimic behavior of ember-rails...
14
12
# We want to include different files in dev/prod. The unminified builds
15
13
# contain console logging for invariants and logging to help catch
Original file line number Diff line number Diff line change @@ -27,9 +27,9 @@ class JSXTransformTest < ActionDispatch::IntegrationTest
27
27
28
28
test 'asset pipeline should transform JSX' do
29
29
get 'assets/example.js'
30
+ FileUtils . rm_r CACHE_PATH if CACHE_PATH . exist?
30
31
assert_response :success
31
32
assert_equal EXPECTED_JS , @response . body
32
- FileUtils . rm_r CACHE_PATH if CACHE_PATH . exist?
33
33
end
34
34
35
35
test 'asset pipeline should transform JSX + Coffeescript' do
@@ -50,9 +50,11 @@ class JSXTransformTest < ActionDispatch::IntegrationTest
50
50
51
51
FileUtils . mv hidden_path , replacing_path
52
52
get 'assets/example3.js'
53
- assert_response :success
54
- assert_equal 'test_confirmation_token_jsx_transformed;' , @response . body
53
+
55
54
FileUtils . mv replacing_path , hidden_path
56
55
FileUtils . rm_r CACHE_PATH if CACHE_PATH . exist?
56
+
57
+ assert_response :success
58
+ assert_equal 'test_confirmation_token_jsx_transformed;' , @response . body
57
59
end
58
60
end
Original file line number Diff line number Diff line change @@ -11,11 +11,12 @@ class ReactTest < ActionDispatch::IntegrationTest
11
11
File . open ( actual_react_file_path , 'w' ) { |f | f . write react_file_token }
12
12
13
13
get 'assets/react.js'
14
- assert_response :success
15
- assert_equal react_file_token , @response . body
16
14
17
15
File . open ( actual_react_file_path , 'w' ) { |f | f . write actual_react_file_content }
18
16
FileUtils . rm_r CACHE_PATH if CACHE_PATH . exist?
17
+
18
+ assert_response :success
19
+ assert_equal react_file_token , @response . body
19
20
end
20
21
21
22
test 'asset pipeline should deliver drop-in react file replacement' do
@@ -24,10 +25,12 @@ class ReactTest < ActionDispatch::IntegrationTest
24
25
25
26
FileUtils . mv hidden_path , replacing_path
26
27
get 'assets/react.js'
27
- assert_response :success
28
- assert_equal "'test_confirmation_token_react_content';\n " , @response . body
28
+
29
29
FileUtils . mv replacing_path , hidden_path
30
30
FileUtils . rm_r CACHE_PATH if CACHE_PATH . exist?
31
+
32
+ assert_response :success
33
+ assert_equal "'test_confirmation_token_react_content';\n " , @response . body
31
34
end
32
35
33
36
end
You can’t perform that action at this time.
0 commit comments