module Wunderbar::Template::Js

Public Class Methods

ext() click to toggle source
# File lib/wunderbar/script.rb, line 83
def self.ext; ['js.rb', :_js]; end
mime() click to toggle source
# File lib/wunderbar/script.rb, line 84
def self.mime; 'application/javascript'; end

Public Instance Methods

evaluate(scope, locals, &block) click to toggle source
# File lib/wunderbar/script.rb, line 86
def evaluate(scope, locals, &block)
  scope.content_type self.class.default_mime_type, charset: 'utf-8'
  begin
    Ruby2JS.convert(block ? block : data, ivars: locals, file: file).to_s
  rescue Parser::SyntaxError => exception
    scope.response.status = Wunderbar::ServerError.status
    location = exception.diagnostic.location
    "Syntax Error: line #{location.line}, column: #{location.column}" +
      "\n#{exception}\n"
  rescue Exception => exception
    scope.response.status = Wunderbar::ServerError.status
    output = "Internal Server Error: #{exception}\n"
    exception.backtrace.each do |frame| 
      next if CALLERS_TO_IGNORE.any? {|re| frame =~ re}
      output += "  #{frame}\n"
    end
    output
  end
end