mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-20 22:42:53 -05:00
parent
48bc031ac1
commit
3b235b9acb
2 changed files with 10 additions and 2 deletions
|
@ -18,7 +18,7 @@ foreach = function (context, options) {
|
||||||
inverse = options.inverse,
|
inverse = options.inverse,
|
||||||
columns = options.hash.columns,
|
columns = options.hash.columns,
|
||||||
length = _.size(context),
|
length = _.size(context),
|
||||||
limit = options.hash.limit || length,
|
limit = parseInt(options.hash.limit, 10) || length,
|
||||||
output = '',
|
output = '',
|
||||||
data,
|
data,
|
||||||
contextPath;
|
contextPath;
|
||||||
|
@ -63,7 +63,7 @@ foreach = function (context, options) {
|
||||||
|
|
||||||
_.each(context, function (item, key) {
|
_.each(context, function (item, key) {
|
||||||
if (count <= limit) {
|
if (count <= limit) {
|
||||||
execIteration(key, count - 1, count === length);
|
execIteration(key, count - 1, count === limit);
|
||||||
}
|
}
|
||||||
count += 1;
|
count += 1;
|
||||||
});
|
});
|
||||||
|
|
|
@ -355,6 +355,14 @@ describe('{{#foreach}} helper', function () {
|
||||||
shouldCompileToExpected(templateString, objectHash2, expected);
|
shouldCompileToExpected(templateString, objectHash2, expected);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('@last in foreach with limit', function () {
|
||||||
|
var templateString = '{{#foreach goodbyes limit="2"}}{{#if @last}}{{text}}! {{/if}}{{/foreach}}cruel {{world}}!',
|
||||||
|
expected = 'Goodbye! cruel world!';
|
||||||
|
|
||||||
|
shouldCompileToExpected(templateString, arrayHash2, expected);
|
||||||
|
shouldCompileToExpected(templateString, objectHash2, expected);
|
||||||
|
});
|
||||||
|
|
||||||
it('foreach with limit 1', function () {
|
it('foreach with limit 1', function () {
|
||||||
var templateString = '<ul>{{#foreach posts limit="1"}}<li>{{title}}</li>{{else}}not this{{/foreach}}</ul>',
|
var templateString = '<ul>{{#foreach posts limit="1"}}<li>{{title}}</li>{{else}}not this{{/foreach}}</ul>',
|
||||||
expected = '<ul><li>first</li></ul>';
|
expected = '<ul><li>first</li></ul>';
|
||||||
|
|
Loading…
Add table
Reference in a new issue