module ExecJS::Rails::Renderer
Public Class Methods
call(function, *args)
click to toggle source
# File lib/execjs/rails/renderer.rb, line 26 def self.call(function, *args) self.reset! unless @@context @@context.call(function, *args) end
config()
click to toggle source
# File lib/execjs/rails/renderer.rb, line 12 def self.config @@config end
dump_render_context(path, assigns, options={})
click to toggle source
# File lib/execjs/rails/renderer.rb, line 52 def self.dump_render_context(path, assigns, options={}) source = @@config.debug_dump_prefix + @@config.build_source.call() + "; #{ @@config.handler_function_name }('#{ path }', '#{ options }');" file = File.open(assigns['__execjs_rails_dump_file'], 'w') file.write(source) file.close() puts "Wrote render context dump to #{ file.path }. If you have node-inspector installed, you can debug it with: " puts "node-debug #{ file.path }" end
find_and_render(path, opts = {})
click to toggle source
Check for template using has_view
and render if we have it. Otherwise, fail with a template missing error that leads back here
# File lib/execjs/rails/renderer.rb, line 43 def self.find_and_render(path, opts = {}) if has_view(path) render(path, opts) else # Throw a missing template error if we don't have it fail ::ActionView::MissingTemplate.new(["ExecJS::Rails::Renderer"], path, [], true, {}) end end
has_view(path)
click to toggle source
# File lib/execjs/rails/renderer.rb, line 31 def self.has_view(path) self.call(@@config.has_view_function_name, path) end
render(path, opts = {})
click to toggle source
# 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!()
click to toggle source
# File lib/execjs/rails/renderer.rb, line 16 def self.reset! unless @@config.memoize_context && !@@context.nil? begin @@context = ExecJS.compile(@@config.build_source.call()) rescue ExecJS::Rails::RuntimeSupport.error_class => error @@config.on_error.call(error) end end end
setup!(config = {})
click to toggle source
# File lib/execjs/rails/renderer.rb, line 8 def self.setup!(config = {}) @@config = config end