Class: Rt::Transformer

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/rt/transformer.rb

Instance Method Summary collapse

Constructor Details

#initializeTransformer

Returns a new instance of Transformer.



8
9
10
11
12
# File 'lib/rt/transformer.rb', line 8

def initialize
  js_path = File.join File.dirname(__FILE__), "../js/react-templates.min.js"
  contents = "var global = global || this;" + File.read(js_path)
  @context = ExecJS.compile(contents)
end

Instance Method Details

#call(code, options = {}) ⇒ Object



14
15
16
17
18
19
# File 'lib/rt/transformer.rb', line 14

def call code, options={}
  name = options[:name] || nil
  modules = options[:modules] || "commonjs"

  @context.call "global.reactTemplates.convertTemplateToReact", code, {modules: modules, name: name}
end