Class: Temple::CoffeeScript::Generator
- Inherits:
-
Generator
- Object
- Generator
- Temple::CoffeeScript::Generator
- Defined in:
- lib/temple/coffee_script/generators.rb
Instance Method Summary collapse
- #call(exp) ⇒ Object
- #concat(str) ⇒ Object
- #indent(str, indent = @indent) ⇒ Object
- #on_capture(name, exp) ⇒ Object
- #on_code(code) ⇒ Object
- #on_dynamic(code) ⇒ Object
- #on_indent(exp) ⇒ Object
- #on_multi(*exp) ⇒ Object
- #on_static(text) ⇒ Object
Instance Method Details
#call(exp) ⇒ Object
8 9 10 11 |
# File 'lib/temple/coffee_script/generators.rb', line 8 def call(exp) @indent = [: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 |