class Mustache::Generator
def on_section(name, content, raw)
Callback fired when the compiler finds a section token. We're
def on_section(name, content, raw) # Convert the tokenized content of this section into a Ruby # string we can use. code = compile(content) # Compile the Ruby for this section now that we know what's # inside the section. ev(<<-compiled) if v = ctx[#{name.to_sym.inspect}] if v == true #{code} elsif v.is_a?(Proc) Mustache::Template.new(v.call(#{raw.inspect}).to_s).render(ctx.dup) else # Shortcut when passed non-array v = [v] if v.respond_to?(:has_key?) || !v.respond_to?(:map) v.map { |h| ctx.push(h); r = #{code}; ctx.pop; r }.join end end compiled end