This commit is contained in:
Philipp Kunz 2017-03-19 17:14:28 +01:00
parent 9297711793
commit 34cfe010f7
18 changed files with 191 additions and 121 deletions

18
dist/index.d.ts vendored
View File

@ -1,15 +1,5 @@
/// <reference types="handlebars" />
import 'typings-global';
export declare type TTemplateStringType = 'filePath' | 'code'; export declare type TTemplateStringType = 'filePath' | 'code';
/** export * from './smarthbs.compile';
* registers a directory of partials to make them available within handlebars compilation export * from './smarthbs.helpers';
*/ export * from './smarthbs.partials';
export declare let registerPartialDir: (dirPathArg: string) => Promise<{}>; export * from './smarthbs.template';
/**
* compiles a directory and outputs it
*/
export declare let compileDirectory: (originDirPathArg: string, destinationDirPathArg: string, dataFileNameArg: string) => Promise<void>;
/**
* get a template for a file on disk
*/
export declare let getTemplateForFile: (filePathArg: string) => Promise<HandlebarsTemplateDelegate>;

63
dist/index.js vendored
View File

@ -1,57 +1,10 @@
"use strict"; "use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function __export(m) {
return new (P || (P = Promise))(function (resolve, reject) { for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true }); Object.defineProperty(exports, "__esModule", { value: true });
require("typings-global"); __export(require("./smarthbs.compile"));
const handlebars = require("handlebars"); __export(require("./smarthbs.helpers"));
const smartfile = require("smartfile"); __export(require("./smarthbs.partials"));
const smartq = require("smartq"); __export(require("./smarthbs.template"));
const path = require("path"); //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7OztBQUdBLHdDQUFrQztBQUNsQyx3Q0FBa0M7QUFDbEMseUNBQW1DO0FBQ25DLHlDQUFtQyJ9
/**
* registers a directory of partials to make them available within handlebars compilation
*/
exports.registerPartialDir = (dirPathArg) => {
let done = smartq.defer();
smartfile.fs.listFileTree(dirPathArg, '**/*.hbs').then(hbsFileArrayArg => {
for (let hbsFilePath of hbsFileArrayArg) {
let parsedPath = path.parse(hbsFilePath);
let hbsFileString = smartfile.fs.toStringSync(path.join(dirPathArg, hbsFilePath));
if (parsedPath.dir === '') {
parsedPath.name = '/' + parsedPath.name;
}
let partialName = `partials${parsedPath.dir}${parsedPath.name}`;
handlebars.registerPartial(partialName, hbsFileString);
done.resolve();
}
});
return done.promise;
};
/**
* compiles a directory and outputs it
*/
exports.compileDirectory = (originDirPathArg, destinationDirPathArg, dataFileNameArg) => __awaiter(this, void 0, void 0, function* () {
let hbsFilePathArray = smartfile.fs.listFilesSync(originDirPathArg, /.hbs/);
let data = smartfile.fs.toObjectSync(path.join(originDirPathArg, dataFileNameArg));
for (let hbsFilePath of hbsFilePathArray) {
let parsedPath = path.parse(hbsFilePath);
let hbsFileString = smartfile.fs.toStringSync(path.join(originDirPathArg, hbsFilePath));
let template = handlebars.compile(hbsFileString);
let output = template(data);
console.log('hi ' + output + ' hi');
smartfile.memory.toFsSync(output, path.join(destinationDirPathArg, parsedPath.name + '.html'));
}
});
/**
* get a template for a file on disk
*/
exports.getTemplateForFile = (filePathArg) => __awaiter(this, void 0, void 0, function* () {
let filePathAbsolute = path.resolve(filePathArg);
return handlebars.compile(smartfile.fs.toStringSync(filePathAbsolute));
});
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7Ozs7Ozs7O0FBQUEsM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SUFDaEcsQ0FBQztBQUNILENBQUMsQ0FBQSxDQUFBO0FBRUQ7O0dBRUc7QUFDUSxRQUFBLGtCQUFrQixHQUFHLENBQU8sV0FBbUI7SUFDeEQsSUFBSSxnQkFBZ0IsR0FBRyxJQUFJLENBQUMsT0FBTyxDQUFDLFdBQVcsQ0FBQyxDQUFBO0lBQ2hELE1BQU0sQ0FBQyxVQUFVLENBQUMsT0FBTyxDQUFDLFNBQVMsQ0FBQyxFQUFFLENBQUMsWUFBWSxDQUFDLGdCQUFnQixDQUFDLENBQUMsQ0FBQTtBQUN4RSxDQUFDLENBQUEsQ0FBQSJ9

