Skip to content

Commit 24a9a58

Browse files
committed
Trying to make code more readable
And by that hopefully more maintainable
1 parent 16688d4 commit 24a9a58

File tree

1 file changed

+12
-19
lines changed

1 file changed

+12
-19
lines changed

lib/common/template-utils.js

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -21,27 +21,20 @@ async function compileTemplate (filePath) {
2121
* @return {Promise}
2222
*/
2323
async function processHandlebarFile (filePath, substitutions) {
24-
return processFile(filePath, (rawSource) => processHandlebarTemplate(rawSource, 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+
})
2533
}
2634

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-
}
35+
function writeTemplate (filePath, template, substitutions) {
36+
const source = template(substitutions)
37+
writeFile(filePath, source)
4538
}
4639

4740
function writeTemplate (filePath, template, substitutions) {

0 commit comments

Comments
 (0)