I'm writing a build script in node. In a nutshell, the script does the following:
I'm attempting to use Handlebars.js for the token replacement step.
There's a second phase for deploying, which also involves token substitution. This is the root of my question.
In some of the files, all of the tokens contained within will be replaced during init-time (the clone/rename/replace part). In other files, only some of these tokens will be replaced at init-time, and others won't be replaced until the deploy step runs (things like the deploy date, the git commit hash, etc.). Consider the following file:
<zimletConfig name="{{name}}" version="{{deploy_version}}">
<global>
<property name="allowedDomains">*.foo.com</property>
<property name="gitCommit">{{gitcommit}}</property>
<property name="deployDate">{{deploydate}}</property>
</global>
</zimletConfig>
In this file, only {{name}} should be replaced at init-time; the other tokens should be replaced at deploy-time only. When I run my init step, though, the deploy-time tokens are replaced with empty strings:
<zimletConfig name="com_foo_myproject" version="">
<global>
<property name="allowedDomains">*.foo.com</property>
<property name="gitCommit"></property>
<property name="deployDate"></property>
</global>
</zimletConfig>
Is there a way to have handlebars not replace tokens if they don't exist in the object passed in?
I think I've got a solution; I implemented a helperMissing
helper and it seems to work like I'd think it should.
handlebars.registerHelper('helperMissing', function(token) {
return '{{'+token+'}}';
});
I'm curious if this is the best way to solve the problem.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With