Module: React::JSX::SprocketsStrategy
- Defined in:
- lib/react/jsx/sprockets_strategy.rb
Overview
Depending on the Sprockets version, attach JSX transformation the the Sprockets environment.
You can override it with ‘config.sprockets_strategy`
Class Method Summary collapse
- .attach_with_strategy(sprockets_env, strategy_or_nil) ⇒ Object
-
.detect_strategy ⇒ Symbol
Based on the environment, return a method name to call with the sprockets environment.
- .register_engine(sprockets_env) ⇒ Object
- .register_engine_with_mime_type(sprockets_env) ⇒ Object
- .register_processors(sprockets_env) ⇒ Object
Class Method Details
.attach_with_strategy(sprockets_env, strategy_or_nil) ⇒ Object
20 21 22 23 |
# File 'lib/react/jsx/sprockets_strategy.rb', line 20 def attach_with_strategy(sprockets_env, strategy_or_nil) strategy = strategy_or_nil || detect_strategy public_send(strategy, sprockets_env) end |
.detect_strategy ⇒ Symbol
Returns based on the environment, return a method name to call with the sprockets environment.
26 27 28 29 30 31 32 33 34 35 |
# File 'lib/react/jsx/sprockets_strategy.rb', line 26 def detect_strategy sprockets_version = Gem::Version.new(Sprockets::VERSION) if sprockets_version >= Gem::Version.new("4.a") :register_processors elsif sprockets_version >= Gem::Version.new("3.0.0") :register_engine_with_mime_type else :register_engine end end |
.register_engine(sprockets_env) ⇒ Object
37 38 39 |
# File 'lib/react/jsx/sprockets_strategy.rb', line 37 def register_engine(sprockets_env) sprockets_env.register_engine(".jsx", React::JSX::Template) end |
.register_engine_with_mime_type(sprockets_env) ⇒ Object
41 42 43 44 |
# File 'lib/react/jsx/sprockets_strategy.rb', line 41 def register_engine_with_mime_type(sprockets_env) sprockets_env.register_engine(".jsx", React::JSX::Processor, mime_type: "application/javascript", silence_deprecation: true) end |
.register_processors(sprockets_env) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/react/jsx/sprockets_strategy.rb', line 46 def register_processors(sprockets_env) sprockets_env.register_mime_type("application/jsx", extensions: [".jsx", ".js.jsx", ".es.jsx", ".es6.jsx"]) sprockets_env.register_mime_type("application/jsx+coffee", extensions: [".jsx.coffee", ".js.jsx.coffee"]) sprockets_env.register_transformer("application/jsx", "application/javascript", React::JSX::Processor) sprockets_env.register_transformer("application/jsx+coffee", "application/jsx", Sprockets::CoffeeScriptProcessor) sprockets_env.register_preprocessor("application/jsx", Sprockets::DirectiveProcessor.new(comments: ["//", ["/*", "*/"]])) sprockets_env.register_preprocessor("application/jsx+coffee", Sprockets::DirectiveProcessor.new(comments: ["#", ["###", "###"]])) end |