-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9917efe
commit bb829aa
Showing
4 changed files
with
81 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,6 +36,7 @@ const helpersList = [ | |
'limit', | ||
'moment', | ||
'money', | ||
'multiConcat', | ||
'nl2br', | ||
'occurrences', | ||
'option', | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); | ||
}); |