Comparing version 1.0.1 to 1.0.2
{ | ||
"name": "kstpl", | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"description": "Ksike Template Engine", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -19,3 +19,3 @@ # KsTpl: Template Compilation Made Easy | ||
- [KsTpl](https://www.npmjs.com/package/kstpl) - Template Engine | ||
- [KsDoc](https://www.npmjs.com/package/ksdoc) - Document Engine | ||
- [KsDoc](https://www.npmjs.com/package/ksdocs) - Document Engine | ||
@@ -22,0 +22,0 @@ ## Driver |
@@ -150,2 +150,7 @@ const _path = require('path'); | ||
* @param {String} [options.close] | ||
* @param {String} [options.delimiter] | ||
* @param {String} [options.openDelimiter] | ||
* @param {String} [options.closeDelimiter] | ||
* @param {String} [options.escape] | ||
* @param {Boolean} [options.deep] | ||
* @returns {String} | ||
@@ -152,0 +157,0 @@ */ |
@@ -114,4 +114,46 @@ const Driver = require('../Driver'); | ||
} | ||
/* | ||
* @description Render method for versions previus 6.0.0 | ||
* @param {String} name | ||
* @param {Object} [data] | ||
* @param {String} [data.flow] | ||
* @param {Object} [options] | ||
* @param {String} [options.path] | ||
* @param {String} [options.ext] | ||
* @param {String} [options.flow] | ||
* @param {Array} [options.functions] | ||
*/ | ||
async renderV5(name, data = {}, options = {}) { | ||
const { path, filename } = this.getPath(name, options); | ||
if (!path) return ""; | ||
try { | ||
const version = require("twing/package")?.version[0]; | ||
if (parseInt(version) >= 6) { | ||
throw new Error("Twing version " + version + " is not supported"); | ||
} | ||
const { TwingEnvironment, TwingLoaderFilesystem, TwingFunction } = require("twing"); | ||
const loader = new TwingLoaderFilesystem(path); | ||
const twing = new TwingEnvironment(loader); | ||
if (options?.functions) { | ||
for (let i in options.functions) { | ||
if (options.functions[i] instanceof Function) { | ||
twing.addFunction(new TwingFunction(i, options.functions[i])); | ||
} | ||
} | ||
} | ||
return await twing.render(filename, data); | ||
} | ||
catch (error) { | ||
this.logger?.error({ | ||
flow: data?.flow || options?.flow, | ||
src: "util:TPLHandler:render", | ||
message: error?.message || error, | ||
data: { name, path, local: __dirname } | ||
}); | ||
return ""; | ||
} | ||
} | ||
} | ||
module.exports = Twing; |
@@ -106,3 +106,3 @@ /** | ||
catch (error) { | ||
this.log({ | ||
this.logger?.error({ | ||
src: "KsTpl:" + driver + ":" + action, | ||
@@ -126,3 +126,3 @@ error: { message: error?.message || error, stack: error?.stack }, | ||
catch (error) { | ||
this.log(error); | ||
this.logger?.error(error); | ||
return null; | ||
@@ -153,10 +153,2 @@ } | ||
/** | ||
* @description internal log handler | ||
*/ | ||
log() { | ||
this.logger?.log && this.logger.log(...arguments); | ||
return this; | ||
} | ||
/** | ||
* @description render | ||
@@ -220,7 +212,11 @@ * @param {String} [file] | ||
* @param {Object} [options] | ||
* @param {String} [options.driver] | ||
* @param {String} [options.flow] | ||
* @param {String} [options.open] | ||
* @param {String} [options.close] | ||
* @param {String} [options.delimiter] | ||
* @param {String} [options.openDelimiter] | ||
* @param {String} [options.closeDelimiter] | ||
* @param {String} [options.driver] | ||
* @param {String} [options.escape] | ||
* @param {Boolean} [options.deep] | ||
* @returns {String} | ||
@@ -227,0 +223,0 @@ */ |
@@ -32,3 +32,2 @@ declare const _exports: { | ||
get(driver?: string): any; | ||
log(...args: any[]): this; | ||
getDrvName(file?: string, options?: { | ||
@@ -53,7 +52,11 @@ path?: string; | ||
}, options?: { | ||
driver?: string; | ||
flow?: string; | ||
open?: string; | ||
close?: string; | ||
delimiter?: string; | ||
openDelimiter?: string; | ||
closeDelimiter?: string; | ||
driver?: string; | ||
escape?: string; | ||
deep?: boolean; | ||
}): string; | ||
@@ -60,0 +63,0 @@ save(content?: string, file?: string, option?: any): string; |
@@ -111,2 +111,7 @@ export = Driver; | ||
* @param {String} [options.close] | ||
* @param {String} [options.delimiter] | ||
* @param {String} [options.openDelimiter] | ||
* @param {String} [options.closeDelimiter] | ||
* @param {String} [options.escape] | ||
* @param {Boolean} [options.deep] | ||
* @returns {String} | ||
@@ -120,2 +125,7 @@ */ | ||
close?: string; | ||
delimiter?: string; | ||
openDelimiter?: string; | ||
closeDelimiter?: string; | ||
escape?: string; | ||
deep?: boolean; | ||
}): string; | ||
@@ -122,0 +132,0 @@ /** |
@@ -85,6 +85,2 @@ export = KsTpl; | ||
/** | ||
* @description internal log handler | ||
*/ | ||
log(...args: any[]): this; | ||
/** | ||
* @description render | ||
@@ -135,7 +131,11 @@ * @param {String} [file] | ||
* @param {Object} [options] | ||
* @param {String} [options.driver] | ||
* @param {String} [options.flow] | ||
* @param {String} [options.open] | ||
* @param {String} [options.close] | ||
* @param {String} [options.delimiter] | ||
* @param {String} [options.openDelimiter] | ||
* @param {String} [options.closeDelimiter] | ||
* @param {String} [options.driver] | ||
* @param {String} [options.escape] | ||
* @param {Boolean} [options.deep] | ||
* @returns {String} | ||
@@ -146,7 +146,11 @@ */ | ||
}, options?: { | ||
driver?: string; | ||
flow?: string; | ||
open?: string; | ||
close?: string; | ||
delimiter?: string; | ||
openDelimiter?: string; | ||
closeDelimiter?: string; | ||
driver?: string; | ||
escape?: string; | ||
deep?: boolean; | ||
}): string; | ||
@@ -153,0 +157,0 @@ /** |
108180
1733