janl/mustache.js — pull request #303 by danielfagerstrom (2013-03-17 16:28:47+00:00)
Title: Mustache specs - whitespace compliance

Fixed the failing whitespace tests from the Mustache spec from my Mustache spec [pull request](http://github.com/janl/mustache.js/pull/301).

1. Spaces from standalone tags without newline should be stripped.
2. Partial tags SHOULD be treated as standalone when appropriate. If this tag
is used standalone, any whitespace preceding the tag should treated as
indentation, and prepended to each line of the partial before rendering. [specs](http://github.com/mustache/spec/blob/master/specs/partials.yml#L13)

To implement the second point I introduced a ```whitespace``` variable in the ```parse``` function to keep track on whitespace on the same row before a standalone tag. For partials the content of the ```whitespace``` variables is stored in the parse tree and used for compiling an indented version of the partial during rendering. To keep track on instances of the same partial with different of indentation in the partial cache I prefixed the partial name with the indentation in the cache. Also needed to store non compiled partials and introduced indentation arguments for ```getPartial``` and ```compilePartial```.

The implementation borrowed from [Milk](http://github.com/pvande/Milk/blob/master/milk.coffee#L143).