Skip to content

Commit

Permalink
feat: multi concat (#236)
Browse files Browse the repository at this point in the history
  • Loading branch information
juliachen-arcticleaf authored Mar 14, 2023
1 parent 9917efe commit bb829aa
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 0 deletions.
1 change: 1 addition & 0 deletions helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ const helpersList = [
'limit',
'moment',
'money',
'multiConcat',
'nl2br',
'occurrences',
'option',
Expand Down
24 changes: 24 additions & 0 deletions helpers/multiConcat.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
'use strict';

/**
* Concats multi values, primarily used as a subhelper
* @example
* {{multiConcat "string1" "string2" "string3"}}
*/


const factory = globals => {
return function(...args) {
// Take the last arg which is a Handlebars options object out of args array
args.pop();

return args.join('');
};

};


module.exports = [{
name: 'multiConcat',
factory: factory,
}];
1 change: 1 addition & 0 deletions spec/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ describe('helper registration', () => {
'limit',
'moment',
'money',
'multiConcat',
'nl2br',
'occurrences',
'option',
Expand Down
55 changes: 55 additions & 0 deletions spec/helpers/multiConcat.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
const Lab = require('lab'),
lab = exports.lab = Lab.script(),
describe = lab.experiment,
it = lab.it,
testRunner = require('../spec-helpers').testRunner;


describe('multiConcat helper', function() {
const context = {
string1: "First",
string2: "Second",
string3: "Third",
string4: "Fourth"
};

const runTestCases = testRunner({context});

it('should concatenate all strings by default', function(done) {
runTestCases([
{
input: '{{multiConcat string1 string2 string3}}',
output: 'FirstSecondThird',
},
{
input: '{{multiConcat string1 string2 string3 string4}}',
output: 'FirstSecondThirdFourth',
},
{
input: '{{multiConcat string1 string2}}',
output: 'FirstSecond',
}
], done);
});

it('should accept string, number, boolean, empty', function(done) {
runTestCases([
{
input: '{{multiConcat "First" 2}}',
output: 'First2',
},
{
input: '{{multiConcat string1 3 "" "4" true}}',
output: 'First34true',
},
{
input: '{{multiConcat string1 3 false "" "4" true}}',
output: 'First3false4true',
},
{
input: '{{multiConcat string1 ""}}',
output: 'First',
}
], done);
});
});

0 comments on commit bb829aa

Please sign in to comment.