==========================
this will use derby-templates to render emails from files.
the controller
is just a module with view functions attached to it, it can be an empty object otherwise.
{templates, contexts} = require 'derby-templates' | |
require 'derby-parsing' | |
util = require './util' | |
fs = require 'fs' | |
cache = {} | |
exports.createRenderer = (ns, parts, controller = util) -> | |
views = new templates.Views() | |
for name, file of parts | |
path = "#{__dirname}/templates/#{ns}/#{file}" | |
template = cache[path] | |
if !template | |
template = cache[path] = fs.readFileSync(path).toString() | |
views.register "#{ns}:#{name}", template | |
contextMeta = new contexts.ContextMeta({}) | |
return (ns, name, context = {}) -> | |
view = views.find "#{ns}:#{name}" | |
controller.model = {data: context} | |
context = new contexts.Context(contextMeta, controller); | |
return view?.get context |