smarthbs/dist/index.js

52 lines
4.8 KiB
JavaScript
Raw Normal View History

2017-02-19 03:12:17 +00:00
"use strict";
2017-02-26 01:08:25 +00:00
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());
});
};
2017-02-19 03:12:17 +00:00
require("typings-global");
const handlebars = require("handlebars");
const smartfile = require("smartfile");
const path = require("path");
2017-02-26 01:08:25 +00:00
/**
* registers a directory of partials to make them available within handlebars compilation
*/
2017-02-19 03:12:17 +00:00
exports.registerPartialDir = (dirPathArg) => {
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);
}
});
};
2017-02-26 01:08:25 +00:00
/**
* compiles a directory and outputs it
*/
exports.compileDirectory = (originDirPathArg, destinationDirPathArg, dataFileNameArg) => __awaiter(this, void 0, void 0, function* () {
2017-02-19 03:12:17 +00:00
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'));
}
2017-02-26 01:08:25 +00:00
});
/**
* 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,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7Ozs7Ozs7QUFBQSwwQkFBdUI7QUFDdkIseUNBQXdDO0FBQ3hDLHVDQUFzQztBQUN0Qyw2QkFBNEI7QUFHNUI7O0dBRUc7QUFDUSxRQUFBLGtCQUFrQixHQUFHLENBQUMsVUFBa0I7SUFDL0MsU0FBUyxDQUFDLEVBQUUsQ0FBQyxZQUFZLENBQUMsVUFBVSxFQUFFLFVBQVUsQ0FBQyxDQUFDLElBQUksQ0FBQyxlQUFlO1FBQ2xFLEdBQUcsQ0FBQyxDQUFDLElBQUksV0FBVyxJQUFJLGVBQWUsQ0FBQyxDQUFDLENBQUM7WUFDdEMsSUFBSSxVQUFVLEdBQUcsSUFBSSxDQUFDLEtBQUssQ0FBQyxXQUFXLENBQUMsQ0FBQTtZQUN4QyxJQUFJLGFBQWEsR0FBRyxTQUFTLENBQUMsRUFBRSxDQUFDLFlBQVksQ0FBQyxJQUFJLENBQUMsSUFBSSxDQUFDLFVBQVUsRUFBRSxXQUFXLENBQUMsQ0FBQyxDQUFBO1lBQ2pGLEVBQUUsQ0FBQyxDQUFDLFVBQVUsQ0FBQyxHQUFHLEtBQUssRUFBRSxDQUFDLENBQUMsQ0FBQztnQkFDeEIsVUFBVSxDQUFDLElBQUksR0FBRyxHQUFHLEdBQUcsVUFBVSxDQUFDLElBQUksQ0FBQTtZQUMzQyxDQUFDO1lBQ0QsSUFBSSxXQUFXLE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