4
dist/smarthbs.compile.d.ts vendored Normal file
View File

@ -0,0 +1,4 @@
/**
* compiles a directory and outputs it
*/
export declare let compileDirectory: (originDirPathArg: string, destinationDirPathArg: string, dataFileNameArg: string) => Promise<void>;

27
dist/smarthbs.compile.js vendored Normal file
View File

@ -0,0 +1,27 @@
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
const plugins = require("./smarthbs.plugins");
/**
* compiles a directory and outputs it
*/
exports.compileDirectory = (originDirPathArg, destinationDirPathArg, dataFileNameArg) => __awaiter(this, void 0, void 0, function* () {
let hbsFilePathArray = plugins.smartfile.fs.listFilesSync(originDirPathArg, /.hbs/);
let data = plugins.smartfile.fs.toObjectSync(plugins.path.join(originDirPathArg, dataFileNameArg));
for (let hbsFilePath of hbsFilePathArray) {
let parsedPath = plugins.path.parse(hbsFilePath);
let hbsFileString = plugins.smartfile.fs.toStringSync(plugins.path.join(originDirPathArg, hbsFilePath));
let template = plugins.handlebars.compile(hbsFileString);
let output = template(data);
console.log('hi ' + output + ' hi');
plugins.smartfile.memory.toFsSync(output, plugins.path.join(destinationDirPathArg, parsedPath.name + '.html'));
}
});
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRoYnMuY29tcGlsZS5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL3NtYXJ0aGJzLmNvbXBpbGUudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7Ozs7Ozs7OztBQUFBLDhDQUE2QztBQUU3Qzs7R0FFRztBQUNRLFFBQUEsZ0JBQWdCLEdBQUcsQ0FDNUIsZ0JBQXdCLEVBQ3hCLHFCQUE2QixFQUM3QixlQUF1QjtJQUV2QixJQUFJLGdCQUFnQixHQUFHLE9BQU8sQ0FBQyxTQUFTLENBQUMsRUFBRSxDQUFDLGFBQWEsQ0FBQyxnQkFBZ0IsRUFBRSxNQUFNLENBQUMsQ0FBQTtJQUNuRixJQUFJLElBQUksR0FBRyxPQUFPLENBQUMsU0FBUyxDQUFDLEVBQUUsQ0FBQyxZQUFZLENBQUMsT0FBTyxDQUFDLElBQUksQ0FBQyxJQUFJLENBQUMsZ0JBQWdCLEVBQUUsZUFBZSxDQUFDLENBQUMsQ0FBQTtJQUNsRyxHQUFHLENBQUMsQ0FBQyxJQUFJLFdBQVcsSUFBSSxnQkFBZ0IsQ0FBQyxDQUFDLENBQUM7UUFDekMsSUFBSSxVQUFVLEdBQUcsT0FBTyxDQUFDLElBQUksQ0FBQyxLQUFLLENBQUMsV0FBVyxDQUFDLENBQUE7UUFDaEQsSUFBSSxhQUFhLEdBQUcsT0FBTyxDQUFDLFNBQVMsQ0FBQyxFQUFFLENBQUMsWUFBWSxDQUFDLE9BQU8sQ0FBQyxJQUFJLENBQUMsSUFBSSxDQUFDLGdCQUFnQixFQUFFLFdBQVcsQ0FBQyxDQUFDLENBQUE7UUFDdkcsSUFBSSxRQUFRLEdBQUcsT0FBTyxDQUFDLFVBQVUsQ0FBQyxPQUFPLENBQUMsYUFBYSxDQUFDLENBQUE7UUFDeEQsSUFBSSxNQUFNLEdBQUcsUUFBUSxDQUFDLElBQUksQ0FBQyxDQUFBO1FBQzNCLE9BQU8sQ0FBQyxHQUFHLENBQUMsS0FBSyxHQUFHLE1BQU0sR0FBRyxLQUFLLENBQUMsQ0FBQTtRQUNuQyxPQUFPLENBQUMsU0FBUyxDQUFDLE1BQU0sQ0FBQyxRQUFRLENBQUMsTUFBTSxFQUFFLE9BQU8sQ0FBQyxJQUFJLENBQUMsSUFBSSxDQUFDLHFCQUFxQixFQUFFLFVBQVUsQ0FBQyxJQUFJLEdBQUcsT0FBTyxDQUFDLENBQUMsQ0FBQTtJQUNoSCxDQUFDO0FBQ0gsQ0FBQyxDQUFBLENBQUEifQ==

