class ReactRuby::Renderer

Public Class Methods

new(config = {}) click to toggle source
# File lib/react_ruby.rb, line 24
def initialize(config = {})
  compile(config)
end

Public Instance Methods

compile(config = {}) click to toggle source
# File lib/react_ruby.rb, line 28
    def compile(config = {})
      @config = ReactRuby.config.merge(config)
      jsx = @config[:jsx]
      jsx = JSX.transform(jsx) if jsx
      @context = ExecJS.compile(<<-JS)
        var global = global || this;
        #{@config[:react]}
        #{jsx}
        #{@config[:js]}
      JS
    end
render(jsx) click to toggle source
# File lib/react_ruby.rb, line 40
def render(jsx)
  @context.eval("React.renderToString(#{JSX.transform(jsx)})")
end