bobthecow/mustache.php — pull request #129 by bobthecow (2013-01-13 21:55:29+00:00)
Title: Add "anchored dot notation"

1. Given that `{{ . }}` resolves as the top of the context stack;
2. And when any falsey segment in a dotted name is encountered, the whole name yields `''`;
3. A name like `{{ .name }}` should imply `{{ [top of stack].name }}`;
4. Thus, it must resolve as truthy _only_ if a member of the top of the context stack matches `name`.

There have been several syntaxes proposed (mustache/spec#10 and mustache/spec#11 as well as my mustache/spec#52). This one is my favorite because,

* It introduces no new symbols, it simply allows combining two existing syntaxes into a single tag.
* It is backwards compatible, meaning, no currently working code will be broken, since `{{ .foo.bar }}` isn't a valid variable name in the current spec.
* It doesn't come with any of the crazy traversal logic that the `{{ ../foo }}` style anchors do, so I feel it's more in keeping with the logic-free nature of Mustache.
* It doesn't involve blessing any valid variable names as super-variables (e.g. the proposed `{{ this.foo }}` syntax, which would be a backwards compatibility break, as well as limiting perfectly valid variable names in some languages.

See spec discussion at mustache/spec#52 and some impetus at #98.

This is a complete implementation, but it's currently missing tests. I'm torn on including it without a pragma, since it would technically make Mustache.php not spec compliant.

Thoughts?