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

export render function #6

Open
sirian opened this issue Dec 29, 2012 · 5 comments
Open

export render function #6

sirian opened this issue Dec 29, 2012 · 5 comments
Milestone

Comments

@sirian
Copy link

sirian commented Dec 29, 2012

It would be nice to do smth like this:

atpl = require('atpl');

var engine = new atpl({cahe: false, root: ...});
engine.renderFile(filename, data, callback);

or

atpl = require('atpl');
atpl.renderFile(filename, {cache: false, root: ...}, data, callback);
@soywiz
Copy link
Member

soywiz commented Jan 2, 2013

Which is the difference between this exported function and the one you suggests?:

function express3RenderFile(filename: string, options: any/*IOptionsExpress*/, callback: (err: Error, output?: string) => void)

@sirian
Copy link
Author

sirian commented Jan 2, 2013

i prefer to separate module options and render data
each approach gives this ability - either in object instance or in a separate parameter

@soywiz
Copy link
Member

soywiz commented Jan 2, 2013

Sorry, I didn't see the parameters from the example.
Yeah I agree with you: having the options mixed with the parameters (render data) is a bad idea. I dislike that too.
Since there are several objects: a TemplateParser instance, a LanguageContext and a RuntimeContext, you can always instantiate those objects directly (some tests do it already). There are several objects in there because the implementation is extensible and you can add new filters, functions, tests and tags (that's the LanguageContext). The LanguageContext can be reused between renders. The TemplateParser is in charge of recompiling the templates into efficient javascript. The RuntimeContext holds information related to the runtime and there is a instance each time you render; it holds the autoescape state and a scope.

I can make a wrapper class as you said with a metod that allows you to extends the language and to render a file and also a static method that performs all-in-one without being able to extend anything.

@sirian
Copy link
Author

sirian commented Jan 2, 2013

wrapper is a good idea, but you alse can add methods in wrapper like setTemplateParser() (aka depenpency injection pattern)

@panosru
Copy link

panosru commented Feb 9, 2013

I agree of exporting that low level api, would be easier to integrate the templating engine with other nodejs web frameworks (like protos) that don't depend on connect or express :)

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