Class: Temple::CoffeeScript::Generator

Inherits:
Generator
  • Object
show all
Defined in:
lib/temple/coffee_script/generators.rb

Instance Method Summary collapse

Instance Method Details

#call(exp) ⇒ Object



8
9
10
11
12
13
14
# File 'lib/temple/coffee_script/generators.rb', line 8

def call(exp)
  @indent = options[:indent]
  compile [:multi,
           [:code, "#{buffer} = []"],
           exp,
           [:code, "#{buffer}.join('')"]]
end

#concat(str) ⇒ Object



43
44
45
# File 'lib/temple/coffee_script/generators.rb', line 43

def concat(str)
  indent("#{buffer}.push(#{str})")
end

#indent(str, indent = @indent) ⇒ Object



47
48
49
# File 'lib/temple/coffee_script/generators.rb', line 47

def indent(str, indent = @indent)
  "  " * indent + str
end

#on_capture(name, exp) ⇒ Object



39
40
41
# File 'lib/temple/coffee_script/generators.rb', line 39

def on_capture(name, exp)
  self.class.new(:buffer => name, :indent => @indent).call(exp)
end

#on_code(code) ⇒ Object



28
29
30
# File 'lib/temple/coffee_script/generators.rb', line 28

def on_code(code)
  indent(code)
end

#on_dynamic(code) ⇒ Object



24
25
26
# File 'lib/temple/coffee_script/generators.rb', line 24

def on_dynamic(code)
  concat(code)
end

#on_indent(exp) ⇒ Object



32
33
34
35
36
37
# File 'lib/temple/coffee_script/generators.rb', line 32

def on_indent(exp)
  @indent += 1
  compile(exp)
ensure
  @indent -= 1
end

#on_multi(*exp) ⇒ Object



16
17
18
# File 'lib/temple/coffee_script/generators.rb', line 16

def on_multi(*exp)
  exp.map {|e| compile(e) }.join("\n")
end

#on_static(text) ⇒ Object



20
21
22
# File 'lib/temple/coffee_script/generators.rb', line 20

def on_static(text)
  concat(JSON.generate(text, :quirks_mode => true))
end