Skip to content
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 #3

Closed
wants to merge 3 commits into from
Closed

Truthiness #3

wants to merge 3 commits into from

Conversation

josh
Copy link

@josh josh commented Feb 7, 2011

Add a few truthiness specs for JSON values: null, strings and numbers.

Edge cases to consider

  • 0 - true in Ruby, false in JS
  • "" - true in Ruby, false in JS

Should mustache enforce consistency or use whatever the host language defines as true?

@pvande
Copy link
Contributor

pvande commented Feb 7, 2011

Whether or not specific values are considered truthy is deliberately left up to the semantics of the hosting language. To do otherwise exposes developers working with non-X implementations to unexpected and unpredictable behavior.

This does directly imply that the same template and data hash will render (logically) differently in certain environments. To avoid this problem in the spec, all values being used in a boolean comparison use YAML's boolean data type; the JSON representation is expected to behave likewise.

Mustache users are encouraged to be mindful of the target language's concept of "truth" when producing contextual data.

I'm somewhat disinclined to integrate these patches, since the tests themselves seem tautological w.r.t. the definition of truthiness. Is there a particular implementation that seems to disregard non-Boolean values used for sections?

This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants