Skip to content

Commit

Permalink
add dist files for travis
Browse files Browse the repository at this point in the history
  • Loading branch information
jmealo committed Jun 8, 2014
1 parent 19fe85e commit bb2bc0e
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 4 deletions.
Empty file added demos/test.html
Empty file.
49 changes: 49 additions & 0 deletions twig.js
Original file line number Diff line number Diff line change
Expand Up @@ -1706,6 +1706,23 @@ var Twig = (function(Twig) {
return string.split(search).join(replace);
};

// chunk an array (arr) into arrays of (size) items, returns an array of arrays, or an empty array on invalid input
Twig.lib.chunkArray = function (arr, size) {
var returnVal = [],
x = 0,
len = arr.length;

if (size < 1 || !Twig.lib.is("Array", arr)) {
return [];
}

while (x < len) {
returnVal.push(arr.slice(x, x += size));
}

return returnVal;
};

return Twig;

})(Twig || { });
Expand Down Expand Up @@ -4521,6 +4538,38 @@ var Twig = (function (Twig) {
raw: function(value) {
//Raw filter shim
return value;
},
batch: function(items, params) {
var size = params.shift(),
fill = params.shift(),
result,
last,
missing;

if (!Twig.lib.is("Array", items)) {
throw new Twig.Error("batch filter expects items to be an array");
}

if (!Twig.lib.is("Number", size)) {
throw new Twig.Error("batch filter expects size to be a number");
}

size = Math.ceil(size);

result = Twig.lib.chunkArray(items, size);

if (fill && items.length % size != 0) {
last = result.pop();
missing = size - last.length;

while (missing--) {
last.push(fill);
}

result.push(last);
}

return result;
}
};

Expand Down
6 changes: 3 additions & 3 deletions twig.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion twig.min.js.map

Large diffs are not rendered by default.

0 comments on commit bb2bc0e

Please sign in to comment.