noahmorrison / chevron

A Python implementation of mustache
MIT License
505 stars 55 forks source link

Elasticsearch compatibility #67

Closed sypste closed 10 months ago

sypste commented 4 years ago

One use case for mustache is building parameterized search templates for Elasticsearch. The rendering engine in Elasticsearch has two special built-in functions/annotations:

{{#toJson}}some-object{{/toJson}} renders the nested object to valid JSON, and {{#join}}some-array{{/join}} concatenates the strings in the array to a single string with a default or custom delimiter. Could chevron implement those annotations as well? Asking for a friend :)

dmorrison42 commented 3 years ago

Would writing a toJson and join lambda in "user space" work for your use case? That should give you full control over your desired functionality without changing behavior for non-elastic search users.

https://github.com/noahmorrison/chevron/blob/90413a2dd56e06e1a493aa703907febe43966ca3/test_spec.py#L289-L310 for reference.

Any thoughts or additional requirements? Thanks!

sypste commented 3 years ago

That should work for the use case, if I can offer any help feel free to get in touch