el2iot2 / grunt-hogan Goto Github PK
View Code? Open in Web Editor NEWA grunt.js task to precompile mustache templates with hogan.js
License: MIT License
A grunt.js task to precompile mustache templates with hogan.js
License: MIT License
I have a folder structure where it would be great to integrate the path in the name of the file.
Would this be a change to the vanilla hulk or could this be an option in this tool?
I have just tried to switch to using the amd binder for compiling our templates, but I have found I am unable to use partials with the current output.
The problem as I see it is that the hogan.js library expects the templates to of type Hogan.Template, but the amd compiled template output cannot provide this as it only returns a function, which when called renders the template.
A mock example of how I am using this is:
<div class="viewport">
<div class="actions">
{{>actions}}
</div>
<div class="meta">
{{>meta}}
</div>
</div>
And I am rendering the template like this:
templates.viewport(data, {
actions: templates.actions,
meta: templates.meta
});
I have also tried passing the partials in rendered but this also doesn't work:
templates.viewport(data, {
actions: templates.actions(),
meta: templates.meta()
});
The problem comes down to the output only providing access to rendered templates. The simplest solution would be just to return the Hogan.Template. This does mean you need to call render(), but this is the same as the output from the hulk binder.
Here is what works for me.
define(['hogan'], function(Hogan) {
var t = {
{{#templates}}
"{{name}}" : new Hogan.Template({{{template}}}){{comma}}
{{/templates}}
},
r = function(n) {
return t[n];
};
return {
{{#templates}}
"{{name}}" : r('{{name}}'){{comma}}
{{/templates}}
}
});
As indicated from further investigation of issue #6 , The Custom Binder Template support was intended, but not really tested or functional.
Fix it and update the documentation.
I can't get custom binders to work, and there isn't much info on them. Where should I start debugging?
Gruntfile:
hogan: {
customBinder: {
template : './templates/binders/pvcBinder.hogan',
output : './templates/binders/pvcBinder.js',
binderName: 'bootstrap'
},
compileTemplates : {
template : './templates/views/*.hogan',
output : './assets/js/hogan-templates.js',
binder: __dirname + '/templates/binders/pvcBinder.js',
}
}
watch: {
hogan: {
files: ['./templates/views/*.hogan'], //watched files
tasks: ['hogan:customBinder', 'hogan:compileTemplates', 'concat:js_frontend','uglify:frontend']
}
}
pvcBinder.hogan: (As a test I simply included the contents of hulk.hogan)
{{!the hulk binder tries to emulate the output of the hulk cli in hogan.js}}
var templates = {};
{{#templates}}
templates['{{name}}'] = new Hogan.Template({{{template}}});
{{/templates}}
Results in an empty hogan-templates.js file... (The binder itself compiles, but the templates aren't compiled by the custom binder...)
You should look to submit this for inclusion in the grunt-contrib project. Will require that you make some adjustments to meet their submission criteria.
What is a correct way to include my custom binder? (I have already created custom-binder.js and custom-binder.hogan)
While the template works just fine, the javascript outputted is invalid. Update the input file names to be a better example.
Support the old mode of configuration as well...output a deprecation message.
update main documentation, point to an upgrade wiki page.
all 0.1.1* versions are not properly building their binders. Need to fix this asap or rollback the npm publish.
I wanna use some export name like _aaa.bbb.ccc
, but this won't work now.
Because exportName = this.target
and target named _aaa.bbb.ccc
won't run in grunt task.
Maybe there's a good way to resolve this problem: add a option called namespace
and use this as exportName
.
If you think it's OK, i'm glad to send PR to do this.
Since any executing javascript code can "render" the result of a grunt-hogan
compile, it isn't very useful to provide a render
directive. It complicates the configuration and is a source of confusion.
Note: this will incur breaking changes for existing configurations
nodejs : {
compile : {
templates : "view/binder/nodejs.hogan",
output : "tasks/binder/nodejs.js",
options : {
binderName: "bootstrap",
}
}
},
Should now be:
nodejs : {
templates : "view/binder/nodejs.hogan",
output : "tasks/binder/nodejs.js",
binderName: "bootstrap"
},
Is it possible, to precompile the src templates (multiple files) as individual files to a directory?
Understanding of the custom binder template would be vastly improved if there were a working example. Add one.
I'm posting this issue to let you know that we will be publishing Grunt 0.4 on Monday, February 18th.
If your plugin is not already Grunt 0.4 compatible, would you please consider updating it? For an overview of what's changed, please see our migration guide.
If you'd like to develop against the final version of Grunt before Monday, please specify "grunt": "0.4.0rc8"
as a devDependency in your project. After Monday's release, you'll be able to use "grunt": "~0.4.0"
to actually publish your plugin. If you depend on any plugins from the grunt-contrib series, please see our list of release candidates for compatible versions. All of these will be updated to final status when Grunt 0.4 is published.
Also, in an effort to reduce duplication of effort and fragmentation in the developer community, could you review the grunt-contrib series of plugins to see if any of your functionality overlaps significantly with them? Grunt-contrib is community maintained with 40+ contributors—we'd love to discuss any additions you'd like to make.
Finally, we're working on a new task format that doesn't depend on Grunt: it's called node-task. Once this is complete, there will be one more conversion, and then we'll never ask you to upgrade your plugins to support our changes again. Until that happens, thanks for bearing with us!
If you have any questions about how to proceed, please respond here, or join us in #grunt on irc.freenode.net.
Thanks, we really appreciate your work!
readme examples show deprecated usages. Fix and massage.
admittly I am new to hogan.js, but for some unknown reason I keep getting this error, which i don't think is hogan.js related.
Compiling template...
Requiring binder template...
>> Found templates["default"]
template/welcome.mustache -> welcome
Reading template/welcome.mustache...OK
Writing dev/asset/template/welcome.js...ERROR
>> Error: Unable to write "dev/asset/template/welcome.js" file (Error code: undefined).
>> Failed to write out compiled template:
>> dev/asset/template/welcome.js
there is no weird permission on folder dev/asset/template
, and other grunt task is perfectly able to write to it, I am using the minimal example with src
and dest
, not sure what went wrong.
Have build on master and test...have master build publish npm module.
node_modules/grunt-hogan/tasks/binders.js:5
es["hulk"] = new Hogan.Template(function(c,p,i){var =this;.b(i=i||"&quo
^
Loading "binders.js" tasks and helpers...ERROR
SyntaxError: Unexpected token &
It seems to be broken at ""
Is it possible to have hogan compile the templates into a state where the need for hogan.js is not required? Just curious if there's an option to do that that I missed.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.