mirror of
https://github.com/zulip/zulip.git
synced 2026-06-24 21:08:25 +08:00
Storing these in Git seems kind of weird, but seems to be [1] the done thing. I have to say, it's a lot more appealing than getting 3 packages from npm installed globally on every prod and dev machine -- we already have too much of that with 'pip install'. We can upgrade these in the future by running 'npm update' in the repo root directory. [1] http://www.futurealoof.com/posts/nodemodules-in-git.html (imported from commit 60a9d6a7cafe742442d87e9f3abc25750e179780)
93 lines
3.2 KiB
JavaScript
93 lines
3.2 KiB
JavaScript
exports.attach = function(Handlebars) {
|
|
|
|
// BEGIN(BROWSER)
|
|
|
|
Handlebars.VM = {
|
|
template: function(templateSpec) {
|
|
// Just add water
|
|
var container = {
|
|
escapeExpression: Handlebars.Utils.escapeExpression,
|
|
invokePartial: Handlebars.VM.invokePartial,
|
|
programs: [],
|
|
program: function(i, fn, data) {
|
|
var programWrapper = this.programs[i];
|
|
if(data) {
|
|
return Handlebars.VM.program(fn, data);
|
|
} else if(programWrapper) {
|
|
return programWrapper;
|
|
} else {
|
|
programWrapper = this.programs[i] = Handlebars.VM.program(fn);
|
|
return programWrapper;
|
|
}
|
|
},
|
|
programWithDepth: Handlebars.VM.programWithDepth,
|
|
noop: Handlebars.VM.noop,
|
|
compilerInfo: null
|
|
};
|
|
|
|
return function(context, options) {
|
|
options = options || {};
|
|
var result = templateSpec.call(container, Handlebars, context, options.helpers, options.partials, options.data);
|
|
|
|
var compilerInfo = container.compilerInfo || [],
|
|
compilerRevision = compilerInfo[0] || 1,
|
|
currentRevision = Handlebars.COMPILER_REVISION;
|
|
|
|
if (compilerRevision !== currentRevision) {
|
|
if (compilerRevision < currentRevision) {
|
|
var runtimeVersions = Handlebars.REVISION_CHANGES[currentRevision],
|
|
compilerVersions = Handlebars.REVISION_CHANGES[compilerRevision];
|
|
throw "Template was precompiled with an older version of Handlebars than the current runtime. "+
|
|
"Please update your precompiler to a newer version ("+runtimeVersions+") or downgrade your runtime to an older version ("+compilerVersions+").";
|
|
} else {
|
|
// Use the embedded version info since the runtime doesn't know about this revision yet
|
|
throw "Template was precompiled with a newer version of Handlebars than the current runtime. "+
|
|
"Please update your runtime to a newer version ("+compilerInfo[1]+").";
|
|
}
|
|
}
|
|
|
|
return result;
|
|
};
|
|
},
|
|
|
|
programWithDepth: function(fn, data, $depth) {
|
|
var args = Array.prototype.slice.call(arguments, 2);
|
|
|
|
return function(context, options) {
|
|
options = options || {};
|
|
|
|
return fn.apply(this, [context, options.data || data].concat(args));
|
|
};
|
|
},
|
|
program: function(fn, data) {
|
|
return function(context, options) {
|
|
options = options || {};
|
|
|
|
return fn(context, options.data || data);
|
|
};
|
|
},
|
|
noop: function() { return ""; },
|
|
invokePartial: function(partial, name, context, helpers, partials, data) {
|
|
var options = { helpers: helpers, partials: partials, data: data };
|
|
|
|
if(partial === undefined) {
|
|
throw new Handlebars.Exception("The partial " + name + " could not be found");
|
|
} else if(partial instanceof Function) {
|
|
return partial(context, options);
|
|
} else if (!Handlebars.compile) {
|
|
throw new Handlebars.Exception("The partial " + name + " could not be compiled when running in runtime-only mode");
|
|
} else {
|
|
partials[name] = Handlebars.compile(partial, {data: data !== undefined});
|
|
return partials[name](context, options);
|
|
}
|
|
}
|
|
};
|
|
|
|
Handlebars.template = Handlebars.VM.template;
|
|
|
|
// END(BROWSER)
|
|
|
|
return Handlebars;
|
|
|
|
};
|