Class: Guard::Templates::Jshaml::Compiler

Inherits:
Object
  • Object
show all
Defined in:
lib/guard/templates/jshaml/compiler.rb

Class Method Summary collapse

Class Method Details

.compile(str, target) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/guard/templates/jshaml/compiler.rb', line 7

def self.compile(str, target)
  engine  = ::Compiler.new
  code = engine.convert_from_string(str)

  return "function(locals) {\n  with(locals || {}) {\n    try {\n      \#{code};\n      return _$output;\n    } catch(e) {\n      console.error(\\\"Error on file: \#{target[:name]} around line \\\"+_$line+\\\"\\\\n Stack: \\\" + e.stack);\n    }\n  }\n}\n"
end