closes #187 foreach column parameter

- adds keys @rowStart and @rowEnd in foreach helper based on an argument passed in for the number of columns desired
- added setKeys function to remove  duplication code
This commit is contained in:
cobbspur 2013-06-23 16:46:02 +01:00
parent 510950595f
commit bf9c55a6fb

View File

@ -50,6 +50,7 @@
inverse = options.inverse,
i = 0,
j = 0,
columns = options.hash.columns,
key,
ret = "",
data;
@ -58,24 +59,33 @@
data = hbs.handlebars.createFrame(options.data);
}
function setKeys(_data, _i, _j, _columns) {
if (_i === 0) {
_data.first = true;
}
if (_i === _j - 1) {
_data.last = true;
}
// first post is index zero but still needs to be odd
if (_i % 2 === 1) {
_data.even = true;
} else {
_data.odd = true;
}
if (_i % _columns === 0) {
_data.rowStart = true;
} else if (_i % _columns === (_columns - 1)) {
_data.rowEnd = true;
}
return _data;
}
if (context && typeof context === 'object') {
if (context instanceof Array) {
for (j = context.length; i < j; i += 1) {
if (data) {
data.index = i;
data.first = data.last = data.even = data.odd = false;
if (i === 0) {
data.first = true;
}
if (i === j - 1) {
data.last = true;
}
// first post is index zero but still needs to be odd
if (i % 2 === 1) {
data.even = true;
} else {
data.odd = true;
}
data.first = data.rowEnd = data.rowStart = data.last = data.even = data.odd = false;
data = setKeys(data, i, j, columns);
}
ret = ret + fn(context[i], { data: data });
}
@ -89,19 +99,8 @@
if (context.hasOwnProperty(key)) {
if (data) {
data.key = key;
data.first = data.last = data.even = data.odd = false;
if (i === 0) {
data.first = true;
}
if (i === j - 1) {
data.last = true;
}
// first post is index zero but still needs to be odd
if (i % 2 === 1) {
data.even = true;
} else {
data.odd = true;
}
data.first = data.rowEnd = data.rowStart = data.last = data.even = data.odd = false;
data = setKeys(data, i, j, columns);
}
ret = ret + fn(context[key], {data: data});
i += 1;