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

Add support for handlebar templates #93

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

mckramer
Copy link

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

@kennethormandy
Copy link
Collaborator

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.

@mckramer
Copy link
Author

mckramer commented May 1, 2015

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.

@zeke
Copy link
Contributor

zeke commented May 1, 2015

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

@kennethormandy kennethormandy mentioned this pull request May 13, 2015
kennethormandy added a commit that referenced this pull request May 21, 2015
@listepo
Copy link

listepo commented May 26, 2015

+1

@listepo
Copy link

listepo commented Jan 6, 2016

What status? Help is needed?

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.

5 participants