-
Notifications
You must be signed in to change notification settings - Fork 756
/
Copy pathjsx.rb
29 lines (25 loc) · 893 Bytes
/
jsx.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# frozen_string_literal: true
require "execjs"
require "react/jsx/processor"
require "react/jsx/template"
require "react/jsx/jsx_transformer"
require "react/jsx/babel_transformer"
require "react/jsx/sprockets_strategy"
require "rails"
module React
module JSX
DEFAULT_TRANSFORMER = BabelTransformer
mattr_accessor :transform_options, :transformer_class, :transformer
# You can assign `config.react.jsx_transformer_class = `
# to provide your own transformer. It must implement:
# - #initialize(options)
# - #transform(code) => new code
self.transformer_class = DEFAULT_TRANSFORMER
# @param code [String] JSX code to transform into JavaScript
# @return [String] plain, browser-ready JavaScript code
def self.transform(code)
self.transformer ||= transformer_class.new(transform_options)
self.transformer.transform(code)
end
end
end