Skip to content

Commit 81dddc0

Browse files
committed
Switch to the new Sprockets processor
1 parent 0573ae2 commit 81dddc0

File tree

3 files changed

+24
-1
lines changed

3 files changed

+24
-1
lines changed

lib/react/jsx.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
require 'execjs'
2+
require 'react/jsx/processor'
23
require 'react/jsx/template'
34
require 'react/jsx/jsx_transformer'
45
require 'react/jsx/babel_transformer'

lib/react/jsx/processor.rb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
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+
@output ||= JSX::transform(input[:data])
14+
end
15+
end
16+
end
17+
end

lib/react/rails/engine.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff 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

0 commit comments

Comments
 (0)