aboutsummaryrefslogtreecommitdiffstats
path: root/etherpad
diff options
context:
space:
mode:
authorEgil Moeller <egil.moller@freecode.no>2010-04-09 21:45:27 +0200
committerEgil Moeller <egil.moller@freecode.no>2010-04-09 21:45:27 +0200
commit7f57da299f144054de41ca8f61ac4f2f45098c77 (patch)
tree61b77fc4e73b95b2c295114ea6bcd5ec023d3ace /etherpad
parentf9cc3b56b95cd471d4917de5d1b4797922e0e496 (diff)
downloadetherpad-7f57da299f144054de41ca8f61ac4f2f45098c77.tar.gz
etherpad-7f57da299f144054de41ca8f61ac4f2f45098c77.tar.xz
etherpad-7f57da299f144054de41ca8f61ac4f2f45098c77.zip
Added template.use, template.define and template.inherit to templates
Diffstat (limited to 'etherpad')
-rw-r--r--etherpad/src/etherpad/utils.js24
1 files changed, 24 insertions, 0 deletions
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) {