mirror of
https://github.com/zulip/zulip.git
synced 2025-11-08 16:01:58 +00: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)
156 lines
3.7 KiB
JavaScript
156 lines
3.7 KiB
JavaScript
/*jshint eqnull: true */
|
|
|
|
module.exports.create = function() {
|
|
|
|
// BEGIN(BROWSER)
|
|
|
|
var Handlebars = {};
|
|
|
|
(function(Handlebars) {
|
|
|
|
Handlebars.VERSION = "1.0.0-rc.3";
|
|
Handlebars.COMPILER_REVISION = 2;
|
|
|
|
Handlebars.REVISION_CHANGES = {
|
|
1: '<= 1.0.rc.2', // 1.0.rc.2 is actually rev2 but doesn't report it
|
|
2: '>= 1.0.0-rc.3'
|
|
};
|
|
|
|
Handlebars.helpers = {};
|
|
Handlebars.partials = {};
|
|
|
|
Handlebars.registerHelper = function(name, fn, inverse) {
|
|
if(inverse) { fn.not = inverse; }
|
|
this.helpers[name] = fn;
|
|
};
|
|
|
|
Handlebars.registerPartial = function(name, str) {
|
|
this.partials[name] = str;
|
|
};
|
|
|
|
Handlebars.registerHelper('helperMissing', function(arg) {
|
|
if(arguments.length === 2) {
|
|
return undefined;
|
|
} else {
|
|
throw new Error("Could not find property '" + arg + "'");
|
|
}
|
|
});
|
|
|
|
var toString = Object.prototype.toString, functionType = "[object Function]";
|
|
|
|
Handlebars.registerHelper('blockHelperMissing', function(context, options) {
|
|
var inverse = options.inverse || function() {}, fn = options.fn;
|
|
|
|
var type = toString.call(context);
|
|
|
|
if(type === functionType) { context = context.call(this); }
|
|
|
|
if(context === true) {
|
|
return fn(this);
|
|
} else if(context === false || context == null) {
|
|
return inverse(this);
|
|
} else if(type === "[object Array]") {
|
|
if(context.length > 0) {
|
|
return Handlebars.helpers.each(context, options);
|
|
} else {
|
|
return inverse(this);
|
|
}
|
|
} else {
|
|
return fn(context);
|
|
}
|
|
});
|
|
|
|
Handlebars.K = function() {};
|
|
|
|
Handlebars.createFrame = Object.create || function(object) {
|
|
Handlebars.K.prototype = object;
|
|
var obj = new Handlebars.K();
|
|
Handlebars.K.prototype = null;
|
|
return obj;
|
|
};
|
|
|
|
Handlebars.logger = {
|
|
DEBUG: 0, INFO: 1, WARN: 2, ERROR: 3, level: 3,
|
|
|
|
methodMap: {0: 'debug', 1: 'info', 2: 'warn', 3: 'error'},
|
|
|
|
// can be overridden in the host environment
|
|
log: function(level, obj) {
|
|
if (Handlebars.logger.level <= level) {
|
|
var method = Handlebars.logger.methodMap[level];
|
|
if (typeof console !== 'undefined' && console[method]) {
|
|
console[method].call(console, obj);
|
|
}
|
|
}
|
|
}
|
|
};
|
|
|
|
Handlebars.log = function(level, obj) { Handlebars.logger.log(level, obj); };
|
|
|
|
Handlebars.registerHelper('each', function(context, options) {
|
|
var fn = options.fn, inverse = options.inverse;
|
|
var i = 0, ret = "", data;
|
|
|
|
if (options.data) {
|
|
data = Handlebars.createFrame(options.data);
|
|
}
|
|
|
|
if(context && typeof context === 'object') {
|
|
if(context instanceof Array){
|
|
for(var j = context.length; i<j; i++) {
|
|
if (data) { data.index = i; }
|
|
ret = ret + fn(context[i], { data: data });
|
|
}
|
|
} else {
|
|
for(var key in context) {
|
|
if(context.hasOwnProperty(key)) {
|
|
if(data) { data.key = key; }
|
|
ret = ret + fn(context[key], {data: data});
|
|
i++;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
if(i === 0){
|
|
ret = inverse(this);
|
|
}
|
|
|
|
return ret;
|
|
});
|
|
|
|
Handlebars.registerHelper('if', function(context, options) {
|
|
var type = toString.call(context);
|
|
if(type === functionType) { context = context.call(this); }
|
|
|
|
if(!context || Handlebars.Utils.isEmpty(context)) {
|
|
return options.inverse(this);
|
|
} else {
|
|
return options.fn(this);
|
|
}
|
|
});
|
|
|
|
Handlebars.registerHelper('unless', function(context, options) {
|
|
var fn = options.fn, inverse = options.inverse;
|
|
options.fn = inverse;
|
|
options.inverse = fn;
|
|
|
|
return Handlebars.helpers['if'].call(this, context, options);
|
|
});
|
|
|
|
Handlebars.registerHelper('with', function(context, options) {
|
|
return options.fn(context);
|
|
});
|
|
|
|
Handlebars.registerHelper('log', function(context, options) {
|
|
var level = options.data && options.data.level != null ? parseInt(options.data.level, 10) : 1;
|
|
Handlebars.log(level, context);
|
|
});
|
|
|
|
}(Handlebars));
|
|
|
|
// END(BROWSER)
|
|
|
|
return Handlebars;
|
|
};
|