Sha256: 055ff69ad2f06c96458de3cc5330460bc54c98fad601835781a5ee178e494044
Contents?: true
Size: 1007 Bytes
Versions: 7
Compression:
Stored size: 1007 Bytes
Contents
require "multi_json" module Temple module CoffeeScript class Generator < Temple::Generator default_options[:indent] = 0 def call(exp) @indent = options[:indent] compile [:multi, [:code, "#{buffer} = []"], exp, [:code, "#{buffer}.join('')"]] end def on_multi(*exp) exp.map {|e| compile(e) }.join("\n") end def on_static(text) concat(MultiJson.encode(text)) end def on_dynamic(code) concat(code) end def on_code(code) indent(code) end def on_indent(exp) @indent += 1 compile(exp) ensure @indent -= 1 end def on_capture(name, exp) self.class.new(:buffer => name, :indent => @indent).call(exp) end def concat(str) indent("#{buffer}.push(#{str})") end def indent(str, indent = @indent) " " * indent + str end end end end
Version data entries
7 entries across 7 versions & 1 rubygems