Module: Render::React::Compiler
- Defined in:
- lib/render/react/compiler.rb
Class Method Summary collapse
Class Method Details
.cxt ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/render/react/compiler.rb', line 8 def cxt return @cxt if @cxt @cxt = Config.new_context js_lib_files = Dir.glob( File.join( Config.gem_js_path, 'compiler', '**', '*.js' ) ) js_lib_files.each { |file| @cxt.load(file) } @cxt end |
.load_components ⇒ Object
25 26 27 28 29 30 31 32 33 34 |
# File 'lib/render/react/compiler.rb', line 25 def load_components Config.paths.each do |path| files = Dir.glob(File.join(path, '**', '*.js')) files.each do |filename| name, code = Transpiler.babelify(filename) cxt.eval(code) lookup[name.to_sym] = true end end end |
.lookup ⇒ Object
4 5 6 |
# File 'lib/render/react/compiler.rb', line 4 def lookup @lookup ||= {} end |
.render(component_class, **props) ⇒ Object
36 37 38 39 40 41 42 43 44 45 |
# File 'lib/render/react/compiler.rb', line 36 def render(component_class, **props) unless lookup[component_class.to_sym] raise "#{component_class} component not found." end cxt.eval " ReactDOMServer.renderToString(\n React.createElement(\#{component_class}, \#{JSON.dump(props)})\n );\n EOS\nend\n" |