Class: HamlCoffeeTemplate::Compiler

Inherits:
Object
  • Object
show all
Defined in:
lib/haml_coffee_template/compiler.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeCompiler

Returns a new instance of Compiler.



7
8
9
# File 'lib/haml_coffee_template/compiler.rb', line 7

def initialize
  @runtime = ExecJS.compile(runtime_source)
end

Instance Attribute Details

#runtimeObject (readonly)

Returns the value of attribute runtime.



5
6
7
# File 'lib/haml_coffee_template/compiler.rb', line 5

def runtime
  @runtime
end

Instance Method Details

#coffeescript_sourceObject



33
34
35
# File 'lib/haml_coffee_template/compiler.rb', line 33

def coffeescript_source
  File.read(CoffeeScript::Source.path)
end

#compile(source) ⇒ Object



21
22
23
24
25
26
27
# File 'lib/haml_coffee_template/compiler.rb', line 21

def compile(source)
  runtime.call(
    "HamlCoffeeTemplate.compile",
    source,
    HamlCoffeeTemplate.configuration.compiler_options
  )
end

#hamlcoffee_sourceObject



37
38
39
# File 'lib/haml_coffee_template/compiler.rb', line 37

def hamlcoffee_source
  File.read(HamlCoffeeTemplate.configuration.hamlcoffee_path)
end

#runtime_sourceObject



29
30
31
# File 'lib/haml_coffee_template/compiler.rb', line 29

def runtime_source
  [coffeescript_source, hamlcoffee_source, wrapper_source].join(";")
end

#template(name, source) ⇒ Object



11
12
13
14
15
16
17
18
19
# File 'lib/haml_coffee_template/compiler.rb', line 11

def template(name, source)
  runtime.call(
    "HamlCoffeeTemplate.template",
    source,
    name,
    HamlCoffeeTemplate.configuration.namespace,
    HamlCoffeeTemplate.configuration.compiler_options
  )
end

#wrapper_script_pathObject



45
46
47
# File 'lib/haml_coffee_template/compiler.rb', line 45

def wrapper_script_path
  File.expand_path("wrapper.js", __dir__)
end

#wrapper_sourceObject



41
42
43
# File 'lib/haml_coffee_template/compiler.rb', line 41

def wrapper_source
  File.read(wrapper_script_path)
end