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



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

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

#compile(source) ⇒ Object



23
24
25
26
27
28
29
30
# File 'lib/haml_coffee_template/compiler.rb', line 23

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

#haml_coffee_sourceObject



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

def haml_coffee_source
  File.read(HamlCoffeeTemplate.configuration.haml_coffee_path)
end

#runtime_sourceObject



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

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

#template(name, source) ⇒ Object



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

def template(name, source)
  haml_coffee_compiler_options = HamlCoffeeTemplate.configuration.haml_coffee_compiler_options.dup
  haml_coffee_compiler_options[:name] = name
  haml_coffee_compiler_options[:namespace] = HamlCoffeeTemplate.configuration.namespace
  runtime.call(
    "HamlCoffeeTemplate.template",
    source,
    haml_coffee_compiler_options,
    HamlCoffeeTemplate.configuration.coffee_script_compiler_options,
  )
end

#wrapper_script_pathObject



48
49
50
# File 'lib/haml_coffee_template/compiler.rb', line 48

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

#wrapper_sourceObject



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

def wrapper_source
  File.read(wrapper_script_path)
end