baryshev / ect

Fastest JavaScript template engine with embedded CoffeeScript syntax
http://ectjs.com
MIT License
625 stars 69 forks source link

Precompilation of templates #17

Open kesavkolla opened 11 years ago

kesavkolla commented 11 years ago

ECT is an excellent template language. I like the way it support the client side templates using the middleware compilation. Is there any way to use the client side templates with pre compiled templates. I don't have a running node middleware on my hosting server. I want to precompile all the templates on my dev server and include the result js directly in my client app. Is there any way to achieve this?

Thanks -Kesav

baryshev commented 11 years ago

This feature planned for next version.

kesavkolla commented 11 years ago

Awesome. A batch compiler for ect templates and the output can be directly served to browser. It would be great if this can be integrated with Angular.js. Also cool thing would be to integrate with CodeKit so that it can auto compile the ect templates. I'd love to see this feature soon.

eliseumds commented 11 years ago

Hey guys!

First of all, I would like to thank everyone, this is project is really impressive and helpful.

I've adapted the code so I can precompile the templates. If anyone is interest, please check my fork: https://github.com/eliseumds/ect

aeischeid commented 11 years ago

Previously we used eco with spine.js and hem. I would love to replace eco with ect in the spine.js docs, example apps and and hem and all that but precomplilation would be a requirement. I will keep an eye out for this feature landing. looks like you guys are doing good work. Keep going!

baryshev commented 11 years ago

First version of command-line compiler released just now (with v0.5.0). It have a basic functionality for now, but will be improved in future.

mwcollins commented 11 years ago

Hey All, What's the status of precompiling templates on the client side? I love ECT, but this is the only thing preventing me from integrating it. Currently the pre-complier outputs an anonymous function... how would one integrate the compiled output to be renderable by an ECT object instance?

I dug into the source a little bit... I was thinking maybe adding a method like:

renderer.register({ name:'foo', compiled:(function(){}) });

... this would add a record to the cache object internally

Then I would be able to:

renderer.render('foo',{});

I'll submit a patch if I end up writing it, but wanted to get your thoughts.

baryshev commented 11 years ago

If you need to serve all precompilied templates to client in one script/html (without ajax lazy load) you can use this syntax:

var renderer = new ECT({
    root : {
        foo: 'ectPrecompilledFuncitonHere',
        bar: 'ectPrecompilledFuncitonHere'
    }
});

After that you can use template foo and bar in your code.

mwcollins commented 11 years ago

Solid, thanks... is that the string source or is it the function reference?

baryshev commented 11 years ago

This is a string as it outputted by ect command line tool.

brian-mann commented 10 years ago

Unfortunately, I find this woefully inadequate. In my opinion ECT beats ECO all around, except for the fact that you're coupled to a server side implementation, and lazy loading the templates async.

My project has hundreds of templates - I doggedly control when those templates are loaded on the client. When a user visits a new page, I send down all the JS including the template code as one file. That way, the minimal code is loaded when the page first loads, but complete "page modules" are loaded lazily when they're needed.

It wouldn't make send to send the templates 1 file at a time on demand.

So that means that there needs to be a way to precompile them into a global namespace. Many templates already do this, ECO, EJS, Handlebars, Jade, etc. ECT not providing this is a real deal breaker.