debrouwere / render

Render text and HTML from Jade, Handlebars, Swig and most other kinds of templates on the command line. Render many files at once and decide where to write to dynamically from the data.
ISC License
17 stars 2 forks source link

Add support for JavaScript (.js) contexts #4

Closed chocolateboy closed 9 years ago

chocolateboy commented 9 years ago

e.g.:

render --engine swig --context context.js template.html

It would be handy if there was a way to expose dynamic properties — like, say, the date or Node.js version — to templates. A common way of achieving this is to load files with a .js extension and operate on their default export (i.e. via module.exports). This is done by e.g. jpm and various other tools and libraries.

debrouwere commented 9 years ago

Will definitely consider this, but I'm also trying to be conscious of not trying to do everything in a single module. For my own blog, I first preprocess my data with https://github.com/debrouwere/refract (which allows you to load .js and .coffee helpers) and then pass on the data to render only when it looks exactly like it should.

Not closing, but need to think about it more.

dskrepps commented 9 years ago

+1. Loading .json and .js files are usually treated interchangeably in node. Confert is basically consolidate for configs, it should simplify your code while supporting more file types.

debrouwere commented 9 years ago

The crowd has spoken. Thanks for the tip, @dskrepps, we're loading files with Confert now. Only JSON files have unit tests now, but might add some for .js and such later. Meanwhile, feel free to check it out.