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

Query template for delimited value #47

Closed
KosmicTask opened this issue Feb 25, 2013 · 3 comments
Closed

Query template for delimited value #47

KosmicTask opened this issue Feb 25, 2013 · 3 comments

Comments

@KosmicTask
Copy link
Contributor

Is it possible using the existing API to query a template as to whether it contains a particular key value, say {{ my-header }}?

My usage case is: if a certain key is present in the template then the GUI presents options to configure the content for that key. If the key is absent then the GUI disables the options.

Obviously I can scan/regex the template string externally but it would need to take into account the current delimiter and be able to deal with filters.

@groue
Copy link
Owner

groue commented Feb 25, 2013

Hi Jonathan.

If you look for an identifier, such as my-header, then rendering a template with a KVC-recorder object (an object whose valueForKey: method returns itself for any given key, and logs the requested keys) should do the trick. Not very efficient, I agree, plus it would require extra work if you look for keys into sections triggered by false values.

A definitive general solution to your request would be to expose the template syntax tree in the public API. However your recent #45 et #46 issues will have me tweak both parser and compiler: I'm happy the AST headers are still private, because I'm free to break any internal guts today :-)

I can explain you how to use the current private headers, and look for the my-header key, if the first solution does not fit your needs.

@KosmicTask
Copy link
Contributor Author

HI Gwendal

I can work with the first method.

As ever, thanks for the reply. Good luck with the surgery on GRMustache!

@groue
Copy link
Owner

groue commented Feb 25, 2013

Thanks ! I'm not a parser professional, and Mustache parsing has quirks that do not help, such as the {{=<% %>=}} "set delimiters tag" that allows to change Mustache delimiters in the middle of a template: {{name}} {{=<% %>=}} <% name %>. And the white space rules are bitches. So I'll turn a low-quality parser to another low-quality parser, I'm afraid :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants