Comparing version 4.0.1 to 4.0.2
@@ -24,2 +24,6 @@ import { LoaderTemplate, CacheManagerContract } from '../Contracts'; | ||
set(absPath: string, payload: LoaderTemplate): void; | ||
/** | ||
* Delete template from the compiled cache | ||
*/ | ||
delete(absPath: string): void; | ||
} |
@@ -47,3 +47,12 @@ "use strict"; | ||
} | ||
/** | ||
* Delete template from the compiled cache | ||
*/ | ||
delete(absPath) { | ||
if (!this.enabled) { | ||
return; | ||
} | ||
this.cacheStore.delete(absPath); | ||
} | ||
} | ||
exports.CacheManager = CacheManager; |
@@ -57,2 +57,6 @@ import { Parser } from 'edge-parser'; | ||
/** | ||
* Tokenize a raw template | ||
*/ | ||
tokenizeRaw(contents: string, templatePath?: string, parser?: Parser): Token[]; | ||
/** | ||
* Compiles the template contents to string. The output is same as the `edge-parser`, | ||
@@ -67,2 +71,12 @@ * it's just that the compiler uses the loader to load the templates and also | ||
compile(templatePath: string, localVariables?: string[]): LoaderTemplate; | ||
/** | ||
* Compiles the template contents to string. The output is same as the `edge-parser`, | ||
* it's just that the compiler uses the loader to load the templates and also | ||
* handles layouts. | ||
* | ||
* ```js | ||
* compiler.compile('welcome') | ||
* ``` | ||
*/ | ||
compileRaw(contents: string, templatePath?: string): LoaderTemplate; | ||
} |
@@ -182,6 +182,12 @@ "use strict"; | ||
let { template } = this.loader.resolve(absPath); | ||
template = this.processor.executeRaw({ path: absPath, raw: template }); | ||
return this.templateContentToTokens(template, parser || this.getParserFor(absPath), absPath); | ||
return this.tokenizeRaw(template, absPath, parser); | ||
} | ||
/** | ||
* Tokenize a raw template | ||
*/ | ||
tokenizeRaw(contents, templatePath = 'eval.edge', parser) { | ||
contents = this.processor.executeRaw({ path: templatePath, raw: contents }); | ||
return this.templateContentToTokens(contents, parser || this.getParserFor(templatePath), templatePath); | ||
} | ||
/** | ||
* Compiles the template contents to string. The output is same as the `edge-parser`, | ||
@@ -219,3 +225,23 @@ * it's just that the compiler uses the loader to load the templates and also | ||
} | ||
/** | ||
* Compiles the template contents to string. The output is same as the `edge-parser`, | ||
* it's just that the compiler uses the loader to load the templates and also | ||
* handles layouts. | ||
* | ||
* ```js | ||
* compiler.compile('welcome') | ||
* ``` | ||
*/ | ||
compileRaw(contents, templatePath = 'eval.edge') { | ||
const parser = this.getParserFor(templatePath); | ||
const buffer = this.getBufferFor(templatePath); | ||
const templateTokens = this.tokenizeRaw(contents, templatePath, parser); | ||
templateTokens.forEach((token) => parser.processToken(token, buffer)); | ||
const template = this.processor.executeCompiled({ | ||
path: templatePath, | ||
compiled: buffer.flush(), | ||
}); | ||
return { template }; | ||
} | ||
} | ||
exports.Compiler = Compiler; |
@@ -54,2 +54,6 @@ /** | ||
register(templatePath: string, contents: LoaderTemplate): void; | ||
/** | ||
* Remove the pre-registered template | ||
*/ | ||
remove(templatePath: string): void; | ||
} | ||
@@ -84,2 +88,3 @@ /** | ||
has(templatePath: string): boolean; | ||
delete(templatePath: string): void; | ||
} | ||
@@ -102,2 +107,10 @@ /** | ||
tokenize(templatePath: string, parser?: Parser): Token[]; | ||
/** | ||
* Compile the raw string as a template | ||
*/ | ||
compileRaw(contents: string, templatePath?: string): LoaderTemplate; | ||
/** | ||
* Tokenize the raw string as a template | ||
*/ | ||
tokenizeRaw(contents: string, templatePath?: string, parser?: Parser): Token[]; | ||
} | ||
@@ -183,2 +196,3 @@ /** | ||
render<T extends Promise<string> | string>(template: string, state: any): T; | ||
renderRaw<T extends Promise<string> | string>(contents: string, state: any, templatePath?: string): T; | ||
/** | ||
@@ -205,2 +219,3 @@ * Escape input | ||
render(templatePath: string, state?: any): string; | ||
renderRaw(contents: string, state?: any, templatePath?: string): string; | ||
/** | ||
@@ -210,2 +225,3 @@ * Render a template asynchronously | ||
renderAsync(templatePath: string, state?: any): Promise<string>; | ||
renderRawAsync(contents: string, state?: any, templatePath?: string): Promise<string>; | ||
} | ||
@@ -312,2 +328,6 @@ /** | ||
/** | ||
* Remove the template registered using the "registerTemplate" method | ||
*/ | ||
removeTemplate(templatePath: string): this; | ||
/** | ||
* Register a global value | ||
@@ -337,2 +357,3 @@ */ | ||
render(templatePath: string, state?: any): string; | ||
renderRaw(contents: string, state?: any, templatePath?: string): string; | ||
/** | ||
@@ -342,2 +363,3 @@ * Render a template asynchronously | ||
renderAsync(templatePath: string, state?: any): Promise<string>; | ||
renderRawAsync(contents: string, state?: any, templatePath?: string): Promise<string>; | ||
} | ||
@@ -344,0 +366,0 @@ /** |
@@ -130,2 +130,6 @@ import { Compiler } from '../Compiler'; | ||
/** | ||
* Remove the template registered using the "registerTemplate" method | ||
*/ | ||
removeTemplate(templatePath: string): this; | ||
/** | ||
* Returns a new instance of edge. The instance | ||
@@ -152,2 +156,18 @@ * can be used to define locals. | ||
/** | ||
* Render a template with optional state | ||
* | ||
* ```ts | ||
* edge.render('welcome', { greeting: 'Hello world' }) | ||
* ``` | ||
*/ | ||
renderRaw(contents: string, state?: any, templatePath?: string): string; | ||
/** | ||
* Render a template asynchronously with optional state | ||
* | ||
* ```ts | ||
* edge.render('welcome', { greeting: 'Hello world' }) | ||
* ``` | ||
*/ | ||
renderRawAsync(templatePath: string, state?: any): Promise<string>; | ||
/** | ||
* Share locals with the current view context. | ||
@@ -154,0 +174,0 @@ * |
@@ -209,2 +209,11 @@ "use strict"; | ||
/** | ||
* Remove the template registered using the "registerTemplate" method | ||
*/ | ||
removeTemplate(templatePath) { | ||
this.loader.remove(templatePath); | ||
this.compiler.cacheManager.delete(templatePath); | ||
this.asyncCompiler.cacheManager.delete(templatePath); | ||
return this; | ||
} | ||
/** | ||
* Returns a new instance of edge. The instance | ||
@@ -238,2 +247,22 @@ * can be used to define locals. | ||
/** | ||
* Render a template with optional state | ||
* | ||
* ```ts | ||
* edge.render('welcome', { greeting: 'Hello world' }) | ||
* ``` | ||
*/ | ||
renderRaw(contents, state, templatePath) { | ||
return this.getRenderer().renderRaw(contents, state, templatePath); | ||
} | ||
/** | ||
* Render a template asynchronously with optional state | ||
* | ||
* ```ts | ||
* edge.render('welcome', { greeting: 'Hello world' }) | ||
* ``` | ||
*/ | ||
renderRawAsync(templatePath, state) { | ||
return this.getRenderer().renderRawAsync(templatePath, state); | ||
} | ||
/** | ||
* Share locals with the current view context. | ||
@@ -240,0 +269,0 @@ * |
@@ -143,2 +143,6 @@ /** | ||
register(templatePath: string, contents: LoaderTemplate): void; | ||
/** | ||
* Remove registered template | ||
*/ | ||
remove(templatePath: string): void; | ||
} |
@@ -240,3 +240,9 @@ "use strict"; | ||
} | ||
/** | ||
* Remove registered template | ||
*/ | ||
remove(templatePath) { | ||
this.preRegistered.delete(templatePath); | ||
} | ||
} | ||
exports.Loader = Loader; |
@@ -26,2 +26,10 @@ import { Processor } from '../Processor'; | ||
renderAsync(templatePath: string, state?: any): Promise<string>; | ||
/** | ||
* Render the template from a raw string | ||
*/ | ||
renderRaw(contents: string, state?: any, templatePath?: string): string; | ||
/** | ||
* Render the template from a raw string | ||
*/ | ||
renderRawAsync(contents: string, state?: any, templatePath?: string): Promise<string>; | ||
} |
@@ -45,3 +45,15 @@ "use strict"; | ||
} | ||
/** | ||
* Render the template from a raw string | ||
*/ | ||
renderRaw(contents, state = {}, templatePath) { | ||
return new Template_1.Template(this.compiler, this.globals, this.locals, this.processor).renderRaw(contents, state, templatePath); | ||
} | ||
/** | ||
* Render the template from a raw string | ||
*/ | ||
async renderRawAsync(contents, state = {}, templatePath) { | ||
return new Template_1.Template(this.asyncCompiler, this.globals, this.locals, this.processor).renderRaw(contents, state, templatePath); | ||
} | ||
} | ||
exports.EdgeRenderer = EdgeRenderer; |
@@ -41,2 +41,6 @@ import { Macroable } from 'macroable'; | ||
/** | ||
* Render a compiled template with state | ||
*/ | ||
private renderCompiled; | ||
/** | ||
* Render a partial | ||
@@ -84,2 +88,10 @@ * | ||
/** | ||
* Render template from a raw string | ||
* | ||
* ```js | ||
* template.renderRaw('Hello {{ username }}', { username: 'virk' }) | ||
* ``` | ||
*/ | ||
renderRaw<T extends Promise<string> | string>(contents: string, state: any, templatePath?: string): T; | ||
/** | ||
* Escapes the value to be HTML safe. Only strings are escaped | ||
@@ -86,0 +98,0 @@ * and rest all values will be returned as it is. |
@@ -57,2 +57,20 @@ "use strict"; | ||
/** | ||
* Render a compiled template with state | ||
*/ | ||
renderCompiled(compiledTemplate, state) { | ||
const templateState = Object.assign({}, this.sharedState, state); | ||
const $context = {}; | ||
/** | ||
* Process template as a promise. | ||
*/ | ||
if (this.compiler.async) { | ||
return this.wrapToFunction(compiledTemplate)(this, templateState, $context).then((output) => { | ||
output = this.trimTopBottomNewLines(output); | ||
return this.processor.executeOutput({ output, template: this }); | ||
}); | ||
} | ||
const output = this.trimTopBottomNewLines(this.wrapToFunction(compiledTemplate)(this, templateState, $context)); | ||
return this.processor.executeOutput({ output, template: this }); | ||
} | ||
/** | ||
* Render a partial | ||
@@ -104,17 +122,16 @@ * | ||
let { template: compiledTemplate } = this.compiler.compile(template); | ||
const templateState = Object.assign({}, this.sharedState, state); | ||
const $context = {}; | ||
/** | ||
* Process template as a promise. | ||
*/ | ||
if (this.compiler.async) { | ||
return this.wrapToFunction(compiledTemplate)(this, templateState, $context).then((output) => { | ||
output = this.trimTopBottomNewLines(output); | ||
return this.processor.executeOutput({ output, template: this }); | ||
}); | ||
} | ||
const output = this.trimTopBottomNewLines(this.wrapToFunction(compiledTemplate)(this, templateState, $context)); | ||
return this.processor.executeOutput({ output, template: this }); | ||
return this.renderCompiled(compiledTemplate, state); | ||
} | ||
/** | ||
* Render template from a raw string | ||
* | ||
* ```js | ||
* template.renderRaw('Hello {{ username }}', { username: 'virk' }) | ||
* ``` | ||
*/ | ||
renderRaw(contents, state, templatePath) { | ||
let { template: compiledTemplate } = this.compiler.compileRaw(contents, templatePath); | ||
return this.renderCompiled(compiledTemplate, state); | ||
} | ||
/** | ||
* Escapes the value to be HTML safe. Only strings are escaped | ||
@@ -121,0 +138,0 @@ * and rest all values will be returned as it is. |
{ | ||
"name": "edge.js", | ||
"version": "4.0.1", | ||
"version": "4.0.2", | ||
"description": "Template engine", | ||
@@ -41,3 +41,3 @@ "main": "build/index.js", | ||
"@poppinss/dev-utils": "^1.1.0", | ||
"@types/node": "^14.14.28", | ||
"@types/node": "^14.14.31", | ||
"commitizen": "^4.2.3", | ||
@@ -49,3 +49,3 @@ "cz-conventional-changelog": "^3.3.0", | ||
"eslint": "^7.20.0", | ||
"eslint-config-prettier": "^7.2.0", | ||
"eslint-config-prettier": "^8.0.0", | ||
"eslint-plugin-adonis": "^1.2.1", | ||
@@ -57,3 +57,3 @@ "eslint-plugin-prettier": "^3.3.1", | ||
"js-stringify": "^1.0.2", | ||
"mrm": "^2.5.18", | ||
"mrm": "^2.5.19", | ||
"np": "^7.4.0", | ||
@@ -79,5 +79,5 @@ "prettier": "^2.2.1", | ||
"@poppinss/utils": "^3.0.3", | ||
"edge-error": "^1.0.5", | ||
"edge-lexer": "^4.0.0", | ||
"edge-parser": "^8.0.0", | ||
"edge-error": "^2.0.0", | ||
"edge-lexer": "^4.0.1", | ||
"edge-parser": "^8.0.1", | ||
"macroable": "^5.1.0", | ||
@@ -84,0 +84,0 @@ "stringify-attributes": "^2.0.0" |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
133754
3802
- Removededge-error@1.0.5(transitive)
Updatededge-error@^2.0.0
Updatededge-lexer@^4.0.1
Updatededge-parser@^8.0.1