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
# File 'lib/temple/coffee_script/generators.rb', line 8

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

#concat(str) ⇒ Object



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

def concat(str)
  indent "#{buffer} += #{str}"
end

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



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

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

#on_capture(name, exp) ⇒ Object



36
37
38
# File 'lib/temple/coffee_script/generators.rb', line 36

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

#on_code(code) ⇒ Object



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

def on_code(code)
  indent(code)
end

#on_dynamic(code) ⇒ Object



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

def on_dynamic(code)
  concat(code)
end

#on_indent(exp) ⇒ Object



29
30
31
32
33
34
# File 'lib/temple/coffee_script/generators.rb', line 29

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

#on_multi(*exp) ⇒ Object



13
14
15
# File 'lib/temple/coffee_script/generators.rb', line 13

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

#on_static(text) ⇒ Object



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

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