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

Comiler function forgetting compiled version of template #96

Open
im4LF opened this issue Oct 19, 2015 · 6 comments
Open

Comiler function forgetting compiled version of template #96

im4LF opened this issue Oct 19, 2015 · 6 comments

Comments

@im4LF
Copy link

im4LF commented Oct 19, 2015

I need compiler function without http senders:

renderer.get('path/to/template', function (error, res) {
    // res - compiled version of path/to/template.ect
})

And amd loader without coffee-script dependencies for server-side compiling

@im4LF
Copy link
Author

im4LF commented Oct 19, 2015

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
});

@Dexus
Copy link

Dexus commented Apr 12, 2016

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?

@im4LF
Copy link
Author

im4LF commented Apr 12, 2016

I need compiled version of template not a rendered result

@Dexus
Copy link

Dexus commented Apr 12, 2016

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;
});
}

@im4LF
Copy link
Author

im4LF commented Apr 12, 2016

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") } ...';

@baryshev
Copy link
Owner

You can compile ECT templates to JS with bundled cli tool (located in bin directory), and use precompiled templates.

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

No branches or pull requests

3 participants