class Mustache::Generator
def compile!(exp)
[:mustache, :etag, "taxed_value"],
[:static, "Well, $"],
[:multi,
"in_ca",
:section,
[:mustache,
[:static, "!\n"],
[:mustache, :etag, "value"],
[:static, "\nYou have just won $"],
[:mustache, :etag, "name"],
[:static, "Hello "],
[:multi,
tokens:
If we run this through the Parser, we'll get back this array of
{{/in_ca}}
Well, ${{taxed_value}}, after taxes.
{{#in_ca}}
You have just won ${{value}}!
Hello {{name}}
template:
To give you an idea of what you'll be dealing with take this
Any Mustache tag, from sections to partials.
:mustache
Normal HTML, the stuff outside of {{mustaches}}.
:static
Mixed bag of :static, :mustache, and whatever.
:multi
with:
particular there are three types of expressions we are concerned
Given an array of tokens, converts them into Ruby code. In
def compile!(exp) case exp.first when :multi exp[1..-1].map { |e| compile!(e) }.join when :static str(exp[1]) when :mustache send("on_#{exp[1]}", *exp[2..-1]) else raise "Unhandled exp: #{exp.first}" end end