ejs icon indicating copy to clipboard operation
ejs copied to clipboard

Stringify a Template / Production-ready code

Open clintandrewhall opened this issue 13 years ago • 5 comments

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!

clintandrewhall avatar Dec 14 '11 06:12 clintandrewhall

jade has similar to disable the debugging stuff. then we could just have ejs.compile(str, options).toString() to get the fn string

tj avatar Dec 14 '11 16:12 tj

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!

clintandrewhall avatar Dec 14 '11 20:12 clintandrewhall

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?

clintandrewhall avatar Dec 14 '11 21:12 clintandrewhall

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

cookrn avatar Jun 27 '12 16:06 cookrn

This will be fixed in EJS v3 (see mde/ejs#23).

TimothyGu avatar Jan 24 '15 21:01 TimothyGu