edge.js
Advanced tools
Comparing version 3.3.0 to 3.4.0
@@ -111,3 +111,3 @@ "use strict"; | ||
templateContentToTokens(content, parser, absPath) { | ||
let templateTokens = parser.tokenize(content, absPath); | ||
let templateTokens = parser.tokenize(content, absPath, (line) => this.processor.executeLine(line)); | ||
const firstToken = templateTokens[0]; | ||
@@ -114,0 +114,0 @@ /** |
@@ -145,5 +145,6 @@ /** | ||
*/ | ||
export interface EdgeContract extends ProcessorContract { | ||
export interface EdgeContract { | ||
loader: LoaderContract; | ||
compiler: CompilerContract; | ||
processor: ProcessorContract; | ||
GLOBALS: { | ||
@@ -150,0 +151,0 @@ [key: string]: any; |
import { Compiler } from '../Compiler'; | ||
import { TagContract, EdgeOptions, EdgeContract, LoaderTemplate, TemplateContract, EdgeRendererContract } from '../Contracts'; | ||
import { Processor } from '../Processor'; | ||
import { TagContract, EdgeOptions, EdgeContract, LoaderTemplate, EdgeRendererContract } from '../Contracts'; | ||
/** | ||
@@ -9,6 +10,2 @@ * Exposes the API to render templates, register custom tags and globals | ||
/** | ||
* Reference to the registered processor handlers | ||
*/ | ||
private processor; | ||
/** | ||
* An array of registered plugins | ||
@@ -18,2 +15,6 @@ */ | ||
/** | ||
* Reference to the registered processor handlers | ||
*/ | ||
processor: Processor; | ||
/** | ||
* Globals are shared with all rendered templates | ||
@@ -118,18 +119,2 @@ */ | ||
/** | ||
* Define processor functions to modify the output of templates | ||
* at different stages | ||
*/ | ||
process(event: 'raw', handler: (data: { | ||
raw: string; | ||
path: string; | ||
}) => string | void): this; | ||
process(event: 'compiled', handler: (data: { | ||
compiled: string; | ||
path: string; | ||
}) => string | void): this; | ||
process(event: 'output', handler: (data: { | ||
output: string; | ||
template: TemplateContract; | ||
}) => string | void): this; | ||
/** | ||
* Returns a new instance of edge. The instance | ||
@@ -136,0 +121,0 @@ * can be used to define locals. |
@@ -44,2 +44,6 @@ "use strict"; | ||
/** | ||
* An array of registered plugins | ||
*/ | ||
this.plugins = []; | ||
/** | ||
* Reference to the registered processor handlers | ||
@@ -49,6 +53,2 @@ */ | ||
/** | ||
* An array of registered plugins | ||
*/ | ||
this.plugins = []; | ||
/** | ||
* Globals are shared with all rendered templates | ||
@@ -180,6 +180,2 @@ */ | ||
} | ||
process(event, handler) { | ||
this.processor.process(event, handler); | ||
return this; | ||
} | ||
/** | ||
@@ -186,0 +182,0 @@ * Returns a new instance of edge. The instance |
@@ -9,2 +9,6 @@ import { ProcessorContract, TemplateContract } from '../Contracts'; | ||
/** | ||
* Execute line handler | ||
*/ | ||
executeLine(line: string): string; | ||
/** | ||
* Execute raw handlers | ||
@@ -37,2 +41,3 @@ */ | ||
}) => string | void): this; | ||
process(event: 'line', handler: (line: string) => string | void): this; | ||
process(event: 'compiled', handler: (data: { | ||
@@ -39,0 +44,0 @@ compiled: string; |
@@ -21,2 +21,18 @@ "use strict"; | ||
/** | ||
* Execute line handler | ||
*/ | ||
executeLine(line) { | ||
const handlers = this.handlers.get('line'); | ||
if (!handlers) { | ||
return line; | ||
} | ||
handlers.forEach((handler) => { | ||
const output = handler(line); | ||
if (output !== undefined) { | ||
line = output; | ||
} | ||
}); | ||
return line; | ||
} | ||
/** | ||
* Execute raw handlers | ||
@@ -23,0 +39,0 @@ */ |
{ | ||
"name": "edge.js", | ||
"version": "3.3.0", | ||
"version": "3.4.0", | ||
"description": "Template engine", | ||
@@ -5,0 +5,0 @@ "main": "build/index.js", |
123887
3463