Closed KentonWhite closed 10 months ago
You hit a point.
A very common interpretation of "language-agnostic", for Mustache, is that a single template file can be parsed and interpreted by various implementations written in different programming languages (ruby, python, java, etc.).
For instance, the tags {{variable}}
, {{>partial}}
, {{#section}}...{{/section}}
etc. have the same meaning, and this is enforced by the spec.
However, the spec does not enforce that a single input (data + template) should render the same in all implementations. The weak spot is the way booleans are handled (see issue #4). In some languages, 0 (zero) would be truthy, and in other languages, the same value would be falsey.
In this last context, "language-agnostic" has a different interpretation: programming languages are free to interpret values according to their "natural" meaning.
With such a fuzzy definition of "language-agnostic", you are free to decide your favorite interpretation :-)
Don't let a specification turn your library into a unusable piece of software. Write a nice template engine for R. Whether it is called Mustache or not is not that much important.
Thanks for the advice!
Happy templating!
I somewhat disagree with the above advice; if an implementation uses $
instead of .
as the name separator, then templates targeting that implementation will not be portable to other implementations and vice versa. That said, if portability is not a goal, then $
might indeed be the best for R.
Closing now as this question no longer seems to looking for an answer.
I'm looking for clarification about using '.' as the context sigil in interpolation. The spec says
I'm working with a Mustache implementation in the R language. R allows for '.' in variable names. It uses '$' and '@' as context sigils. This puts me in a bind. To be compliant with the Mustache spec, I must split names on periods and then resolve each remaining piece within the previous context. Doing this in R returns empty strings for valid R expressions, e.g.
{{data.frame$foo}}
will return the empty string regardless ifdata.frame
exists on the current stack or if the namefoo
is valid in the context ofdata.frame
.Since Mustache is meant to be language agnostic, can I interpret "split the name on periods" to mean "split the name on context sigils"?