Class: Wunderbar::Render

Inherits:
Object
  • Object
show all
Defined in:
lib/wunderbar/react.rb,
lib/wunderbar/vue.rb

Constant Summary collapse

RUBY2JS_OPTIONS =
{vue_h: '$h'}

Class Method Summary collapse

Class Method Details

.client(common, element, target) ⇒ Object



25
26
27
# File 'lib/wunderbar/react.rb', line 25

def self.client(common, element, target)
  "ReactDOM.render(#{common}, #{element})"
end

.eval(scripts, server) ⇒ Object



29
30
31
32
33
34
35
36
# File 'lib/wunderbar/react.rb', line 29

def self.eval(scripts, server)
  context = ExecJS.compile(scripts.compact.join(";\n"))
  context.eval(server)
rescue ExecJS::ProgramError => e
  Wunderbar.error e
  "<pre>" + e.message.gsub('&', '&amp;').gsub('<', '&lt;').gsub('>', '&gt;') +
    "</pre>"
end

.extract(nodes) ⇒ Object

unwrap children from div wrapper inserted by self.server



21
22
23
# File 'lib/wunderbar/react.rb', line 21

def self.extract(nodes)
  nodes
end

.nodejsObject

Raises:

  • (RuntimeError)


12
13
14
15
16
17
18
# File 'lib/wunderbar/vue.rb', line 12

def self.nodejs
  return @nodejs if @nodejs
  path = `which nodejs`.chomp
  path = `which node`.chomp if path.empty?
  raise RuntimeError.new('Unable to locate nodejs') if path.empty?
  @nodejs = path
end

.server(common) ⇒ Object



15
16
17
# File 'lib/wunderbar/react.rb', line 15

def self.server(common)
  "ReactDOMServer.renderToString(#{common})"
end