2
dist/smarthbs.helpers.d.ts vendored Normal file
View File

@ -0,0 +1,2 @@
/// <reference types="handlebars" />
export declare let registerHelper: typeof Handlebars.registerHelper;

5
dist/smarthbs.helpers.js vendored Normal file
View File

@ -0,0 +1,5 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const plugins = require("./smarthbs.plugins");
exports.registerHelper = plugins.handlebars.registerHelper;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRoYnMuaGVscGVycy5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL3NtYXJ0aGJzLmhlbHBlcnMudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7QUFBQSw4Q0FBNkM7QUFFbEMsUUFBQSxjQUFjLEdBQUcsT0FBTyxDQUFDLFVBQVUsQ0FBQyxjQUFjLENBQUEifQ==

4
dist/smarthbs.partials.d.ts vendored Normal file
View File

@ -0,0 +1,4 @@
/**
* registers a directory of partials to make them available within handlebars compilation
*/
export declare let registerPartialDir: (dirPathArg: string) => Promise<{}>;

23
dist/smarthbs.partials.js vendored Normal file
View File

@ -0,0 +1,23 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const plugins = require("./smarthbs.plugins");
/**
* registers a directory of partials to make them available within handlebars compilation
*/
exports.registerPartialDir = (dirPathArg) => {
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;
};
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRoYnMucGFydGlhbHMuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9zbWFydGhicy5wYXJ0aWFscy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOztBQUFBLDhDQUE2QztBQUU3Qzs7R0FFRztBQUNRLFFBQUEsa0JBQWtCLEdBQUcsQ0FBQyxVQUFrQjtJQUNqRCxJQUFJLElBQUksR0FBRyxPQUFPLENBQUMsTUFBTSxDQUFDLEtBQUssRUFBRSxDQUFBO0lBQ2pDLE9BQU8sQ0FBQyxTQUFTLENBQUMsRUFBRSxDQUFDLFlBQVksQ0FBQyxVQUFVLEVBQUUsVUFBVSxDQUFDLENBQUMsSUFBSSxDQUFDLGVBQWU7UUFDNUUsR0FBRyxDQUFDLENBQUMsSUFBSSxXQUFXLElBQUksZUFBZSxDQUFDLENBQUMsQ0FBQztZQUN4QyxJQUFJLFVBQVUsR0FBRyxPQUFPLENBQUMsSUFBSSxDQUFDLEtBQUssQ0FBQyxXQUFXLENBQUMsQ0FBQTtZQUNoRCxJQUFJLGFBQWEsR0FBRyxPQUFPLENBQUMsU0FBUyxDQUFDLEVBQUUsQ0FBQyxZQUFZLENBQUMsT0FBTyxDQUFDLElBQUksQ0FBQyxJQUFJLENBQUMsVUFBVSxFQUFFLFdBQVcsQ0FBQyxDQUFDLENBQUE7WUFDakcsRUFBRSxDQUFDLENBQUMsVUFBVSxDQUFDLEdBQUcsS0FBSyxFQUFFLENBQUMsQ0FBQyxDQUFDO2dCQUMxQixVQUFVLENBQUMsSUFBSSxHQUFHLEdBQUcsR0FBRyxVQUFVLENBQUMsSUFBSSxDQUFBO1lBQ3pDLENBQUM7WUFDRCxJQUFJLFdBQVcsR0FBRyxXQUFXLFVBQVUsQ0FBQyxHQUFHLEdBQUcsVUFBVSxDQUFDLElBQUksRUFBRSxDQUFBO1lBQy9ELE9BQU8sQ0FBQyxVQUFVLENBQUMsZUFBZSxDQUFDLFdBQVcsRUFBRSxhQUFhLENBQUMsQ0FBQTtZQUM5RCxJQUFJLENBQUMsT0FBTyxFQUFFLENBQUE7UUFDaEIsQ0FBQztJQUNILENBQUMsQ0FBQyxDQUFBO0lBQ0YsTUFBTSxDQUFDLElBQUksQ0FBQyxPQUFPLENBQUE7QUFDckIsQ0FBQyxDQUFBIn0=

