add postprocess

This commit is contained in:
Philipp Kunz 2017-05-31 23:59:39 +02:00
parent 0b14cca8cc
commit 02aaa042f3
8 changed files with 65 additions and 2 deletions

1
dist/index.d.ts vendored
View File

@ -6,3 +6,4 @@ import './smarthbs.helpers';
export * from './smarthbs.partials';
export * from './smarthbs.template';
export * from './smarthbs.variables';
export * from './smarthbs.postprocess';

3
dist/index.js vendored
View File

@ -10,4 +10,5 @@ require("./smarthbs.helpers");
__export(require("./smarthbs.partials"));
__export(require("./smarthbs.template"));
__export(require("./smarthbs.variables"));
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7OztBQUFBLDhDQUE2QztBQUdsQyxRQUFBLFVBQVUsR0FBRyxPQUFPLENBQUMsVUFBVSxDQUFBO0FBQzFDLHdDQUFrQztBQUNsQyw4QkFBMkI7QUFDM0IseUNBQW1DO0FBQ25DLHlDQUFtQztBQUNuQywwQ0FBb0MifQ==
__export(require("./smarthbs.postprocess"));
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7OztBQUFBLDhDQUE2QztBQUdsQyxRQUFBLFVBQVUsR0FBRyxPQUFPLENBQUMsVUFBVSxDQUFBO0FBQzFDLHdDQUFrQztBQUNsQyw4QkFBMkI7QUFDM0IseUNBQW1DO0FBQ25DLHlDQUFtQztBQUNuQywwQ0FBb0M7QUFDcEMsNENBQXNDIn0=

View File

@ -1,6 +1,10 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const plugins = require("./smarthbs.plugins");
/**
* Helper:
* Allows you to analyze a context
*/
plugins.handlebars.registerHelper('__analyze', (analyzeContext) => {
if (typeof analyzeContext === 'string') {
if (plugins.handlebars.partials[analyzeContext]) {
@ -13,6 +17,10 @@ plugins.handlebars.registerHelper('__analyze', (analyzeContext) => {
return 'analyzed';
}
});
/**
* Helper:
* logs all registered partials to console
*/
plugins.handlebars.registerHelper('__allPartialsLog', (analyzeContext) => {
console.log(plugins.handlebars.partials);
return 'analyzed';
@ -21,4 +29,4 @@ plugins.handlebars.registerHelper('__compile', (evaluationString, evaluationCont
let template = plugins.handlebars.compile(evaluationString);
return template(evaluationContext);
});
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRoYnMuaGVscGVycy5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL3NtYXJ0aGJzLmhlbHBlcnMudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7QUFBQSw4Q0FBNkM7QUFFN0MsT0FBTyxDQUFDLFVBQVUsQ0FBQyxjQUFjLENBQUMsV0FBVyxFQUFFLENBQUMsY0FBYztJQUM1RCxFQUFFLENBQUMsQ0FBQyxPQUFPLGNBQWMsS0FBSyxRQUFRLENBQUMsQ0FBQyxDQUFDO1FBQ3ZDLEVBQUUsQ0FBQyxDQUFDLE9BQU8sQ0FBQyxVQUFVLENBQUMsUUFBUSxDQUFDLGNBQWMsQ0FBQyxDQUFDLENBQUMsQ0FBQztZQUNoRCxPQUFPLENBQUMsU0FBUyxDQUFDLEdBQUcsQ0FBQyx3QkFBd0IsY0FBYyxrQkFBa0IsQ0FBQyxDQUFBO1lBQy9FLE9BQU8sQ0FBQyxHQUFHLENBQUMsT0FBTyxDQUFDLFVBQVUsQ0FBQyxRQUFRLENBQUMsY0FBYyxDQUFDLENBQUMsQ0FBQTtRQUMxRCxDQUFDO1FBQUMsSUFBSSxDQUFDLENBQUM7WUFDTixPQUFPLENBQUMsU0FBUyxDQUFDLEtBQUssQ0FBQyxlQUFlLGNBQWM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
* helpful when handlebars syntax is used by more than one tool in a build chain
*/
export declare let postprocess: (stringArg: string) => Promise<string>;

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

@ -0,0 +1,23 @@
"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 });
let safeSyntaxBeginRegex = /{-{/g;
let safeSyntaxEndRegex = /}-}/g;
/**
* allows you to keep handlebars in place across multiple iterations
* helpful when handlebars syntax is used by more than one tool in a build chain
*/
exports.postprocess = (stringArg) => __awaiter(this, void 0, void 0, function* () {
let processedString = stringArg;
processedString = processedString.replace(safeSyntaxBeginRegex, '{{');
processedString = processedString.replace(safeSyntaxEndRegex, '}}');
return processedString;
});
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRoYnMucG9zdHByb2Nlc3MuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9zbWFydGhicy5wb3N0cHJvY2Vzcy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7Ozs7Ozs7O0FBR0EsSUFBSSxvQkFBb0IsR0FBRyxNQUFNLENBQUE7QUFDakMsSUFBSSxrQkFBa0IsR0FBRyxNQUFNLENBQUE7QUFFL0I7OztHQUdHO0FBQ1EsUUFBQSxXQUFXLEdBQUcsQ0FBTyxTQUFpQjtJQUMvQyxJQUFJLGVBQWUsR0FBRyxTQUFTLENBQUE7SUFDL0IsZUFBZSxHQUFHLGVBQWUsQ0FBQyxPQUFPLENBQUMsb0JBQW9CLEVBQUUsSUFBSSxDQUFDLENBQUE7SUFDckUsZUFBZSxHQUFHLGVBQWUsQ0FBQyxPQUFPLENBQUMsa0JBQWtCLEVBQUUsSUFBSSxDQUFDLENBQUE7SUFDbkUsTUFBTSxDQUFDLGVBQWUsQ0FBQTtBQUN4QixDQUFDLENBQUEsQ0FBQSJ9

View File

@ -7,3 +7,4 @@ import './smarthbs.helpers'
export * from './smarthbs.partials'
export * from './smarthbs.template'
export * from './smarthbs.variables'
export * from './smarthbs.postprocess'

View File

@ -1,5 +1,9 @@
import * as plugins from './smarthbs.plugins'
/**
* Helper:
* Allows you to analyze a context
*/
plugins.handlebars.registerHelper('__analyze', (analyzeContext) => {
if (typeof analyzeContext === 'string') {
if (plugins.handlebars.partials[analyzeContext]) {
@ -12,6 +16,10 @@ plugins.handlebars.registerHelper('__analyze', (analyzeContext) => {
}
})
/**
* Helper:
* logs all registered partials to console
*/
plugins.handlebars.registerHelper('__allPartialsLog', (analyzeContext) => {
console.log(plugins.handlebars.partials)
return 'analyzed'

View File

@ -0,0 +1,16 @@
import * as plugins from './smarthbs.plugins'
let safeSyntaxBeginRegex = /{-{/g
let safeSyntaxEndRegex = /}-}/g
/**
* allows you to keep handlebars in place across multiple iterations
* helpful when handlebars syntax is used by more than one tool in a build chain
*/
export let postprocess = async (stringArg: string): Promise<string> => {
let processedString = stringArg
processedString = processedString.replace(safeSyntaxBeginRegex, '{{')
processedString = processedString.replace(safeSyntaxEndRegex, '}}')
return processedString
}