hoisie/mustache — pull request #24 by drbawb (2012-08-17 19:08:31+00:00)
Title: Sections can be lambdas (in the form of `fn(in string) string`), as per mustache spec.

This is useful for implementing things such as filters (for example, transforming a static block of text into Markdown output).

Notable changes:
The parser now stores rawBody as it reads sections; reconstructing mustache-tags as appropriate.
This is because the mustache spec requires that a [lambda] section be passsed in as a string literal, with mustache tags unexpanded. Since a lambda can only be detected at runtime, the parser must emit the unexpanded tags in addition to the expanded tags.

The renderer now reflects on type "Func", calling the lambda with a string (the rawBody), and replacing the output with that function's result. (Also a string.)
This does not break existing tests, though I would appreciate a third-party review for regressions.

For future improvement / safety: we should ensure that the lambda is of type func(in string) string; and error / fall through as appropriate.