6
dist/smarthbs.plugins.d.ts vendored Normal file
View File

@ -0,0 +1,6 @@
import 'typings-global';
import * as handlebars from 'handlebars';
import * as smartfile from 'smartfile';
import * as smartq from 'smartq';
import * as path from 'path';
export { handlebars, smartfile, smartq, path };

12
dist/smarthbs.plugins.js vendored Normal file
View File

@ -0,0 +1,12 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
require("typings-global");
const handlebars = require("handlebars");
exports.handlebars = handlebars;
const smartfile = require("smartfile");
exports.smartfile = smartfile;
const smartq = require("smartq");
exports.smartq = smartq;
const path = require("path");
exports.path = path;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRoYnMucGx1Z2lucy5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL3NtYXJ0aGJzLnBsdWdpbnMudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7QUFBQSwwQkFBdUI7QUFDdkIseUNBQXdDO0FBTXRDLGdDQUFVO0FBTFosdUNBQXNDO0FBTXBDLDhCQUFTO0FBTFgsaUNBQWdDO0FBTTlCLHdCQUFNO0FBTFIsNkJBQTRCO0FBTTFCLG9CQUFJIn0=

5
dist/smarthbs.template.d.ts vendored Normal file
View File

@ -0,0 +1,5 @@
/// <reference types="handlebars" />
/**
* get a template for a file on disk
*/
export declare let getTemplateForFile: (filePathArg: string) => Promise<HandlebarsTemplateDelegate>;

19
dist/smarthbs.template.js vendored Normal file
View File

@ -0,0 +1,19 @@
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
const plugins = require("./smarthbs.plugins");
/**
* get a template for a file on disk
*/
exports.getTemplateForFile = (filePathArg) => __awaiter(this, void 0, void 0, function* () {
let filePathAbsolute = plugins.path.resolve(filePathArg);
return plugins.handlebars.compile(plugins.smartfile.fs.toStringSync(filePathAbsolute));
});
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRoYnMudGVtcGxhdGUuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9zbWFydGhicy50ZW1wbGF0ZS50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7Ozs7Ozs7O0FBQUEsOENBQTZDO0FBRTdDOztHQUVHO0FBQ1EsUUFBQSxrQkFBa0IsR0FBRyxDQUFPLFdBQW1CO0lBQ3hELElBQUksZ0JBQWdCLEdBQUcsT0FBTyxDQUFDLElBQUksQ0FBQyxPQUFPLENBQUMsV0FBVyxDQUFDLENBQUE7SUFDeEQsTUFBTSxDQUFDLE9BQU8sQ0FBQyxVQUFVLENBQUMsT0FBTyxDQUFDLE9BQU8sQ0FBQyxTQUFTLENBQUMsRUFBRSxDQUFDLFlBQVksQ0FBQyxnQkFBZ0IsQ0FBQyxDQUFDLENBQUE7QUFDeEYsQ0FBQyxDQUFBLENBQUEifQ==

View File

