Skip to content

Commit bfdb2ce

Browse files
committed
Cleaning up a bit
1 parent 24a9a58 commit bfdb2ce

File tree

1 file changed

+21
-9
lines changed

1 file changed

+21
-9
lines changed

lib/common/template-utils.js

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,27 @@ async function compileTemplate (filePath) {
2121
* @return {Promise}
2222
*/
2323
async function processHandlebarFile (filePath, substitutions) {
24-
return processFile(filePath, (rawSource) => {
25-
try {
26-
const template = Handlebars.compile(rawSource)
27-
return template(substitutions)
28-
} catch (error) {
29-
debug(`Error processing template: ${error}`)
30-
return rawSource
31-
}
32-
})
24+
return processFile(filePath, (rawSource) => processHandlebarTemplate(rawSource, substitutions))
25+
}
26+
27+
/**
28+
* Performs a Handlebars string template substitution, and returns the
29+
* resulting string.
30+
*
31+
* @see https://www.npmjs.com/package/handlebars
32+
*
33+
* @param source {string} e.g. 'Hello, {{name}}'
34+
*
35+
* @return {string} Result, e.g. 'Hello, Alice'
36+
*/
37+
function processHandlebarTemplate (source, substitutions) {
38+
try {
39+
const template = Handlebars.compile(source)
40+
return template(substitutions)
41+
} catch (error) {
42+
debug(`Error processing template: ${error}`)
43+
return source
44+
}
3345
}
3446

3547
function writeTemplate (filePath, template, substitutions) {

0 commit comments

Comments
 (0)