class Temple::Generator
Abstract generator base class Generators should inherit this class and compile the Core Abstraction to ruby code.
@api public
Public Instance Methods
call(exp)
click to toggle source
# File lib/temple/generator.rb, line 14 def call(exp) [preamble, compile(exp), postamble].join('; ') end
on(*exp)
click to toggle source
# File lib/temple/generator.rb, line 18 def on(*exp) raise InvalidExpression, "Generator supports only core expressions - found #{exp.inspect}" end
on_capture(name, exp)
click to toggle source
# File lib/temple/generator.rb, line 30 def on_capture(name, exp) capture_generator.new(:buffer => name).call(exp) end
on_code(code)
click to toggle source
# File lib/temple/generator.rb, line 42 def on_code(code) code end
on_dynamic(code)
click to toggle source
# File lib/temple/generator.rb, line 38 def on_dynamic(code) concat(code) end
on_multi(*exp)
click to toggle source
# File lib/temple/generator.rb, line 22 def on_multi(*exp) exp.map {|e| compile(e) }.join('; ') end
on_newline()
click to toggle source
# File lib/temple/generator.rb, line 26 def on_newline "\n" end
on_static(text)
click to toggle source
# File lib/temple/generator.rb, line 34 def on_static(text) concat(text.inspect) end
Protected Instance Methods
buffer()
click to toggle source
# File lib/temple/generator.rb, line 48 def buffer options[:buffer] end
capture_generator()
click to toggle source
# File lib/temple/generator.rb, line 52 def capture_generator @capture_generator ||= Class === options[:capture_generator] ? options[:capture_generator] : Generators.const_get(options[:capture_generator]) end
concat(str)
click to toggle source
# File lib/temple/generator.rb, line 58 def concat(str) "#{buffer} << (#{str})" end