granula
Version:
i18n tool for angular.js applications
48 lines (44 loc) • 1.37 kB
JavaScript
(function() {
var context,
__slice = [].slice;
context = function(attributes, interpolator) {
var attr, ctx, idx, key, noop, value, _i, _len, _ref;
ctx = {
attrs: {}
};
if (attributes.length === 1 && typeof attributes[0] === 'object') {
_ref = attributes[0];
for (key in _ref) {
value = _ref[key];
ctx.attrs[key] = value;
}
} else {
for (idx = _i = 0, _len = attributes.length; _i < _len; idx = ++_i) {
attr = attributes[idx];
ctx.attrs[idx + 1] = attr;
}
}
noop = function() {};
ctx.interpolate = function() {
var data, method, _ref1;
method = arguments[0], data = 2 <= arguments.length ? __slice.call(arguments, 1) : [];
return ((_ref1 = interpolator[method]) != null ? _ref1 : noop).apply(null, [ctx].concat(__slice.call(data)));
};
ctx.begin = function() {
return typeof interpolator.begin === "function" ? interpolator.begin(ctx) : void 0;
};
ctx.end = function(result) {
return typeof interpolator.end === "function" ? interpolator.end(ctx, result) : void 0;
};
ctx.apply = function(fn) {
var res, _ref1;
ctx.begin();
res = fn(ctx);
return (_ref1 = ctx.end(res)) != null ? _ref1 : res;
};
return ctx;
};
module.exports = {
context: context
};
}).call(this);