Module: Wunderbar::Template::Js

Defined in:
lib/wunderbar/script.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.extObject



81
# File 'lib/wunderbar/script.rb', line 81

def self.ext; ['js.rb', :_js]; end

.mimeObject



82
# File 'lib/wunderbar/script.rb', line 82

def self.mime; 'application/javascript'; end

Instance Method Details

#evaluate(scope, locals, &block) ⇒ Object



84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/wunderbar/script.rb', line 84

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