Open im4LF opened 9 years ago
Something like:
this.compiled = function (template, callback) {
try {
var context = new TemplateContext();
var container = context.load(template);
callback(null, container);
}
catch (err) {
callback(err);
}
};
And usage:
renderer.compiled('path/to/template', function (err, res) {
// do something with res.source
});
Why you dont Use:
var ECT = require('ect');
var renderer = ECT({ root : __dirname + '/views', ext : '.ect' });
renderer.render('page', { title: 'Hello, World!' }, function (error, html) {
console.log(error);
console.log(html);
});
Or what I miss to understand?
I need compiled version of template not a rendered result
ah, sorry. but its also possible todo:
var tpl_compiled = {};
var ECT = require('ect');
var renderer = ECT({ root : __dirname + '/views', ext : '.ect' });
if (tpl_compiled['page']){
return tpl_compiled['page'];
}
else
{
renderer.render('page', { title: 'Hello, World!' }, function (error, html) {
console.log(error);
console.log(html);
tpl_compiled['page'] = html;
});
}
I mean translate cofeescript to native javascript
var template = '{{ if @a > 10: }}more then 10{{ end }}';
var compiled = '... if ( this.a > 10 ) { buf.push("more then 10") } ...';
You can compile ECT templates to JS with bundled cli tool (located in bin
directory), and use precompiled templates.
I need compiler function without http senders:
And amd loader without coffee-script dependencies for server-side compiling