class Temple::Generator
def self.to_ruby(str)
def self.to_ruby(str) str.inspect end
def buffer(str = '')
def buffer(str = '') @options[:buffer] + str end
def capture_generator
def capture_generator @capture_generator ||= @options[:capture_generator] || Temple::Core::StringBuffer end
def compile(exp, single = false)
def compile(exp, single = false) if @compiling || single type, *args = exp recv = @in_capture || self recv.send("on_#{type}", *args) else begin @compiling = true [preamble, compile(exp), postamble].join(' ; ') ensure @compiling = false end end end
def concat(str)
def concat(str) buffer " << (#{str})" end
def initialize(options = {})
def initialize(options = {}) @options = DEFAULT_OPTIONS.merge(options) @compiling = false @in_capture = nil end
def on_capture(name, block)
def on_capture(name, block) before = @capture @capture = capture_generator.new(:buffer => name) [ @capture.preamble, @capture.compile(block, true), "#{name} = (#{@capture.postamble})" ].join(' ; ') ensure @capture = before end
def on_multi(*exp)
def on_multi(*exp) exp.map { |e| compile(e) }.join(" ; ") end
def on_newline
def on_newline "\n" end
def postamble; '' end
def postamble; '' end
def preamble; '' end
def preamble; '' end
def to_ruby(str)
def to_ruby(str) Generator.to_ruby(str) end