hoisie/mustache — pull request #23 by lye (2012-07-31 04:04:13+00:00)
Title: Conform to spec: empty list evaluates inverted section

The mustache manual[1] states the following:

While sections can be used to render text one or more times based on the
value of the key, inverted sections may render text once based on the
inverse value of the key. That is, they will be rendered if the key
doesn't exist, is false, or is an empty list.

The previous implementation, upon encountering an empty list, iterated
over the items in the list and rendered each one. Since the list was
empty, nothing would be emitted for an inverted section over an empty
list, thus the following template would never have any output:

{{#list}} not empty {{/list}}
{{^list}} empty {{/list}}

Furthermore, though the mustache spec isn't clear on what constitutes a
`false` value, I felt that the definition in `isNil` was too
constrained -- most primitive zero-values were not handled and defined
as non-false. This, unfortunately, included common things like integers,
maps, lists, etc. I have amended `isNil` to switch on every
`reflect.Kind` and check for zero-value equivalents (e.g., empty
lists/maps/channels/strings, 0-value numerics).

Finally, tests have been added for these additions.