Closed Swivelgames closed 1 year ago
I'm actually working on an alternative to this that might make it obsolete. Trying to implement something that allows for a bit broader of a solution, including passing keys and values of associative arrays, and nested loops.
I'm not sure if that is desired, but let me know either way!
If it is, we probably don't want to merge #54.
Updated #54! Here's the rundown on the changes:
Click the arrows below to see examples.
I think it might be better to split this to separate issues to keep the discussions isolated.
{{$}}
syntax seems different from any other mustache implementation and doesn't really fit Bash because $$
is the process ID. Handlebars.js uses @key
, which would work.
mo
supports Bash 3.2 for Apple, which does not support associative arrays. Have you tested the referencing of a sister array with older versions of Bash? If this uses the same syntax as the first issue ($
vs @key
) and doesn't complain in Bash 3.2 (I don't expect it to work, just not complain), then I see no issues.
Array of associate arrays - how will mo
differentiate between an array of associative arrays and an array that happens to contain array variable names?
When expanding associative arrays, how will you determine if I am referencing arrays versus having words in a list?
Functions called within loops should not automatically get parameters. Imagine a function with an optional argument, then how do you determine if the optional argument was passed? If you want the function to get the value, you should use {{func2 @key .}}
or similar.
MO_LOOP and MO_LOOP_KEYS: I'm against adding these non-standard iteration values to Mustache because they rely heavily on the nesting of the templates. What use case do you have for these?
It looks like you're asking a lot out of logic-less templates, to the point that this appears to be adding logic into templates. If you would like to continue the discussion, please create issues that individually span smaller scopes.
That's kind of the response I was expecting. I'll work to isolate these changes into separate PRs and create separate issues to discuss them at their merit.
Most of this is not related to adding logic per se, but more to bring it in-line with other Mustache implementations. But I'll elaborate in the other threads! I'll go ahead and close this issue in favor of those so we don't continue to branch this issue thread.
And, sincerely, thanks a lot for the response!
It would be a huge help if it was possible to pass in the current element to a function call when looping. This would greatly simplify things when looping.
I spent quite a bit of time studying
mo
, and went ahead and implemented the idea in #54, along with tests and a demo. Thoughts?Here's an example: