Module: ExecJS::Rails::Renderer

Defined in:
lib/execjs/rails/renderer.rb

Constant Summary collapse

@@config =
nil
@@context =
nil

Class Method Summary collapse

Class Method Details

.call(function, *args) ⇒ Object



27
28
29
# File 'lib/execjs/rails/renderer.rb', line 27

def self.call(function, *args)
  @@context.call(function, *args)
end

.configObject



13
14
15
# File 'lib/execjs/rails/renderer.rb', line 13

def self.config
  @@config
end

.has_view(path) ⇒ Object



31
32
33
# File 'lib/execjs/rails/renderer.rb', line 31

def self.has_view(path)
  @@context.call(@@config.has_view_function_name, path)
end

.render(path, opts = {}) ⇒ Object



35
36
37
38
39
# File 'lib/execjs/rails/renderer.rb', line 35

def self.render(path, opts = {})
  output = self.call(@@config.handler_function_name, path, opts)
  fail "ExecJS call to render function `#{function}` returned null" if output.nil?
  output.html_safe
end

.reset!Object



17
18
19
20
21
22
23
24
25
# File 'lib/execjs/rails/renderer.rb', line 17

def self.reset!
  unless @@config.memoize_context? && !@@context.nil?
    begin
      @@context = ExecJS.compile(@@config.build_source.call())
    rescue V8::Error => error
      @@config.on_error.call(error)
    end
  end
end

.setup!(config = {}) ⇒ Object



8
9
10
11
# File 'lib/execjs/rails/renderer.rb', line 8

def self.setup!(config = {})
  @@config = config
  self.reset!
end