Skip to content

Commit

Permalink
Bump version to 2.4.0.
Browse files Browse the repository at this point in the history
  • Loading branch information
carljm committed Mar 10, 2016
1 parent f7ebe0d commit 4deb594
Show file tree
Hide file tree
Showing 6 changed files with 162 additions and 65 deletions.
4 changes: 2 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Changelog
=========

2.x (unreleased)
----------------
2.4.0 (Mar 10 2016)
-------------------

* Allow retrieving boolean-false as a global. Thanks Marius Büscher. Merge of
[#694](https://github.com/mozilla/nunjucks/pull/694).
Expand Down
68 changes: 51 additions & 17 deletions browser/nunjucks-slim.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*! Browser bundle of nunjucks 2.3.0 (slim, only works with precompiled templates) */
/*! Browser bundle of nunjucks 2.4.0 (slim, only works with precompiled templates) */
var nunjucks =
/******/ (function(modules) { // webpackBootstrap
/******/ // The module cache
Expand Down Expand Up @@ -425,6 +425,17 @@ var nunjucks =
}
};

exports.inOperator = function (key, arrOrObj) {
if (exports.isArray(arrOrObj)) {
return exports.indexOf(arrOrObj, key) !== -1;
} else if (exports.isObject(arrOrObj)) {
return key in arrOrObj;
} else {
throw new Error('Cannot use "in" operator to search for "'
+ key + '" in unexpected types.');
}
};


/***/ },
/* 2 */
Expand Down Expand Up @@ -556,7 +567,7 @@ var nunjucks =
},

getGlobal: function(name) {
if(!this.globals[name]) {
if(typeof this.globals[name] === 'undefined') {
throw new Error('global not found: ' + name);
}
return this.globals[name];
Expand Down Expand Up @@ -865,7 +876,7 @@ var nunjucks =
_this._compile();
}
catch(err) {
throw lib.prettifyError(this.path, this.env.dev, err);
throw lib.prettifyError(this.path, this.env.opts.dev, err);
}
}
else {
Expand Down Expand Up @@ -897,13 +908,13 @@ var nunjucks =
try {
_this.compile();
} catch (_err) {
var err = lib.prettifyError(this.path, this.env.dev, _err);
var err = lib.prettifyError(this.path, this.env.opts.dev, _err);
if (cb) return callbackAsap(cb, err);
else throw err;
}

var context = new Context(ctx || {}, _this.blocks, _this.env);
var frame = parentFrame ? parentFrame.push() : new Frame();
var frame = parentFrame ? parentFrame.push(true) : new Frame();
frame.topLevel = true;
var syncResult = null;

Expand All @@ -914,7 +925,7 @@ var nunjucks =
runtime,
function(err, res) {
if(err) {
err = lib.prettifyError(_this.path, _this.env.dev, err);
err = lib.prettifyError(_this.path, _this.env.opts.dev, err);
}

if(cb) {
Expand Down Expand Up @@ -1761,6 +1772,26 @@ var nunjucks =
return res;
},

sum: function(arr, attr, start) {
var sum = 0;

if(typeof start === 'number'){
sum += start;
}

if(attr) {
arr = lib.map(arr, function(v) {
return v[attr];
});
}

for(var i = 0; i < arr.length; i++) {
sum += arr[i];
}

return sum;
},

sort: r.makeMacro(['value', 'reverse', 'case_sensitive', 'attribute'], [], function(arr, reverse, caseSens, attr) {
// Copy it
arr = lib.map(arr, function(v) { return v; });
Expand Down Expand Up @@ -1895,7 +1926,7 @@ var nunjucks =
var wwwRE = /^www\./;
var tldRE = /\.(?:org|net|com)(?:\:|\/|$)/;

var words = str.split(/\s+/).filter(function(word) {
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;
Expand Down Expand Up @@ -1923,7 +1954,7 @@ var nunjucks =

});

return words.join(' ');
return words.join('');
},

wordcount: function(str) {
Expand Down Expand Up @@ -1963,10 +1994,13 @@ var nunjucks =
// we know how to access variables. Block tags can introduce special
// variables, for example.
var Frame = Obj.extend({
init: function(parent) {
init: function(parent, isolateWrites) {
this.variables = {};
this.parent = parent;
this.topLevel = false;
// if this is true, writes (set) should never propagate upwards past
// this frame to its parent (though reads may).
this.isolateWrites = isolateWrites;
},

set: function(name, val, resolveUp) {
Expand All @@ -1977,11 +2011,10 @@ var nunjucks =
var frame = this;

if(resolveUp) {
if((frame = this.resolve(parts[0]))) {
if((frame = this.resolve(parts[0], true))) {
frame.set(name, val);
return;
}
frame = this;
}

for(var i=0; i<parts.length - 1; i++) {
Expand Down Expand Up @@ -2013,17 +2046,17 @@ var nunjucks =
return p && p.lookup(name);
},

resolve: function(name) {
var p = this.parent;
resolve: function(name, forWrite) {
var p = (forWrite && this.isolateWrites) ? undefined : this.parent;
var val = this.variables[name];
if(val !== undefined && val !== null) {
return this;
}
return p && p.resolve(name);
},

push: function() {
return new Frame(this);
push: function(isolateWrites) {
return new Frame(this, isolateWrites);
},

pop: function() {
Expand Down Expand Up @@ -2311,7 +2344,8 @@ var nunjucks =
copySafeness: copySafeness,
markSafe: markSafe,
asyncEach: asyncEach,
asyncAll: asyncAll
asyncAll: asyncAll,
inOperator: lib.inOperator
};


Expand Down Expand Up @@ -2361,7 +2395,7 @@ var nunjucks =
function globals() {
return {
range: function(start, stop, step) {
if(!stop) {
if(typeof stop === 'undefined') {
stop = start;
start = 0;
step = 1;
Expand Down
4 changes: 2 additions & 2 deletions browser/nunjucks-slim.min.js

Large diffs are not rendered by default.

Loading

0 comments on commit 4deb594

Please sign in to comment.