-
Notifications
You must be signed in to change notification settings - Fork 71
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
"Truthiness" and "Falsiness" #4
Comments
agibralter's example is actually pretty clear: https://gist.github.com/820519 |
Updated the ticket with additional options, including one inspired by agibralter's example. |
Improving documentation can be done regardless. A simple statement like "A value should be considered empty if it is an empty structure or it evaluates to false according to the host language." Thinking "Utilize the existing YAML tag, !code, to provide a set of language-specific truthy and falsey values." - seems like the clearest way to specify this. It might be good to do this in an optional section so the core spec can be free of |
Improvements to documentation can be done independently of any other solution; it's actually one of the called-out benefits. I hesitate to associate too closely with the concept of "emptiness", however, as there is very inconsistent correlation between truthiness and emptiness. If we were to use the The current list of Mustache implementations also extends far beyond those five languages, many of which in languages that will be ill-suited to handling the |
For the time being, this will be enshrined in the documentation for the Section and Inverted Section tags. We will investigate more explicit options if and when we have a demonstrable problem. |
Generally speaking, there is little to no consistency between languages in the truthiness (or lack thereof) of any given value. Consequently, the fundamental description of the section tag (and its inverse) -- namely, that it's rendered when the named value is truthy (and falsey, respectively) -- is difficult to test in this specification.
The following options are available:
Introduce two new YAML tags,
!truthy
and!falsey
. Implementors of the spec are expected to intercept these and replace them with a non-boolean truthy or falsey value in the implementation language.data:
truthy: !truthy {}
falsey: !falsey {}
Utilize the existing YAML tag,
!code
, to provide a set of language-specific truthy and falsey values.data:
truthy: !code
ruby: '[ {value: ""}, {value: 0}, {value: Object.new} ]'
javascript: '[ {value: "non-empty"}, {value: 1}, {value: {}} ]'
falsey: !code
ruby: '[ {value: nil} ]'
javascript: '[ {value: ""}, {value: 0}, {value: undefined}, {value: null} ]'
!code
YAML tag.Handle the concepts of truthiness and falsiness abstractly, using a pair of values that are generally recognized as truthy / falsey.
data:
truthy: "non-empty"
falsey: null
Provide better documentation of Mustache as a whole, including guidelines for implementors (specifically calling out, among other things, truthiness and falsiness). Responsibility for proving conformance falls to the implementation's users and to the Mustache community at large.
The text was updated successfully, but these errors were encountered: