Skip to content

fix before to work as expected #289

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/array.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ helpers.arrayify = function(value) {

helpers.before = function(array, n) {
if (util.isUndefined(array)) return '';
return array.slice(0, -n);
return array.slice(0, n);
};

/**
Expand Down Expand Up @@ -617,7 +617,7 @@ helpers.withAfter = function(array, idx, options) {

helpers.withBefore = function(array, idx, options) {
if (!Array.isArray(array)) return '';
array = array.slice(0, -idx);
array = array.slice(0, idx);
var result = '';

for (var i = 0; i < array.length; i++) {
Expand Down
6 changes: 3 additions & 3 deletions test/array.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@ describe('array', function() {
assert.equal(hbs.compile('{{before}}')(), '');
});
it('should return all of the items in an array before the given index', function() {
var fn = hbs.compile('{{before array 5}}');
var fn = hbs.compile('{{before array 3}}');
assert.equal(fn(context), 'a,b,c');
});

it('should return all of the items in an array before the specified count', function() {
var fn = hbs.compile('{{before array 5}}');
var fn = hbs.compile('{{before array 3}}');
assert.equal(fn(context), 'a,b,c');
});
});
Expand Down Expand Up @@ -396,7 +396,7 @@ describe('array', function() {

describe('withBefore', function() {
it('should use all of the items in an array before the specified count', function() {
var fn = hbs.compile('{{#withBefore array 5}}<{{this}}>{{/withBefore}}');
var fn = hbs.compile('{{#withBefore array 3}}<{{this}}>{{/withBefore}}');
assert.equal(fn(context), '<a><b><c>');
});
});
Expand Down