gpreview
Version:
Preview Ghost themes locally without a full Ghost installation
39 lines • 1.22 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.foreachHelper = foreachHelper;
function foreachHelper(context, options) {
if (!options) {
options = context;
context = this;
}
const items = context;
if (!items || !Array.isArray(items)) {
return options.inverse(this);
}
const results = [];
const length = items.length;
items.forEach((item, index) => {
const data = {
...(options.data || {}),
index: index,
number: index + 1,
first: index === 0,
last: index === length - 1,
even: index % 2 === 0,
odd: index % 2 === 1,
rowStart: false,
rowEnd: false,
};
if (options.hash.columns) {
const columns = parseInt(options.hash.columns, 10);
data.rowStart = index % columns === 0;
data.rowEnd = (index + 1) % columns === 0 || index === length - 1;
}
if (options.hash.key) {
data.key = options.hash.key;
}
results.push(options.fn(item, { data }));
});
return results.join('');
}
//# sourceMappingURL=foreach.js.map