Skip to content
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

feat: multi concat #236

Merged
merged 15 commits into from
Mar 14, 2023
Merged
1 change: 1 addition & 0 deletions helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,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);
});
});