-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #17 from gsandf/gsandf-linting
🚨 move to using GS&F code style
- Loading branch information
Showing
6 changed files
with
135 additions
and
137 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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
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 |
---|---|---|
@@ -1,31 +1,32 @@ | ||
const pify = require('pify') | ||
const readFile = pify(require('fs').readFile) | ||
const valueForProperty = require('dot-prop').get | ||
const pify = require('pify'); | ||
const readFile = pify(require('fs').readFile); | ||
const valueForProperty = require('dot-prop').get; | ||
|
||
function renderString(template, data) { | ||
return template.replace(/\{\{\s?(.*?)\s?\}\}/g, (match, captured) => { | ||
const replacement = valueForProperty(data, captured.trim()) | ||
const replacement = valueForProperty(data, captured.trim()); | ||
|
||
// If a template variable is found but nothing is supplied to fill it, remove it | ||
if (replacement == null) { | ||
return '' | ||
return ''; | ||
} | ||
|
||
// If the replacement is a function, replace the variable with the result of the function | ||
if (typeof replacement === 'function') { | ||
return replacement() | ||
return replacement(); | ||
} | ||
|
||
return replacement | ||
}) | ||
return replacement; | ||
}); | ||
} | ||
|
||
function renderTemplateFile(filepath, data) { | ||
return readFile(filepath, 'utf8') | ||
.then(templateString => renderString(templateString, data)) | ||
return readFile(filepath, 'utf8').then(templateString => | ||
renderString(templateString, data) | ||
); | ||
} | ||
|
||
module.exports = { | ||
renderString, | ||
renderTemplateFile | ||
} | ||
}; |
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
Oops, something went wrong.