now supports frontmatter for advanced file templating

This commit is contained in:
2017-05-27 23:52:58 +02:00
parent fa961f86b8
commit b9a346c5d7
8 changed files with 77 additions and 11 deletions

View File

@@ -69,12 +69,22 @@ export class ScafTemplate {
async writeToDisk (destinationDirArg) {
let smartfileArrayToWrite = plugins.lodash.cloneDeep(this.templateSmartfileArray)
for (let smartfile of smartfileArrayToWrite) {
// render the template
let template = await plugins.smarthbs.getTemplateForString(
smartfile.contents.toString()
)
let renderedTemplateString = template(this.suppliedVariables)
smartfile.contents = Buffer.from(renderedTemplateString)
// handle frontmatter
let parsedTemplate = plugins.smartfm.parse(renderedTemplateString)
if (parsedTemplate.data.fileName) {
smartfile.updateFileName(parsedTemplate.data.fileName)
}
smartfile.contents = Buffer.from(parsedTemplate.content)
}
await plugins.smartfile.memory.smartfileArrayToFs(smartfileArrayToWrite, destinationDirArg)
}