terraform icon indicating copy to clipboard operation
terraform copied to clipboard

Add support for handlebar templates

Open mckramer opened this issue 10 years ago • 5 comments

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' }}

mckramer avatar Apr 30 '15 15:04 mckramer

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.

kennethormandy avatar Apr 30 '15 16:04 kennethormandy

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.

mckramer avatar May 01 '15 04:05 mckramer

Nice! I hope this works out. It would be awesome to see handlebars support land in terraform and harp.

zeke avatar May 01 '15 05:05 zeke

+1

listepo avatar May 26 '15 21:05 listepo

What status? Help is needed?

listepo avatar Jan 06 '16 14:01 listepo