terraform
terraform copied to clipboard
Add support for handlebar templates
Adding missing partial support from #36. See discussion in sintaxi/harp#246. I attempted to implement the tests that @kennethormandy provided.
I'm not completely sold on the partial syntax, so would be interested in feedback. It is currently prepared as:
{{partial '../foo.jade' locals='{"a": "b"}' }}
I did play with a few other syntaxes, such as passing an extra parameter:
{{partial '../foo.jade' '{"a": "b"}' }}
And flattening the object as attributes:
{{partial '../foo.jade' a='b' }}
Wow, that’s awesome, thank you. I won’t be able to look at it properly until next week, but I really appreciate you taking this on. I think I’d lean towards the second option since it’s closer to what you have to do in Jade and EJS, but I’ll keep thinking on that part.
Yes, option 1 was defined in the initial tests you wrote, so I started with that syntax. The tough thing with handlebars is JS objects and arrays can not be defined inline to helpers, so if you notice the first two options are actually passing JSON.
This can be awkward when you need to dynamically provide the locals. For example, trying to dynamically create a locals object from concatenation and stringify do not work:
{{partial '../foo.jade' '{ "a":' + b + '" }' }}
{{partial '../foo.jade' JSON.stringify({ a: b }) }}
I'd argue the 3rd option feels the cleanest to me, but also differs the most from ejs and jade:
{{partial '../foo.jade' a=b }}
However, options 2 & 3 can be combined with a subexpression. So, for example by adding an additional locals helper, the following two expressions are the same:
{{partial '../foo.jade' '{ "a": "b" }' }}
{{partial '../foo.jade' (locals a="b") }}
This might give people the most flexibility, but still provide a similar API for defining locals amongst the various templating languages.
Nice! I hope this works out. It would be awesome to see handlebars support land in terraform and harp.
+1
What status? Help is needed?