module React::JSX

Public Class Methods

compile(code) click to toggle source
# File lib/react/jsx.rb, line 29
def self.compile(code)
  if rubyracer?
    context.transform(code)['code']
  elsif rubyrhino?
    context['transform'].new(code)['code']
  else
    context.call('JSXTransformer.transform', code)['code']
  end
end
context() click to toggle source
# File lib/react/jsx.rb, line 6
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")
    elsif rubyrhino?
      Rhino::Context.new.eval("module={}; exports={}; #{content}; module.exports")
    else
      ExecJS.compile(content)
    end
  end
  @context
end
rubyracer?() click to toggle source
# File lib/react/jsx.rb, line 21
def self.rubyracer?
  ExecJS.runtime == ExecJS::Runtimes::RubyRacer
end
rubyrhino?() click to toggle source
# File lib/react/jsx.rb, line 25
def self.rubyrhino?
  ExecJS.runtime == ExecJS::Runtimes::RubyRhino
end