diff --git a/README.md b/README.md index e4b700c..4bf829a 100644 --- a/README.md +++ b/README.md @@ -136,7 +136,12 @@ Outputs contents if a complex boolean logic expression is satisfied. Uses string ### slice Loop through a subset of items -- `{{#slice items limit="2" offset="4"}} some content {{/slice}} +- `{{#slice items limit="2" offset="4"}} some content {{/slice}}` + +### increment +Displays `@index` value added to given argument (e.g. an argument of `1` will display ordinal not cardinal numbers, i.e. values start from 1 not 0). +- `{{#each array}}{{#increment 1}}{{@index}}{{/increment}}{{/each}}` + ## Presenter helpers diff --git a/src/extend-helpers.js b/src/extend-helpers.js index ca7d247..52b7c24 100644 --- a/src/extend-helpers.js +++ b/src/extend-helpers.js @@ -18,6 +18,7 @@ module.exports = function (helpers) { helpers.defineBlock = require('./helpers/defineBlock'); helpers.outputBlock = require('./helpers/outputBlock'); helpers.slice = require('./helpers/slice'); + helpers.increment = require('./helpers/increment'); helpers.json = require('./helpers/json'); helpers.concat = require('./helpers/concat'); helpers.usePartial = require('./helpers/usePartial'); diff --git a/src/helpers/increment.js b/src/helpers/increment.js new file mode 100644 index 0000000..5eefef3 --- /dev/null +++ b/src/helpers/increment.js @@ -0,0 +1,5 @@ +'use strict'; + +module.exports = function (incrementBy, options) { + return parseInt(options.fn(this)) + incrementBy; +}; diff --git a/test/express.test.js b/test/express.test.js index 15a12b1..c3dbe3a 100755 --- a/test/express.test.js +++ b/test/express.test.js @@ -60,6 +60,12 @@ describe('express handlebars setup', function() { .get('/templated') .expect(200, /slice\:34\:end/, done); }); + + it('should provide an index increment helper', function(done) { + request(app) + .get('/templated') + .expect(200, /increment\:12345\:end/, done); + }); }); describe('logic helpers', function () { diff --git a/test/fixtures/app/views/main.html b/test/fixtures/app/views/main.html index 8709251..65daa37 100644 --- a/test/fixtures/app/views/main.html +++ b/test/fixtures/app/views/main.html @@ -43,6 +43,7 @@