Module: React::JSX

Defined in:
lib/react/jsx.rb

Class Method Summary collapse

Class Method Details

.compile(code) ⇒ Object



6
7
8
9
10
11
12
# File 'lib/react/jsx.rb', line 6

def self.compile(code)
  if rubyracer?
    context.transform(code)['code']
  else
    context.call('JSXTransformer.transform', code)['code']
  end
end

.contextObject



14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/react/jsx.rb', line 14

def self.context
  unless @context
    content = File.read(React::Source.bundled_path_for('JSXTransformer.js'))

    @context = if rubyracer?
      V8::Context.new.eval("module={}; exports={}; #{content}; module.exports")
    else
      ExecJS.compile(content)
    end
  end
  @context
end

.rubyracer?Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/react/jsx.rb', line 27

def self.rubyracer?
  ExecJS.runtime == ExecJS::Runtimes::RubyRacer
end