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

implement the exact opposite of the inverted match #64

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

exaexa
Copy link

@exaexa exaexa commented Jul 21, 2023

This implements {{?something}}...{{/something}} syntax, which works as an exact opposite of {{^something}}...{{/something}}, that is, fires precisely if the something does not evaluate to a falsey (empty, null) value. This allows implementing simple and exact if/else constructions, which is actually quite hard to achieve properly with original mustache. (I guess that lack of these is one of the ground reasons why e.g. handlebars.js exist.)

This is actually not in mustache spec but given the minor size of the extension and some other tiny improvements already in this repo, I guess it could be viable to get merged. (At the bare minimum I wouldn't need to keep the repo forked... :D)

Thanks for maintaining the library!

This implements `{{?something}}...{{/something}}` syntax, which works as an
exact opposite of `{{^something}}...{{/something}}`, that is, fires precisely
if the `something` does NOT evaluate to falsey (empty, null) value. This allows
implementing simple and exact if/else constructions, which is actually quite
hard to achieve properly with original mustache.
@exaexa
Copy link
Author

exaexa commented Jul 21, 2023

PS I see that I actually added a few changes that might not be necessary (the 2 removed imports). I guess I hit some issues with those, unfortunately it is now over a month since I did this change, and I didn't write down the actual reason. If these are required for compatibility reasons, please ping me, I'll try to dig deeper and see why I actually had to remove these.

PPS. I just realize the tests are missing :D I'll try to write some if this looks OK for merging.

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.

1 participant