Skip to content
This repository

Compiling directory recursively #435

Closed
ksaitor opened this Issue February 13, 2013 · 7 comments

5 participants

Raman Shalupau Kevin Decker Pierce Moore Victor Bastos Frederik Eychenié
Raman Shalupau

Would be really handy to compile templates recursively:

handlebars -R templates/ -f templates.js -a -r templates
Pierce Moore

I am involved in a node module called Handlebar-rider, written originally by @cif, that does this. And it's really not that difficult. I love writing code for it, but if Handlebars natively supported recursive folders and daemonized (ish) folder watching then there would be no competition left.

I am perfectly willing to write the code that makes this happen, as surely many other people are. But I don't want to write it and submit the pull request if there is either a lack of interest or if it won't be accepted. It just seems like such a basic feature that in my thinking there has to be a reason it's not done yet.

Kevin Decker
Collaborator

@piercemoore if you want to submit a PR I'll work with you to get it in. This seems like a useful feature.

Pierce Moore

@kpdecker It's a deal. I'm actually pretty excited to get working on it. I have a lot of code on the ground for this other module, but I'll hopefully be able to port it over without too much trouble. The way it works in handlebar-rider is that it traverses the directory structure and creates namespaced templates out of the folder names. So if you had the following directory structure:

templates
    - messages
        - elements
            - avatar.hb
            - labels.hb
        - inbox.hb
        - compose.hb

Then you could access the compose template by calling Handlebars.templates['messages/compose']. You could also access the labels template by calling Handlebars.templates['messages/elements/labels']. And so on and so forth :-P

Right now we're just including all the existing templates in the Handlebars.partials object as well, which is the easiest way to allow you to access all the templates in Handlebars.partials inside other templates.

I'll get it written and submitted this weekend :D

Victor Bastos

in fact you can do like this:

handlebars "your folder" > templates.js

and it will precompile all the templates recursively!

Frederik Eychenié

@piercemoore I am very very interested in this feature, especially in an AMD usage, have you made any progress on this ? I'm willing to give you a hand if you need some help :)

@victorwpbastos what you are talking about is compiling recursively into a single file, if i understand well the point here is to have a separate output file for each file in the directories, the whole respecting the original directory structure

Victor Bastos

@feychenie the original question was about precompiling all templates in a folder recursively to a single template file.

Kevin Decker
Collaborator

Closing this as I think that 17e1b1f resolved this.

Kevin Decker kpdecker closed this October 12, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.