This commit is contained in:
2017-03-19 17:14:28 +01:00
parent 9297711793
commit 34cfe010f7
18 changed files with 191 additions and 121 deletions
+21
View File
@@ -0,0 +1,21 @@
import * as plugins from './smarthbs.plugins'
/**
* registers a directory of partials to make them available within handlebars compilation
*/
export let registerPartialDir = (dirPathArg: string) => {
let done = plugins.smartq.defer()
plugins.smartfile.fs.listFileTree(dirPathArg, '**/*.hbs').then(hbsFileArrayArg => {
for (let hbsFilePath of hbsFileArrayArg) {
let parsedPath = plugins.path.parse(hbsFilePath)
let hbsFileString = plugins.smartfile.fs.toStringSync(plugins.path.join(dirPathArg, hbsFilePath))
if (parsedPath.dir === '') {
parsedPath.name = '/' + parsedPath.name
}
let partialName = `partials${parsedPath.dir}${parsedPath.name}`
plugins.handlebars.registerPartial(partialName, hbsFileString)
done.resolve()
}
})
return done.promise
}