mirror of
https://github.com/Mibew/mibew.git
synced 2025-03-01 01:24:32 +03:00
Add "repeat" Handlebars.js helper
This commit is contained in:
parent
814869ec77
commit
75276ab2da
@ -214,4 +214,23 @@
|
||||
return options.inverse(this);
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* Registers "repeat" helper.
|
||||
*
|
||||
* This helper repeats a string specified number of times. Example of usage:
|
||||
* <code>
|
||||
* {{#repeat times}}content to repeat{{/repeat}}
|
||||
* </code>
|
||||
*/
|
||||
Handlebars.registerHelper('repeat', function(count, options) {
|
||||
var result = '',
|
||||
content = options.fn(this);
|
||||
|
||||
for (var i = 0; i < count; i++) {
|
||||
result += content;
|
||||
}
|
||||
|
||||
return result;
|
||||
});
|
||||
})(Mibew, Handlebars);
|
@ -155,3 +155,15 @@ test('ifEqual', function() {
|
||||
'Test equal values'
|
||||
);
|
||||
});
|
||||
|
||||
// Test "repeat" Handlebars helper
|
||||
test('repeat', function() {
|
||||
var template = '{{#repeat times}}{{foo}}{{/repeat}}';
|
||||
var compiledTemplate = Handlebars.compile(template);
|
||||
|
||||
equal(
|
||||
compiledTemplate({foo: 'Foo.', times: 3}),
|
||||
'Foo.Foo.Foo.',
|
||||
'Test repeating'
|
||||
);
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user