From 7f57da299f144054de41ca8f61ac4f2f45098c77 Mon Sep 17 00:00:00 2001 From: Egil Moeller Date: Fri, 9 Apr 2010 21:45:27 +0200 Subject: Added template.use, template.define and template.inherit to templates --- etherpad/src/etherpad/utils.js | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'etherpad') diff --git a/etherpad/src/etherpad/utils.js b/etherpad/src/etherpad/utils.js index 3e35f00..67592b1 100644 --- a/etherpad/src/etherpad/utils.js +++ b/etherpad/src/etherpad/utils.js @@ -64,10 +64,34 @@ function findTemplate(filename, plugin) { return '/templates/' + filename; } +function Template(params, plugin) { + this._defines = {} + this._params = params; + this._params.template = this; + this._plugin = plugin; +} + +Template.prototype.define = function(name, fn) { + this._defines[name] = fn; + return ''; +} + +Template.prototype.use = function (name, fn, arg) { + if (this._defines[name] != undefined) + return this._defines[name](arg); + else + return fn(arg); +} + +Template.prototype.inherit = function (template) { + return renderTemplateAsString(template, this._params, this._plugin); +} + function renderTemplateAsString(filename, data, plugin) { data = data || {}; data.helpers = helpers; // global helpers data.plugins = plugins; // Access callHook and the like... + new Template(data, plugin); var f = findTemplate(filename, plugin); //"/templates/"+filename; if (! appjet.scopeCache.ejs) { -- cgit v1.2.3-1-g7c22