work on moving lib modules to bower

This commit is contained in:
Kevin Ngo 2014-09-23 12:43:27 -07:00
Родитель aee75a34aa
Коммит d97581694d
14 изменённых файлов: 11373 добавлений и 5525 удалений

Просмотреть файл

@ -1,2 +1,5 @@
gulp:
@node_modules/.bin/gulp
update:
@node_modules/.bin/gulp update

Просмотреть файл

@ -4,7 +4,13 @@
"description": "Bootstrap template for your Commonplace app.",
"version": "0.0.0",
"dependencies": {
"commonplace": "*"
"commonplace": "*",
"marketplace-constants": "*",
"jquery": "2.0.2",
"nunjucks": "1.0.0",
"requirejs": "2.1.4",
"underscore": "1.4.4"
},
"ignore": [
]

Просмотреть файл

@ -1,11 +1,10 @@
var _ = require('underscore');
var gulpBowerCopyLocal = require('./config_local');
var gulpBowerCopy = {}; // Source -> Destination.
// Commonplace Core.
var corePath = 'bower_components/commonplace/dist/core/';
var core = [
var CORE_MODULES = [
// Core JS modules.
// Will tell Gulp which modules to pull into commonplace/.
// Will tell the require.js config which files live in commonplace/.
'assert',
'buckets',
'builder',
@ -26,12 +25,32 @@ var core = [
'utils',
'z'
];
var CORE_SRC_PATH = 'commonplace/dist/core/';
var CORE_DEST_PATH = 'src/media/js/commonplace/';
_.each(core, function(module) {
gulpBowerCopy[corePath + module + '.js'] = 'src/media/js/commonplace/';
var LIB_DEST_PATH = 'src/media/js/lib/';
var LIB_MODULES = {
// Third-party JS modules.
// Will tell Gulp which modules to pull into lib/.
// Will tell the require.js config which files live in lib/.
'requirejs/require.js': LIB_DEST_PATH,
'jquery/jquery.js': LIB_DEST_PATH,
'nunjucks/browser/nunjucks-slim.js': LIB_DEST_PATH + 'nunjucks.js',
'underscore/underscore.js': LIB_DEST_PATH,
};
// Build config object to tell Gulp which Bower files into project and where.
var gulpBowerCopy = {};
_.each(CORE_MODULES, function(module) {
gulpBowerCopy[CORE_SRC_PATH + module + '.js'] = 'src/media/js/commonplace/';
});
gulpBowerCopy = _.extend(gulpBowerCopy, LIB_MODULES);
// Extend with local config.
gulpBowerCopy = _.extend(gulpBowerCopy, gulpBowerCopyLocal);
exports.gulpBowerCopy = gulpBowerCopy;
var requireConfig = {};
module.exports = {
gulpBowerCopy: gulpBowerCopy,
requireConfig: requireConfig
};

Просмотреть файл

@ -16,7 +16,7 @@ gulp.task('bower_copy', ['install'], function() {
// Copy files from Bower into project.
_.each(Object.keys(config.gulpBowerCopy), function(source) {
var dest = config.gulpBowerCopy[source];
gulp.src(source)
gulp.src('bower_components/' + source)
.pipe(gulp.dest(dest));
});
});

1
src/.commonplace Normal file
Просмотреть файл

@ -0,0 +1 @@
{"version":"AWESOME"}

0
src/media/css/.gitkeep Normal file
Просмотреть файл

Просмотреть файл

Просмотреть файл

@ -1,31 +0,0 @@
/* Python(ish) string formatting:
* >>> format('{0}', ['zzz'])
* "zzz"
* >>> format('{0}{1}', 1, 2)
* "12"
* >>> format('{x}', {x: 1})
* "1"
*/
define('format', [], function() {
var re = /\{([^}]+)\}/g;
function format(s, args) {
if (!s) {
throw "Format string is empty!";
}
if (!args) return;
if (!(args instanceof Array || args instanceof Object))
args = Array.prototype.slice.call(arguments, 1);
return s.replace(re, function(_, match){ return args[match]; });
}
function template(s) {
if (!s) {
throw "Template string is empty!";
}
return function(args) { return format(s, args); };
}
return {
format: format,
template: template
};
});

5125
src/media/js/lib/jquery-2.0.2.js поставляемый

Разница между файлами не показана из-за своего большого размера Загрузить разницу

8842
src/media/js/lib/jquery.js поставляемый Executable file

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Просмотреть файл

@ -43,7 +43,7 @@ function extend(cls, name, props) {
prototype.typename = name;
var new_cls = function() {
var new_cls = function() {
if(prototype.init) {
prototype.init.apply(this, arguments);
}
@ -63,7 +63,7 @@ function extend(cls, name, props) {
return new_cls;
}
modules.object = extend(Object, "Object", {});
modules['object'] = extend(Object, "Object", {});
})();
(function() {
var ArrayProto = Array.prototype;
@ -81,27 +81,27 @@ var lookupEscape = function(ch) {
return escapeMap[ch];
};
var exports = modules.lib = {};
var exports = modules['lib'] = {};
exports.withPrettyErrors = function(path, withInternals, func) {
// try {
try {
return func();
// } catch (e) {
// if (!e.Update) {
// // not one of ours, cast it
// e = new exports.TemplateError(e);
// }
// e.Update(path);
} catch (e) {
if (!e.Update) {
// not one of ours, cast it
e = new exports.TemplateError(e);
}
e.Update(path);
// // Unless they marked the dev flag, show them a trace from here
// if (!withInternals) {
// var old = e;
// e = new Error(old.message);
// e.name = old.name;
// }
// Unless they marked the dev flag, show them a trace from here
if (!withInternals) {
var old = e;
e = new Error(old.message);
e.name = old.name;
}
// throw e;
// }
throw e;
}
};
exports.TemplateError = function(message, lineno, colno) {
@ -219,7 +219,7 @@ exports.repeat = function(char_, n) {
};
exports.each = function(obj, func, context) {
if(obj === null) {
if(obj == null) {
return;
}
@ -235,7 +235,7 @@ exports.each = function(obj, func, context) {
exports.map = function(obj, func) {
var results = [];
if(obj === null) {
if(obj == null) {
return results;
}
@ -277,7 +277,7 @@ exports.asyncParallel = function(funcs, done) {
exports.asyncIter = function(arr, iter, cb) {
var i = -1;
function next() {
i++;
@ -314,7 +314,7 @@ exports.asyncFor = function(obj, iter, cb) {
if(!Array.prototype.indexOf) {
Array.prototype.indexOf = function(array, searchElement /*, fromIndex */) {
if (array === null) {
if (array == null) {
throw new TypeError();
}
var t = Object(array);
@ -327,7 +327,7 @@ if(!Array.prototype.indexOf) {
n = Number(arguments[2]);
if (n != n) { // shortcut for verifying if it's NaN
n = 0;
} else if (n !== 0 && n !== Infinity && n !== -Infinity) {
} else if (n != 0 && n != Infinity && n != -Infinity) {
n = (n > 0 || -1) * Math.floor(Math.abs(n));
}
}
@ -363,12 +363,12 @@ exports.keys = function(obj) {
}
return keys;
}
};
}
})();
(function() {
var lib = modules.lib;
var Object = modules.object;
var lib = modules["lib"];
var Object = modules["object"];
// Frames keep track of scoping both at compile-time and run-time so
// we know how to access variables. Block tags can introduce special
@ -429,14 +429,13 @@ function makeMacro(argNames, kwargNames, func) {
var args;
var kwargs = getKeywordArgs(arguments);
var i;
if(argCount > argNames.length) {
args = Array.prototype.slice.call(arguments, 0, argNames.length);
// Positional arguments that should be passed in as
// keyword arguments (essentially default values)
var vals = Array.prototype.slice.call(arguments, args.length, argCount);
for(i=0; i<vals.length; i++) {
for(var i=0; i<vals.length; i++) {
if(i < kwargNames.length) {
kwargs[kwargNames[i]] = vals[i];
}
@ -447,7 +446,7 @@ function makeMacro(argNames, kwargNames, func) {
else if(argCount < argNames.length) {
args = Array.prototype.slice.call(arguments, 0, argCount);
for(i=argCount; i<argNames.length; i++) {
for(var i=argCount; i<argNames.length; i++) {
var arg = argNames[i];
// Keyword arguments that should be passed as
@ -644,7 +643,7 @@ function asyncAll(arr, dimen, func, cb) {
len = arr.length;
outputArr = new Array(len);
if(len === 0) {
if(len == 0) {
cb(null, '');
}
else {
@ -667,7 +666,7 @@ function asyncAll(arr, dimen, func, cb) {
len = keys.length;
outputArr = new Array(len);
if(len === 0) {
if(len == 0) {
cb(null, '');
}
else {
@ -679,7 +678,7 @@ function asyncAll(arr, dimen, func, cb) {
}
}
modules.runtime = {
modules['runtime'] = {
Frame: Frame,
makeMacro: makeMacro,
makeKeywordArgs: makeKeywordArgs,
@ -690,6 +689,7 @@ modules.runtime = {
callWrap: callWrap,
handleError: handleError,
isArray: lib.isArray,
asyncEach: lib.asyncEach,
keys: lib.keys,
SafeString: SafeString,
copySafeness: copySafeness,
@ -699,9 +699,111 @@ modules.runtime = {
};
})();
(function() {
var Obj = modules["object"];
var lib = modules["lib"];
var lib = modules.lib;
var r = modules.runtime;
var Loader = Obj.extend({
on: function(name, func) {
this.listeners = this.listeners || {};
this.listeners[name] = this.listeners[name] || [];
this.listeners[name].push(func);
},
emit: function(name /*, arg1, arg2, ...*/) {
var args = Array.prototype.slice.call(arguments, 1);
if(this.listeners && this.listeners[name]) {
lib.each(this.listeners[name], function(listener) {
listener.apply(null, args);
});
}
}
});
modules['loader'] = Loader;
})();
(function() {
var Loader = modules["loader"];
var WebLoader = Loader.extend({
init: function(baseURL, neverUpdate) {
// It's easy to use precompiled templates: just include them
// before you configure nunjucks and this will automatically
// pick it up and use it
this.precompiled = window.nunjucksPrecompiled || {};
this.baseURL = baseURL || '';
this.neverUpdate = neverUpdate;
},
getSource: function(name) {
if(this.precompiled[name]) {
return {
src: { type: "code",
obj: this.precompiled[name] },
path: name
};
}
else {
var src = this.fetch(this.baseURL + '/' + name);
if(!src) {
return null;
}
return { src: src,
path: name,
noCache: this.neverUpdate };
}
},
fetch: function(url, callback) {
// Only in the browser please
var ajax;
var loading = true;
var src;
if(window.XMLHttpRequest) { // Mozilla, Safari, ...
ajax = new XMLHttpRequest();
}
else if(window.ActiveXObject) { // IE 8 and older
ajax = new ActiveXObject("Microsoft.XMLHTTP");
}
ajax.onreadystatechange = function() {
if(ajax.readyState == 4 && ajax.status == 200 && loading) {
loading = false;
src = ajax.responseText;
}
};
url += (url.indexOf('?') === -1 ? '?' : '&') + 's=' +
(new Date().getTime());
// Synchronous because this API shouldn't be used in
// production (pre-load compiled templates instead)
ajax.open('GET', url, false);
ajax.send();
return src;
}
});
modules['web-loaders'] = {
WebLoader: WebLoader
};
})();
(function() {
if(typeof window === 'undefined') {
modules['loaders'] = modules["node-loaders"];
}
else {
modules['loaders'] = modules["web-loaders"];
}
})();
(function() {
var lib = modules["lib"];
var r = modules["runtime"];
var filters = {
abs: function(n) {
@ -723,7 +825,7 @@ var filters = {
if(tmp.length) {
if(fill_with) {
for(i=tmp.length; i<linecount; i++) {
for(var i=tmp.length; i<linecount; i++) {
tmp.push(fill_with);
}
}
@ -777,7 +879,7 @@ var filters = {
"dictsort filter: You can only sort by either key or value");
}
array.sort(function(t1, t2) {
array.sort(function(t1, t2) {
var a = t1[si];
var b = t2[si];
@ -795,16 +897,18 @@ var filters = {
return array;
},
escape: function(str) {
if(typeof str == 'string' ||
if(typeof str == 'string' ||
str instanceof r.SafeString) {
return lib.escape(str);
}
return str;
},
safe: r.markSafe,
safe: function(str) {
return r.markSafe(str);
},
first: function(arr) {
return arr[0];
@ -821,7 +925,7 @@ var filters = {
var sp = lib.repeat(' ', width);
for(var i=0; i<lines.length; i++) {
if(i === 0 && !indentfirst) {
if(i == 0 && !indentfirst) {
res += lines[i] + '\n';
}
else {
@ -984,7 +1088,7 @@ var filters = {
x = x.toLowerCase();
y = y.toLowerCase();
}
if(x < y) {
return reverse ? 1 : -1;
}
@ -1041,50 +1145,26 @@ var filters = {
return str.toUpperCase();
},
urlize: function(str, length, nofollow) {
if (isNaN(length)) length = Infinity;
var noFollowAttr = (nofollow === true ? ' rel="nofollow"' : '');
// For the jinja regexp, see
// https://github.com/mitsuhiko/jinja2/blob/f15b814dcba6aa12bc74d1f7d0c881d55f7126be/jinja2/utils.py#L20-L23
var puncRE = /^(?:\(|<|&lt;)?(.*?)(?:\.|,|\)|\n|&gt;)?$/;
// from http://blog.gerv.net/2011/05/html5_email_address_regexp/
var emailRE = /^[\w.!#$%&'*+\-\/=?\^`{|}~]+@[a-z\d\-]+(\.[a-z\d\-]+)+$/i;
var httpHttpsRE = /^https?:\/\/.*$/;
var wwwRE = /^www\./;
var tldRE = /\.(?:org|net|com)(?:\:|\/|$)/;
var words = str.split(/\s+/).filter(function(word) {
// If the word has no length, bail. This can happen for str with
// trailing whitespace.
return word && word.length;
}).map(function(word) {
var matches = word.match(puncRE);
var possibleUrl = matches && matches[1] || word;
// url that starts with http or https
if (httpHttpsRE.test(possibleUrl))
return '<a href="' + possibleUrl + '"' + noFollowAttr + '>' + possibleUrl.substr(0, length) + '</a>';
// url that starts with www.
if (wwwRE.test(possibleUrl))
return '<a href="http://' + possibleUrl + '"' + noFollowAttr + '>' + possibleUrl.substr(0, length) + '</a>';
// an email address of the form username@domain.tld
if (emailRE.test(possibleUrl))
return '<a href="mailto:' + possibleUrl + '">' + possibleUrl + '</a>';
// url that ends in .com, .org or .net that is not an email address
if (tldRE.test(possibleUrl))
return '<a href="http://' + possibleUrl + '"' + noFollowAttr + '>' + possibleUrl.substr(0, length) + '</a>';
return possibleUrl;
});
return words.join(' ');
urlencode: function(obj) {
var enc = encodeURIComponent;
if (lib.isString(obj)) {
return enc(obj);
} else {
var parts;
if (lib.isArray(obj)) {
parts = obj.map(function(item) {
return enc(item[0]) + '=' + enc(item[1]);
})
} else {
parts = [];
for (var k in obj) {
if (obj.hasOwnProperty(k)) {
parts.push(enc(k) + '=' + enc(obj[k]));
}
}
}
return parts.join('&');
}
},
wordcount: function(str) {
@ -1106,7 +1186,7 @@ var filters = {
filters.d = filters['default'];
filters.e = filters.escape;
modules.filters = filters;
modules['filters'] = filters;
})();
(function() {
@ -1162,6 +1242,9 @@ var globals = {
return arr;
},
// lipsum: function(n, html, min, max) {
// },
cycler: function() {
return cycler(Array.prototype.slice.call(arguments));
},
@ -1169,16 +1252,19 @@ var globals = {
joiner: function(sep) {
return joiner(sep);
}
};
}
modules.globals = globals;
modules['globals'] = globals;
})();
(function() {
var lib = modules.lib;
var Obj = modules.object;
var builtin_filters = modules.filters;
var runtime = modules.runtime;
var globals = modules.globals;
var lib = modules["lib"];
var Obj = modules["object"];
var lexer = modules["lexer"];
var compiler = modules["compiler"];
var builtin_filters = modules["filters"];
var builtin_loaders = modules["loaders"];
var runtime = modules["runtime"];
var globals = modules["globals"];
var Frame = runtime.Frame;
var Environment = Obj.extend({
@ -1198,16 +1284,47 @@ var Environment = Obj.extend({
// defaults to false
this.autoesc = !!opts.autoescape;
if(!loaders) {
// The filesystem loader is only available client-side
if(builtin_loaders.FileSystemLoader) {
this.loaders = [new builtin_loaders.FileSystemLoader('views')];
}
else {
this.loaders = [new builtin_loaders.WebLoader('/views')];
}
}
else {
this.loaders = lib.isArray(loaders) ? loaders : [loaders];
}
this.initCache();
this.filters = {};
this.asyncFilters = [];
this.extensions = {};
this.extensionsList = [];
if(opts.tags) {
lexer.setTags(opts.tags);
}
for(var name in builtin_filters) {
this.addFilter(name, builtin_filters[name]);
}
},
initCache: function() {
// Caching and cache busting
var cache = {};
lib.each(this.loaders, function(loader) {
loader.on('update', function(template) {
cache[template] = null;
});
});
this.cache = cache;
},
addExtension: function(name, extension) {
extension._name = name;
this.extensions[name] = extension;
@ -1234,40 +1351,102 @@ var Environment = Obj.extend({
return this.filters[name];
},
getTemplate: function(name, cb) {
getTemplate: function(name, eagerCompile, cb) {
if(name && name.raw) {
// this fixes autoescape for templates referenced in symbols
name = name.raw;
}
if(lib.isFunction(eagerCompile)) {
cb = eagerCompile;
eagerCompile = false;
}
if(typeof name !== 'string') {
throw new Error('template names must be a string: ' + name);
}
var tmpl = this.cache[name];
var env = this;
tmpl.render = function(ctx, frame, cb) {
return this.root(env, new Context(ctx), frame, runtime, cb);
};
tmpl.getExported = function(cb) {
var ctx = new Context({});
this.root(env, ctx, new Frame(), runtime, function() {
cb(null, ctx.getExported());
});
};
if(tmpl) {
if(eagerCompile) {
tmpl.compile();
}
if(cb) {
cb.call(this, null, tmpl);
cb(null, tmpl);
}
else {
return tmpl;
}
} else {
throw new Error('Template not available: "' + name + '"');
var syncResult;
lib.asyncIter(this.loaders, function(loader, i, next, done) {
function handle(src) {
if(src) {
done(src);
}
else {
next();
}
}
if(loader.async) {
loader.getSource(name, function(err, src) {
if(err) { throw err; }
handle(src);
});
}
else {
handle(loader.getSource(name));
}
}, function(info) {
if(!info) {
var err = new Error('template not found: ' + name);
if(cb) {
cb(err);
}
else {
throw err;
}
}
else {
var tmpl = new Template(info.src, this,
info.path, eagerCompile);
if(!info.noCache) {
this.cache[name] = tmpl;
}
if(cb) {
cb(null, tmpl);
}
else {
syncResult = tmpl;
}
}
}.bind(this));
return syncResult;
}
},
express: function(app) {
var env = this;
function NunjucksView(name, opts) {
this.name = name;
this.path = name;
}
NunjucksView.prototype.render = function(opts, cb) {
env.render(this.name, opts, cb);
};
app.set('view', NunjucksView);
},
render: function(name, ctx, cb) {
if(lib.isFunction(ctx)) {
cb = ctx;
@ -1288,7 +1467,7 @@ var Environment = Obj.extend({
throw err;
}
else {
tmpl.root(this, new Context(ctx || {}), new Frame(), runtime, cb || function(err, res) {
tmpl.render(ctx, cb || function(err, res) {
if(err) { throw err; }
syncResult = res;
});
@ -1296,6 +1475,11 @@ var Environment = Obj.extend({
});
return syncResult;
},
renderString: function(src, ctx, cb) {
var tmpl = new Template(src, this);
return tmpl.render(ctx, cb);
}
});
@ -1368,17 +1552,186 @@ var Context = Obj.extend({
}
});
modules.environment = {Environment: Environment};
var Template = Obj.extend({
init: function (src, env, path, eagerCompile) {
this.env = env || new Environment();
if(lib.isObject(src)) {
switch(src.type) {
case 'code': this.tmplProps = src.obj; break;
case 'string': this.tmplStr = src.obj; break;
}
}
else if(lib.isString(src)) {
this.tmplStr = src;
}
else {
throw new Error("src must be a string or an object describing " +
"the source");
}
this.path = path;
if(eagerCompile) {
lib.withPrettyErrors(this.path,
this.env.dev,
this._compile.bind(this));
}
else {
this.compiled = false;
}
},
render: function(ctx, frame, cb) {
if (typeof ctx === 'function') {
cb = ctx;
ctx = {};
}
else if (typeof frame === 'function') {
cb = frame;
frame = null;
}
return lib.withPrettyErrors(this.path, this.env.dev, function() {
this.compile();
var context = new Context(ctx || {}, this.blocks);
var syncResult = null;
this.rootRenderFunc(this.env,
context,
frame || new Frame(),
runtime,
cb || function(err, res) {
if(err) { throw err; }
syncResult = res;
});
return syncResult;
}.bind(this));
},
getExported: function(cb) {
this.compile();
// Run the rootRenderFunc to populate the context with exported vars
var context = new Context({}, this.blocks);
this.rootRenderFunc(this.env,
context,
new Frame(),
runtime,
function() {
cb(null, context.getExported());
});
},
compile: function() {
if(!this.compiled) {
this._compile();
}
},
_compile: function() {
var props;
if(this.tmplProps) {
props = this.tmplProps;
}
else {
var source = compiler.compile(this.tmplStr,
this.env.asyncFilters,
this.env.extensionsList,
this.path);
var func = new Function(source);
props = func();
}
this.blocks = this._getBlocks(props);
this.rootRenderFunc = props.root;
this.compiled = true;
},
_getBlocks: function(props) {
var blocks = {};
for(var k in props) {
if(k.slice(0, 2) == 'b_') {
blocks[k.slice(2)] = props[k];
}
}
return blocks;
}
});
// test code
// var src = 'hello {% foo baz | bar %}hi{% endfoo %} end';
// var env = new Environment(new builtin_loaders.FileSystemLoader('tests/templates', true), { dev: true });
// function FooExtension() {
// this.tags = ['foo'];
// this._name = 'FooExtension';
// this.parse = function(parser, nodes) {
// var tok = parser.nextToken();
// var args = parser.parseSignature(null, true);
// parser.advanceAfterBlockEnd(tok.value);
// var body = parser.parseUntilBlocks('endfoo');
// parser.advanceAfterBlockEnd();
// return new nodes.CallExtensionAsync(this, 'run', args, [body]);
// };
// this.run = function(context, baz, body, cb) {
// cb(null, baz + '--' + body());
// };
// }
// env.addExtension('FooExtension', new FooExtension());
// env.addFilter('bar', function(val, cb) {
// cb(null, val + '22222');
// }, true);
// var ctx = {};
// var tmpl = new Template(src, env, null, null, true);
// console.log("OUTPUT ---");
// tmpl.render(ctx, function(err, res) {
// if(err) {
// throw err;
// }
// console.log(res);
// });
modules['environment'] = {
Environment: Environment,
Template: Template
};
})();
var nunjucks;
var lib = modules.lib;
var env = modules.environment;
var runtime = modules.runtime;
var lib = modules["lib"];
var env = modules["environment"];
var compiler = modules["compiler"];
var parser = modules["parser"];
var lexer = modules["lexer"];
var runtime = modules["runtime"];
var Loader = modules["loader"];
var loaders = modules["loaders"];
var precompile = modules["precompile"];
nunjucks = {};
nunjucks.Environment = env.Environment;
nunjucks.Template = env.Template;
nunjucks.Loader = env.Loader;
nunjucks.FileSystemLoader = loaders.FileSystemLoader;
nunjucks.WebLoader = loaders.WebLoader;
nunjucks.compiler = compiler;
nunjucks.parser = parser;
nunjucks.lexer = lexer;
nunjucks.runtime = runtime;
// A single instance of an environment, since this is so commonly used
@ -1391,8 +1744,12 @@ nunjucks.configure = function(templatesPath, opts) {
templatesPath = null;
}
var noWatch = 'watch' in opts ? !opts.watch : false;
e = new env.Environment(null, opts);
var loader = loaders.FileSystemLoader || loaders.WebLoader;
e = new env.Environment(new loader(templatesPath, opts.watch), opts);
if(opts && opts.express) {
e.express(opts.express);
}
return e;
};
@ -1405,7 +1762,26 @@ nunjucks.render = function(name, ctx, cb) {
return e.render(name, ctx, cb);
};
nunjucks.renderString = function(src, ctx, cb) {
if(!e) {
nunjucks.configure();
}
return e.renderString(src, ctx, cb);
};
if(precompile) {
nunjucks.precompile = precompile.precompile;
nunjucks.precompileString = precompile.precompileString;
}
nunjucks.require = function(name) { return modules[name]; };
define('nunjucks', [], function() { return nunjucks; });
if(typeof define === 'function' && define.amd) {
define(function() { return nunjucks; });
}
else {
window.nunjucks = nunjucks;
}
})();

Просмотреть файл

@ -1,153 +0,0 @@
define('nunjucks.compat', ['nunjucks'], function(nunjucks) {
console.log('Loading nunjucks compat...')
var runtime = nunjucks.require('runtime');
var lib = nunjucks.require('lib');
var orig_contextOrFrameLookup = runtime.contextOrFrameLookup;
runtime.contextOrFrameLookup = function(context, frame, key) {
var val = orig_contextOrFrameLookup.apply(this, arguments);
if (val === undefined) {
switch (key) {
case 'True':
return true;
case 'False':
return false;
case 'None':
return null;
}
}
return val;
};
var orig_memberLookup = runtime.memberLookup;
var ARRAY_MEMBERS = {
pop: function(index) {
if (index === undefined) {
return this.pop();
}
if (index >= this.length || index < 0) {
throw new Error('KeyError');
}
return this.splice(index, 1);
},
remove: function(element) {
for (var i = 0; i < this.length; i++) {
if (this[i] == element) {
return this.splice(i, 1);
}
}
throw new Error('ValueError');
},
count: function(element) {
var count = 0;
for (var i = 0; i < this.length; i++) {
if (this[i] == element) {
count++;
}
}
return count;
},
index: function(element) {
var i;
if ((i = this.indexOf(element)) == -1) {
throw new Error('ValueError');
}
return i;
},
find: function(element) {
return this.indexOf(element);
},
insert: function(index, elem) {
return this.splice(index, 0, elem);
}
};
var OBJECT_MEMBERS = {
items: function() {
var ret = [];
for(var k in this) {
ret.push([k, this[k]]);
}
return ret;
},
values: function() {
var ret = [];
for(var k in this) {
ret.push(this[k]);
}
return ret;
},
keys: function() {
var ret = [];
for(var k in this) {
ret.push(k);
}
return ret;
},
get: function(key, def) {
var output = this[key];
if (output === undefined) {
output = def;
}
return output;
},
has_key: function(key) {
return this.hasOwnProperty(key);
},
pop: function(key, def) {
var output = this[key];
if (output === undefined && def !== undefined) {
output = def;
} else if (output === undefined) {
throw new Error('KeyError');
} else {
delete this[key];
}
return output;
},
popitem: function() {
for (var k in this) {
// Return the first object pair.
var val = this[k];
delete this[k];
return [k, val];
}
throw new Error('KeyError');
},
setdefault: function(key, def) {
if (key in this) {
return this[key];
}
if (def === undefined) {
def = null;
}
return this[key] = def;
},
update: function(kwargs) {
for (var k in kwargs) {
this[k] = kwargs[k];
}
return null; // Always returns None
}
};
OBJECT_MEMBERS.iteritems = OBJECT_MEMBERS.items;
OBJECT_MEMBERS.itervalues = OBJECT_MEMBERS.values;
OBJECT_MEMBERS.iterkeys = OBJECT_MEMBERS.keys;
runtime.memberLookup = function(obj, val, autoescape) {
obj = obj || {};
// If the object is an object, return any of the methods that Python would
// otherwise provide.
if (lib.isArray(obj) && ARRAY_MEMBERS.hasOwnProperty(val)) {
return function() {return ARRAY_MEMBERS[val].apply(obj, arguments);};
}
if (lib.isObject(obj) && OBJECT_MEMBERS.hasOwnProperty(val)) {
return function() {return OBJECT_MEMBERS[val].apply(obj, arguments);};
}
return orig_memberLookup.apply(this, arguments);
};
});

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Просмотреть файл

@ -1,14 +1,13 @@
// Underscore.js 1.4.4
// ===================
// Underscore.js 1.4.4
// http://underscorejs.org
// (c) 2009-2013 Jeremy Ashkenas, DocumentCloud Inc.
// Underscore may be freely distributed under the MIT license.
// > http://underscorejs.org
// > (c) 2009-2013 Jeremy Ashkenas, DocumentCloud Inc.
// > Underscore may be freely distributed under the MIT license.
// Baseline setup
// --------------
(function() {
// Baseline setup
// --------------
// Establish the root object, `window` in the browser, or `global` on the server.
var root = this;
@ -1224,6 +1223,4 @@
});
define('underscore', [], function() {return _;});
}).call(this);