mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-06 22:40:14 -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,
|
||||
columns = options.hash.columns,
|
||||
length = _.size(context),
|
||||
limit = options.hash.limit || length,
|
||||
limit = parseInt(options.hash.limit, 10) || length,
|
||||
output = '',
|
||||
data,
|
||||
contextPath;
|
||||
|
@ -63,7 +63,7 @@ foreach = function (context, options) {
|
|||
|
||||
_.each(context, function (item, key) {
|
||||
if (count <= limit) {
|
||||
execIteration(key, count - 1, count === length);
|
||||
execIteration(key, count - 1, count === limit);
|
||||
}
|
||||
count += 1;
|
||||
});
|
||||
|
|
|
@ -355,6 +355,14 @@ describe('{{#foreach}} helper', function () {
|
|||
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 () {
|
||||
var templateString = '<ul>{{#foreach posts limit="1"}}<li>{{title}}</li>{{else}}not this{{/foreach}}</ul>',
|
||||
expected = '<ul><li>first</li></ul>';
|
||||
|
|
Loading…
Reference in a new issue