class ReactTemplates::Template

Public Instance Methods

context() click to toggle source
# File lib/react-templates/template.rb, line 3
def context
  @context ||= ExecJS.compile(context_js)
end
evaluate(scope, locals, &block) click to toggle source
# File lib/react-templates/template.rb, line 10
def evaluate(scope, locals, &block)
  template(scope.logical_path)
end
prepare() click to toggle source
# File lib/react-templates/template.rb, line 7
def prepare
end

Private Instance Methods

context_js() click to toggle source
# File lib/react-templates/template.rb, line 36
def context_js
  "var window = {}, global = this; #{File.read(js_path)}"
end
js_path() click to toggle source
# File lib/react-templates/template.rb, line 32
def js_path
  File.join(File.dirname(__FILE__),'..','..','assets','rt-main.browser.js')
end
react_template() click to toggle source
# File lib/react-templates/template.rb, line 25
def react_template
  context.call(
    'window.reactTemplates.convertTemplateToReact',
    data,
    modules: 'jsrt')
end
template(template_name) click to toggle source
# File lib/react-templates/template.rb, line 16
    def template(template_name)
      <<-JS
        (function() {
          if (typeof(window.JST) == 'undefined') { window.JST = {}; }
          window.JST[#{template_name.to_json}] = #{react_template};
        }());
      JS
    end