UNPKG

tribe

Version:

Tribe is a platform for building rich, powerful, highly scalable distributed HTML5 web and mobile systems.

42 lines (36 loc) 1.38 kB
var utils = require('tribe/utilities'), options = require('tribe/options'), templates = require('tribe/build').templates, rewrite = require('knockout-arrows'), path = require('path'), fs = require('q-io/fs'), _ = require('underscore'); module.exports = function (name, data) { var template = _.template(templates(name)); return { to: function (targetPath, targetProperty) { targetProperty = targetProperty || 'output'; return function (context) { var content, templateData = { data: data || {}, utils: utils, context: context, options: options, rewrite: rewrite, _: _ }; try { content = template(templateData); } catch (ex) { utils.errors.rethrow("Error rendering template '" + name + "' to " + targetPath)(ex); } if (targetPath) { context[targetProperty] = context[targetProperty] || {}; context[targetProperty][targetPath] = content; } return content; }; } }; };