diff --git a/.gitignore b/.gitignore index 2f812b0..771a8fd 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,5 @@ node_modules/ coverage/ public/ pages/ +test/testresult/ .nogit/ diff --git a/dist/smarthbs.helpers.js b/dist/smarthbs.helpers.js index cad126f..80401c5 100644 --- a/dist/smarthbs.helpers.js +++ b/dist/smarthbs.helpers.js @@ -1,8 +1,24 @@ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const plugins = require("./smarthbs.plugins"); +plugins.handlebars.registerHelper('__analyze', (analyzeContext) => { + if (typeof analyzeContext === 'string') { + if (plugins.handlebars.partials[analyzeContext]) { + plugins.beautylog.log(`The analyzed partial ${analyzeContext} looks like this`); + console.log(plugins.handlebars.partials[analyzeContext]); + } + else { + plugins.beautylog.error(`The Partial ${analyzeContext} cannot be found`); + } + return 'analyzed'; + } +}); +plugins.handlebars.registerHelper('__allPartialsLog', (analyzeContext) => { + console.log(plugins.handlebars.partials); + return 'analyzed'; +}); plugins.handlebars.registerHelper('__compile', (evaluationString, evaluationContext) => { let template = plugins.handlebars.compile(evaluationString); return template(evaluationContext); }); -//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRoYnMuaGVscGVycy5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL3NtYXJ0aGJzLmhlbHBlcnMudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7QUFBQSw4Q0FBNkM7QUFFN0MsT0FBTyxDQUFDLFVBQVUsQ0FBQyxjQUFjLENBQUMsV0FBVyxFQUFFLENBQUMsZ0JBQWdCLEVBQUUsaUJBQWlCO0lBQ2pGLElBQUksUUFBUSxHQUFHLE9BQU8sQ0FBQyxVQUFVLENBQUMsT0FBTyxDQUFDLGdCQUFnQixDQUFDLENBQUE7SUFDM0QsTUFBTSxDQUFDLFFBQVEsQ0FBQyxpQkFBaUIsQ0FBQyxDQUFBO0FBQ3BDLENBQ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0FBQyxDQUFBO0lBQ3hDLE1BQU0sQ0FBQyxVQUFVLENBQUE7QUFDbkIsQ0FBQyxDQUFDLENBQUE7QUFFRixPQUFPLENBQUMsVUFBVSxDQUFDLGNBQWMsQ0FBQyxXQUFXLEVBQUUsQ0FBQyxnQkFBZ0IsRUFBRSxpQkFBaUI7SUFDakYsSUFBSSxRQUFRLEdBQUcsT0FBTyxDQUFDLFVBQVUsQ0FBQyxPQUFPLENBQUMsZ0JBQWdCLENBQUMsQ0FBQTtJQUMzRCxNQUFNLENBQUMsUUFBUSxDQUFDLGlCQUFpQixDQUFDLENBQUE7QUFDcEMsQ0FBQyxDQUFDLENBQUEifQ== \ No newline at end of file diff --git a/dist/smarthbs.partials.js b/dist/smarthbs.partials.js index c317a8c..ab9dd7f 100644 --- a/dist/smarthbs.partials.js +++ b/dist/smarthbs.partials.js @@ -10,14 +10,17 @@ exports.registerPartialDir = (dirPathArg) => { 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; + if (parsedPath.dir === '/') { + parsedPath.dir = ''; } - let partialName = `partials${parsedPath.dir}${parsedPath.name}`; + if (parsedPath.dir !== '') { + parsedPath.dir = parsedPath.dir + '/'; + } + let partialName = `partials/${parsedPath.dir}${parsedPath.name}`; plugins.handlebars.registerPartial(partialName, hbsFileString); done.resolve(); } }); return done.promise; }; -//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRoYnMucGFydGlhbHMuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9zbWFydGhicy5wYXJ0aWFscy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOztBQUFBLDhDQUE2QztBQUU3Qzs7R0FFRztBQUNRLFFBQUEsa0JBQWtCLEdBQUcsQ0F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BRyxDQUFBO1lBQ3ZDLENBQUM7WUFDRCxJQUFJLFdBQVcsR0FBRyxZQUFZLFVBQVUsQ0FBQyxHQUFHLEdBQUcsVUFBVSxDQUFDLElBQUksRUFBRSxDQUFBO1lBQ2hFLE9BQU8sQ0FBQyxVQUFVLENBQUMsZUFBZSxDQUFDLFdBQVcsRUFBRSxhQUFhLENBQUMsQ0FBQTtZQUM5RCxJQUFJLENBQUMsT0FBTyxFQUFFLENBQUE7UUFDaEIsQ0FBQztJQUNILENBQUMsQ0FBQyxDQUFBO0lBQ0YsTUFBTSxDQUFDLElBQUksQ0FBQyxPQUFPLENBQUE7QUFDckIsQ0FBQyxDQUFBIn0= \ No newline at end of file diff --git a/dist/smarthbs.plugins.d.ts b/dist/smarthbs.plugins.d.ts index 371b468..63dba8e 100644 --- a/dist/smarthbs.plugins.d.ts +++ b/dist/smarthbs.plugins.d.ts @@ -1,7 +1,8 @@ import 'typings-global'; +import * as beautylog from 'beautylog'; import * as handlebars from 'handlebars'; import * as lodash from 'lodash'; import * as path from 'path'; import * as smartfile from 'smartfile'; import * as smartq from 'smartq'; -export { handlebars, lodash, path, smartfile, smartq }; +export { beautylog, handlebars, lodash, path, smartfile, smartq }; diff --git a/dist/smarthbs.plugins.js b/dist/smarthbs.plugins.js index a398d54..aa8e577 100644 --- a/dist/smarthbs.plugins.js +++ b/dist/smarthbs.plugins.js @@ -1,6 +1,8 @@ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); require("typings-global"); +const beautylog = require("beautylog"); +exports.beautylog = beautylog; const handlebars = require("handlebars"); exports.handlebars = handlebars; const lodash = require("lodash"); @@ -11,4 +13,4 @@ const smartfile = require("smartfile"); exports.smartfile = smartfile; const smartq = require("smartq"); exports.smartq = smartq; -//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRoYnMucGx1Z2lucy5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL3NtYXJ0aGJzLnBsdWdpbnMudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7QUFBQSwwQkFBdUI7QUFDdkIseUNBQXdDO0FBT3RDLGdDQUFVO0FBTlosaUNBQWdDO0FBTzlCLHdCQUFNO0FBTlIsNkJBQTRCO0FBTzFCLG9CQUFJO0FBTk4sdUNBQXNDO0FBT3BDLDhCQUFTO0FBTlgsaUNBQWdDO0FBTzlCLHdCQUFNIn0= \ No newline at end of file +//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRoYnMucGx1Z2lucy5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL3NtYXJ0aGJzLnBsdWdpbnMudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7QUFBQSwwQkFBdUI7QUFDdkIsdUNBQXNDO0FBUXBDLDhCQUFTO0FBUFgseUNBQXdDO0FBUXRDLGdDQUFVO0FBUFosaUNBQWdDO0FBUTlCLHdCQUFNO0FBUFIsNkJBQTRCO0FBUTFCLG9CQUFJO0FBUE4sdUNBQXNDO0FBUXBDLDhCQUFTO0FBUFgsaUNBQWdDO0FBUTlCLHdCQUFNIn0= \ No newline at end of file diff --git a/package.json b/package.json index 05eae08..cb40576 100644 --- a/package.json +++ b/package.json @@ -22,14 +22,15 @@ "homepage": "https://gitlab.com/pkunz/smarthbs#README", "dependencies": { "@types/handlebars": "^4.0.32", - "@types/lodash": "^4.14.63", - "handlebars": "^4.0.7", + "@types/lodash": "^4.14.64", + "beautylog": "^6.1.10", + "handlebars": "^4.0.8", "lodash": "^4.17.4", - "smartfile": "^4.2.9", + "smartfile": "^4.2.11", "smartq": "^1.1.1", "typings-global": "^1.0.16" }, "devDependencies": { - "tapbundle": "^1.0.10" + "tapbundle": "^1.0.12" } } diff --git a/test/hbs_testfiles/index.hbs b/test/hbs_testfiles/index.hbs index 7b83553..cc2cbcd 100644 --- a/test/hbs_testfiles/index.hbs +++ b/test/hbs_testfiles/index.hbs @@ -1 +1,2 @@ -{{> partials/header}} \ No newline at end of file +{{> partials/header}} +{{__analyze 'partials/header'}} \ No newline at end of file diff --git a/test/hbs_testfiles/index2.hbs b/test/hbs_testfiles/index2.hbs new file mode 100644 index 0000000..8205a31 --- /dev/null +++ b/test/hbs_testfiles/index2.hbs @@ -0,0 +1 @@ +A second hbs file! \ No newline at end of file diff --git a/test/hbs_testfiles/partials/footer.hbs b/test/hbs_testfiles/partials/footer.hbs index e69de29..0099b5b 100644 --- a/test/hbs_testfiles/partials/footer.hbs +++ b/test/hbs_testfiles/partials/footer.hbs @@ -0,0 +1 @@ +this is a footer \ No newline at end of file diff --git a/test/test.ts b/test/test.ts index 408d4b7..6f32fbd 100644 --- a/test/test.ts +++ b/test/test.ts @@ -5,6 +5,7 @@ import * as path from 'path' let testHbsDir = path.join(__dirname, 'hbs_testfiles') let testPartialDir = path.join(testHbsDir, 'partials') let testResultDir = path.join(__dirname, 'testresult') + tap.test('smarthbs -> should create partials', async () => { await smarthbs.registerPartialDir(testPartialDir) }) diff --git a/test/testresult/index.html b/test/testresult/index.html deleted file mode 100644 index abbb30c..0000000 --- a/test/testresult/index.html +++ /dev/null @@ -1 +0,0 @@ -
\ No newline at end of file diff --git a/ts/smarthbs.helpers.ts b/ts/smarthbs.helpers.ts index 2c3d6aa..6741b6d 100644 --- a/ts/smarthbs.helpers.ts +++ b/ts/smarthbs.helpers.ts @@ -1,8 +1,24 @@ import * as plugins from './smarthbs.plugins' +plugins.handlebars.registerHelper('__analyze', (analyzeContext) => { + if (typeof analyzeContext === 'string') { + if (plugins.handlebars.partials[analyzeContext]) { + plugins.beautylog.log(`The analyzed partial ${analyzeContext} looks like this`) + console.log(plugins.handlebars.partials[analyzeContext]) + } else { + plugins.beautylog.error(`The Partial ${analyzeContext} cannot be found`) + } + return 'analyzed' + } +}) + +plugins.handlebars.registerHelper('__allPartialsLog', (analyzeContext) => { + console.log(plugins.handlebars.partials) + return 'analyzed' +}) + plugins.handlebars.registerHelper('__compile', (evaluationString, evaluationContext) => { let template = plugins.handlebars.compile(evaluationString) return template(evaluationContext) }) - diff --git a/ts/smarthbs.partials.ts b/ts/smarthbs.partials.ts index 4a55900..9fc13b4 100644 --- a/ts/smarthbs.partials.ts +++ b/ts/smarthbs.partials.ts @@ -9,10 +9,13 @@ export let registerPartialDir = (dirPathArg: string): Promise