@ -1,54 +1,7 @@
import 'typings-global' import * as plugins from './smarthbs.plugins'
import * as handlebars from 'handlebars'
import * as smartfile from 'smartfile'
import * as smartq from 'smartq'
import * as path from 'path'
export type TTemplateStringType = 'filePath' | 'code' export type TTemplateStringType = 'filePath' | 'code'
/** export * from './smarthbs.compile'
* registers a directory of partials to make them available within handlebars compilation export * from './smarthbs.helpers'
*/ export * from './smarthbs.partials'
export let registerPartialDir = (dirPathArg: string) => { export * from './smarthbs.template'
let done = smartq.defer()
smartfile.fs.listFileTree(dirPathArg, '**/*.hbs').then(hbsFileArrayArg => {
for (let hbsFilePath of hbsFileArrayArg) {
let parsedPath = path.parse(hbsFilePath)
let hbsFileString = smartfile.fs.toStringSync(path.join(dirPathArg, hbsFilePath))
if (parsedPath.dir === '') {
parsedPath.name = '/' + parsedPath.name
}
let partialName = `partials${parsedPath.dir}${parsedPath.name}`
handlebars.registerPartial(partialName, hbsFileString)
done.resolve()
}
})
return done.promise
}
/**
* compiles a directory and outputs it
*/
export let compileDirectory = async (
originDirPathArg: string,
destinationDirPathArg: string,
dataFileNameArg: string
) => {
let hbsFilePathArray = smartfile.fs.listFilesSync(originDirPathArg, /.hbs/)
let data = smartfile.fs.toObjectSync(path.join(originDirPathArg, dataFileNameArg))
for (let hbsFilePath of hbsFilePathArray) {
let parsedPath = path.parse(hbsFilePath)
let hbsFileString = smartfile.fs.toStringSync(path.join(originDirPathArg, hbsFilePath))
let template = handlebars.compile(hbsFileString)
let output = template(data)
console.log('hi ' + output + ' hi')
smartfile.memory.toFsSync(output, path.join(destinationDirPathArg, parsedPath.name + '.html'))
}
}
/**
* get a template for a file on disk
*/
export let getTemplateForFile = async (filePathArg: string) => {
let filePathAbsolute = path.resolve(filePathArg)
return handlebars.compile(smartfile.fs.toStringSync(filePathAbsolute))
}

21
ts/smarthbs.compile.ts Normal file
View File

@ -0,0 +1,21 @@
import * as plugins from './smarthbs.plugins'
/**
* compiles a directory and outputs it
*/
export let compileDirectory = async (
originDirPathArg: string,
destinationDirPathArg: string,
dataFileNameArg: string
) => {
let hbsFilePathArray = plugins.smartfile.fs.listFilesSync(originDirPathArg, /.hbs/)
let data = plugins.smartfile.fs.toObjectSync(plugins.path.join(originDirPathArg, dataFileNameArg))
for (let hbsFilePath of hbsFilePathArray) {
let parsedPath = plugins.path.parse(hbsFilePath)
let hbsFileString = plugins.smartfile.fs.toStringSync(plugins.path.join(originDirPathArg, hbsFilePath))
let template = plugins.handlebars.compile(hbsFileString)
let output = template(data)
console.log('hi ' + output + ' hi')
plugins.smartfile.memory.toFsSync(output, plugins.path.join(destinationDirPathArg, parsedPath.name + '.html'))
}
}

4
ts/smarthbs.helpers.ts Normal file
View File

@ -0,0 +1,4 @@
import * as plugins from './smarthbs.plugins'
export let registerHelper = plugins.handlebars.registerHelper

21
ts/smarthbs.partials.ts Normal file
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
}

12
ts/smarthbs.plugins.ts Normal file
View File

@ -0,0 +1,12 @@
import 'typings-global'
import * as handlebars from 'handlebars'
import * as smartfile from 'smartfile'
import * as smartq from 'smartq'
import * as path from 'path'
export {
handlebars,
smartfile,
smartq,
path
}

9
ts/smarthbs.template.ts Normal file
View File

@ -0,0 +1,9 @@
import * as plugins from './smarthbs.plugins'
/**
* get a template for a file on disk
*/
export let getTemplateForFile = async (filePathArg: string) => {
let filePathAbsolute = plugins.path.resolve(filePathArg)
return plugins.handlebars.compile(plugins.smartfile.fs.toStringSync(filePathAbsolute))
}