ejs
ejs copied to clipboard
Stringify a Template / Production-ready code
We have a use-case where we'd want ejs templates compiled into a function string, rather than into a function. This would allow us to assign the template result to a namespace and ship a collection of templates without including ejs as a dependency.
In addition, these types of compiled formats shouldn't include line numbers or rethrow functionality.
This would be supported through two attributes on the options object: stringify and production.
I've taken a first crack at implementing these features into a fork:
https://github.com/clintandrewhall/ejs
I'd love your opinion on this, and if this is a good start to this functionality? If it's appropriate, I'll continue working on it as a pull request.
Thanks!
jade has similar to disable the debugging stuff. then we could just have ejs.compile(str, options).toString() to get the fn string
I had considered the toString() option, but I was thinking an option parameter would allow for the most passivity in the future... but it's probably a trivial concern.
I'll take a look at the jade implementation and put together a pull request. Thanks!
How would you recommend including the filters and utils.escape closure within the function that is returned? I'd like to not have the bulk of the ejs code as a dependency... short of copying those files and their functions, would you recommend teasing these components apart into a custom build script?
This does not solve the problem of avoiding the library client side, but is a reference to my solution for this problem. Requires the ejs and underscore libraries in the browser.
https://gist.github.com/3001401
This will be fixed in EJS v3 (see mde/ejs#23).