Class: ReactRuby::Renderer
- Inherits:
-
Object
- Object
- ReactRuby::Renderer
- Defined in:
- lib/react_ruby.rb
Instance Method Summary collapse
- #compile(config = {}) ⇒ Object
-
#initialize(config = {}) ⇒ Renderer
constructor
A new instance of Renderer.
- #render(jsx) ⇒ Object
Constructor Details
#initialize(config = {}) ⇒ Renderer
Returns a new instance of Renderer.
24 25 26 |
# File 'lib/react_ruby.rb', line 24 def initialize(config = {}) compile(config) end |
Instance Method Details
#compile(config = {}) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 |
# 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(" var global = global || this;\n \#{@config[:react]}\n \#{jsx}\n \#{@config[:js]}\n JS\nend\n") |
#render(jsx) ⇒ Object
40 41 42 |
# File 'lib/react_ruby.rb', line 40 def render(jsx) @context.eval("React.renderToString(#{JSX.transform(jsx)})") end |