@lwrjs/base-template-engine
Advanced tools
Comparing version 0.0.2-alpha1 to 0.0.2-alpha10
@@ -7,4 +7,11 @@ import templateEngine from './micro-template'; | ||
} | ||
export declare function templateMiddleware({ views, layouts, defaultLayout }: EngineConfig): any; | ||
interface LayoutContext { | ||
title: string; | ||
head_resources: string; | ||
body_resources: string; | ||
layout: string; | ||
} | ||
declare type MiddlewareFunction = <T extends LayoutContext>(filePath: string, context: Partial<T>, callback: Function) => void; | ||
export declare function templateMiddleware({ views, layouts, defaultLayout, }: EngineConfig): MiddlewareFunction; | ||
export { templateEngine }; | ||
//# sourceMappingURL=index.d.ts.map |
@@ -7,2 +7,3 @@ "use strict"; | ||
exports.templateEngine = exports.templateMiddleware = void 0; | ||
/* eslint-disable @typescript-eslint/no-unused-vars */ | ||
const micro_template_1 = __importDefault(require("./micro-template")); | ||
@@ -16,3 +17,3 @@ exports.templateEngine = micro_template_1.default; | ||
} | ||
function templateMiddleware({ views, layouts, defaultLayout = 'main' }) { | ||
function templateMiddleware({ views, layouts, defaultLayout = 'main', }) { | ||
return function (filePath, context, callback) { | ||
@@ -19,0 +20,0 @@ const { title = 'LWR', layout } = context; |
@@ -1,2 +0,2 @@ | ||
export default function template(template: any, data: any): string; | ||
export default function template(template: string, data: any): string; | ||
//# sourceMappingURL=micro-template.d.ts.map |
"use strict"; | ||
/* eslint-disable @typescript-eslint/no-explicit-any */ | ||
// Ported and inspired by from https://github.com/sindresorhus/pupa/blob/master/index.js | ||
// The semantics of double and triple brackets follow handlebars. | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
/* eslint-disable @typescript-eslint/no-explicit-any */ | ||
// Ported from https://github.com/sindresorhus/pupa/blob/master/index.js | ||
const escape_goat_1 = require("escape-goat"); | ||
@@ -13,2 +14,12 @@ function template(template, data) { | ||
} | ||
const triplebraceRegex = /{{{(.*?)}}}/g; | ||
if (triplebraceRegex.test(template)) { | ||
template = template.replace(triplebraceRegex, (_, key) => { | ||
let result = data; | ||
for (const property of key.split('.')) { | ||
result = result ? result[property] : ''; | ||
} | ||
return String(result); | ||
}); | ||
} | ||
const doubleBraceRegex = /{{(.*?)}}/g; | ||
@@ -24,12 +35,5 @@ if (doubleBraceRegex.test(template)) { | ||
} | ||
const braceRegex = /{(.*?)}/g; | ||
return template.replace(braceRegex, (_, key) => { | ||
let result = data; | ||
for (const property of key.split('.')) { | ||
result = result ? result[property] : ''; | ||
} | ||
return String(result); | ||
}); | ||
return template; | ||
} | ||
exports.default = template; | ||
//# sourceMappingURL=micro-template.js.map |
import { LwrGlobalConfig } from '@lwrjs/types'; | ||
import express from 'express'; | ||
import { templateEngine } from './engine/index'; | ||
export declare function registerEngine(app: express.Application, config: LwrGlobalConfig): void; | ||
export declare function render(data: string, context: any): string; | ||
export { templateEngine as render }; | ||
//# sourceMappingURL=index.d.ts.map |
@@ -5,5 +5,6 @@ "use strict"; | ||
const index_1 = require("./engine/index"); | ||
Object.defineProperty(exports, "render", { enumerable: true, get: function () { return index_1.templateEngine; } }); | ||
function registerEngine(app, config) { | ||
const viewsDir = config.application.views[0]; | ||
const layoutsDir = config.application.layouts[0]; | ||
const viewsDir = config.contentDir; | ||
const layoutsDir = config.layoutsDir; | ||
app.engine('html', index_1.templateMiddleware({ | ||
@@ -17,6 +18,2 @@ views: viewsDir, | ||
exports.registerEngine = registerEngine; | ||
function render(data, context) { | ||
return index_1.templateEngine(data, context); | ||
} | ||
exports.render = render; | ||
//# sourceMappingURL=index.js.map |
@@ -7,3 +7,12 @@ { | ||
}, | ||
"version": "0.0.2-alpha1", | ||
"version": "0.0.2-alpha10", | ||
"homepage": "https://lwr.dev/", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/salesforce/lwr.git", | ||
"directory": "packages/@lwrjs/base-template-engine" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/salesforce/lwr/issues" | ||
}, | ||
"types": "build/index.d.ts", | ||
@@ -18,3 +27,3 @@ "main": "build/index.js", | ||
}, | ||
"gitHead": "ae4583dba86a00596d3641f60144d8c1f39a0d78" | ||
"gitHead": "cb54d75e833b0ecb269a74ae40da0337a18846c1" | ||
} |
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
No website
QualityPackage does not have a website.
Found 1 instance in 1 package
6100
8
100
1
0