fenekku / moustachu

Mustache templating for Nim
65 stars 8 forks source link

other feature request: adding renderFile #11

Closed JohnAD closed 5 years ago

JohnAD commented 6 years ago

This is second of two features I'd be interested in adding to this library.

Currently, the syntax of render is

render(tmplate: string, c: Context, partialsDir="."): string

I'm proposing adding another procedure, called renderFile, that specifically pulls from a file rather than string:

renderFile(template_file_path: string, c: Context, partialsDir=nil): string

This proc simply gets the file from local disk and then passes it onto render. If partialsDir is not passed a value, then the directory for partials is derived from template_file_path.

Border cases:

Using a when statement, if the library is compiled for javascript, calling renderFile will purposely raise a descriptive error since this can't work under javascript. However, I will ensure that the library itself will compile just fine under javascript.

If the file is not found, rather than raise a runtime error, the procedure would ... I'm not sure. Perhaps return a nil? Or perhaps add an optional fallback_template string parameter that defaults to nil?

fenekku commented 5 years ago

12 merged. I am closing this.