smarthbs/ts/smarthbs.partials.ts

25 lines
902 B
TypeScript
Raw Normal View History

2017-03-19 16:14:28 +00:00
import * as plugins from './smarthbs.plugins'
/**
* registers a directory of partials to make them available within handlebars compilation
*/
2017-05-01 14:57:53 +00:00
export let registerPartialDir = (dirPathArg: string): Promise<any> => {
2017-03-19 16:14:28 +00:00
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))
2017-05-11 12:51:20 +00:00
if (parsedPath.dir === '/') {
parsedPath.dir = ''
2017-03-19 16:14:28 +00:00
}
2017-05-11 12:51:20 +00:00
if (parsedPath.dir !== '') {
parsedPath.dir = parsedPath.dir + '/'
}
let partialName = `partials/${parsedPath.dir}${parsedPath.name}`
2017-03-19 16:14:28 +00:00
plugins.handlebars.registerPartial(partialName, hbsFileString)
done.resolve()
}
})
return done.promise
}