@atjson/renderer-hir
Advanced tools
Comparing version 0.11.9 to 0.12.0
@@ -6,2 +6,10 @@ # Change Log | ||
## [0.12.0](https://github.com/CondeNast-Copilot/atjson/compare/@atjson/renderer-hir@0.11.9...@atjson/renderer-hir@0.12.0) (2019-01-24) | ||
**Note:** Version bump only for package @atjson/renderer-hir | ||
## [0.11.9](https://github.com/CondeNast-Copilot/atjson/compare/@atjson/renderer-hir@0.11.8...@atjson/renderer-hir@0.11.9) (2019-01-14) | ||
@@ -8,0 +16,0 @@ |
import Document, { Annotation } from '@atjson/document'; | ||
import { HIR } from '@atjson/hir'; | ||
export declare function escapeHTML(text: string): string; | ||
@@ -9,8 +8,9 @@ export interface Context { | ||
children: Annotation[]; | ||
document: Document; | ||
} | ||
export default class Renderer { | ||
static render(document: Document): any; | ||
renderAnnotation(annotation: Annotation, context: Context): IterableIterator<any>; | ||
root(): IterableIterator<any>; | ||
text(text: string): string; | ||
render(document: Document | HIR): any; | ||
text(text: string, _: Context): string; | ||
} |
@@ -30,3 +30,3 @@ "use strict"; | ||
} | ||
function compile(renderer, node, parent, previous, next) { | ||
function compile(renderer, node, context) { | ||
let annotation = node.annotation; | ||
@@ -36,12 +36,7 @@ let childNodes = node.children(); | ||
let generator; | ||
if (parent == null) { | ||
if (context.parent == null) { | ||
generator = renderer.root(); | ||
} | ||
else { | ||
generator = renderer.renderAnnotation(annotation, { | ||
parent, | ||
previous: previous || null, | ||
next: next || null, | ||
children: childAnnotations | ||
}); | ||
generator = renderer.renderAnnotation(annotation, Object.assign({}, context, { children: childAnnotations })); | ||
} | ||
@@ -53,7 +48,13 @@ let result = generator.next(); | ||
return generator.next(flatten(childNodes.map((childNode, idx) => { | ||
let childContext = { | ||
parent: annotation || null, | ||
previous: childAnnotations[idx - 1] || null, | ||
next: childAnnotations[idx + 1] || null, | ||
document: context.document | ||
}; | ||
if (childNode.annotation instanceof hir_1.TextAnnotation) { | ||
return renderer.text(childNode.annotation.attributes.text); | ||
return renderer.text(childNode.annotation.attributes.text, Object.assign({}, childContext, { children: [] })); | ||
} | ||
else { | ||
return compile(renderer, childNode, annotation, childAnnotations[idx - 1], childAnnotations[idx + 1]); | ||
return compile(renderer, childNode, childContext); | ||
} | ||
@@ -63,2 +64,6 @@ }))).value; | ||
class Renderer { | ||
static render(document) { | ||
let renderer = new this(); | ||
return compile(renderer, new hir_1.HIR(document).rootNode, { document }); | ||
} | ||
*renderAnnotation(annotation, context) { | ||
@@ -74,13 +79,7 @@ let generator = this[annotation.type]; | ||
} | ||
text(text) { | ||
text(text, _) { | ||
return text; | ||
} | ||
render(document) { | ||
if (document instanceof hir_1.HIR) { | ||
return compile(this, document.rootNode); | ||
} | ||
return compile(this, new hir_1.HIR(document).rootNode); | ||
} | ||
} | ||
exports.default = Renderer; | ||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvaW5kZXgudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7QUFDQSxxQ0FBMkQ7QUFNM0QsTUFBTSxNQUFNLEdBQVk7SUFDdEIsR0FBRyxFQUFFLE9BQU87SUFDWixHQUFHLEVBQUUsTUFBTTtJQUNYLEdBQUcsRUFBRSxNQUFNO0lBQ1gsR0FBRyxFQUFFLFFBQVE7SUFDYixJQUFJLEVBQUUsUUFBUTtJQUNkLEdBQUcsRUFBRSxRQUFRO0lBQ2IsR0FBRyxFQUFFLFFBQVE7Q0FDZCxDQUFDO0FBSUYsU0FBZ0IsVUFBVSxDQUFDLElBQVk7SUFDckMsT0FBTyxJQUFJLENBQUMsT0FBTyxDQUFDLFlBQVksRUFBRSxDQUFDLEdBQW9CLEVBQUUsRUFBRSxDQUFDLE1BQU0sQ0FBQyxHQUFHLENBQUMsQ0FBQyxDQUFDO0FBQzNFLENBQUM7QUFGRCxnQ0FFQztBQUVELFNBQVMsT0FBTyxDQUFDLEtBQVk7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sQ0FBQyxRQUFRLEVBQUUsU0FBUyxFQUFFLFlBQVksQ0FBQyxDQUFDO1NBQ25EO0lBQ0gsQ0FBQyxDQUFDLENBQUMsQ0FBQyxDQUFDLEtBQUssQ0FBQztBQUNiLENBQUM7QUFFRCxNQUFxQixRQUFRO0lBRTNCLE1BQU0sQ0FBQyxNQUFNLENBQUMsUUFBa0I7UUFDOUIsSUFBSSxRQUFRLEdBQUcsSUFBSSxJQUFJLEVBQUUsQ0FBQztRQUUxQixPQUFPLE9BQU8sQ0FBQyxRQUFRLEVBQUUsSUFBSSxTQUFHLENBQUMsUUFBUSxDQUFDLENBQUMsUUFBUSxFQUFFLEVBQUUsUUFBUSxFQUFFLENBQUMsQ0FBQztJQUNyRSxDQUFDO0lBRUQsQ0FBQyxnQkFBZ0IsQ0FBQyxVQUFzQixFQUFFLE9BQWdCO1FBQ3hELElBQUksU0FBUyxHQUFJLElBQVksQ0FBQyxVQUFVLENBQUMsSUFBSSxDQUFDLENBQUM7UUFDL0MsSUFBSSxTQUFTLEVBQUU7WUFDYixPQUFPLEtBQUssQ0FBQyxDQUFDLFNBQVMsQ0FBQyxJQUFJLENBQUMsSUFBSSxFQUFFLFVBQVUsRUFBRSxPQUFPLENBQUMsQ0FBQztTQUN6RDtRQUNELE9BQU8sS0FBSyxDQUFDO0lBQ2YsQ0FBQztJQUVELENBQUMsSUFBSTtRQUNILE9BQU8sS0FBSyxDQUFDO0lBQ2YsQ0FBQztJQUVELElBQUksQ0FBQyxJQUFZLEVBQUUsQ0FBVTtRQUMzQixPQUFPLElBQUksQ0FBQztJQUNkLENBQUM7Q0FDRjtBQXZCRCwyQkF1QkMifQ== |
import Document, { Annotation } from '@atjson/document'; | ||
import { HIR } from '@atjson/hir'; | ||
export declare function escapeHTML(text: string): string; | ||
@@ -9,8 +8,9 @@ export interface Context { | ||
children: Annotation[]; | ||
document: Document; | ||
} | ||
export default class Renderer { | ||
static render(document: Document): any; | ||
renderAnnotation(annotation: Annotation, context: Context): IterableIterator<any>; | ||
root(): IterableIterator<any>; | ||
text(text: string): string; | ||
render(document: Document | HIR): any; | ||
text(text: string, _: Context): string; | ||
} |
@@ -27,3 +27,3 @@ import { HIR, TextAnnotation } from '@atjson/hir'; | ||
} | ||
function compile(renderer, node, parent, previous, next) { | ||
function compile(renderer, node, context) { | ||
let annotation = node.annotation; | ||
@@ -33,12 +33,7 @@ let childNodes = node.children(); | ||
let generator; | ||
if (parent == null) { | ||
if (context.parent == null) { | ||
generator = renderer.root(); | ||
} | ||
else { | ||
generator = renderer.renderAnnotation(annotation, { | ||
parent, | ||
previous: previous || null, | ||
next: next || null, | ||
children: childAnnotations | ||
}); | ||
generator = renderer.renderAnnotation(annotation, Object.assign({}, context, { children: childAnnotations })); | ||
} | ||
@@ -50,7 +45,13 @@ let result = generator.next(); | ||
return generator.next(flatten(childNodes.map((childNode, idx) => { | ||
let childContext = { | ||
parent: annotation || null, | ||
previous: childAnnotations[idx - 1] || null, | ||
next: childAnnotations[idx + 1] || null, | ||
document: context.document | ||
}; | ||
if (childNode.annotation instanceof TextAnnotation) { | ||
return renderer.text(childNode.annotation.attributes.text); | ||
return renderer.text(childNode.annotation.attributes.text, Object.assign({}, childContext, { children: [] })); | ||
} | ||
else { | ||
return compile(renderer, childNode, annotation, childAnnotations[idx - 1], childAnnotations[idx + 1]); | ||
return compile(renderer, childNode, childContext); | ||
} | ||
@@ -60,2 +61,6 @@ }))).value; | ||
export default class Renderer { | ||
static render(document) { | ||
let renderer = new this(); | ||
return compile(renderer, new HIR(document).rootNode, { document }); | ||
} | ||
*renderAnnotation(annotation, context) { | ||
@@ -71,12 +76,6 @@ let generator = this[annotation.type]; | ||
} | ||
text(text) { | ||
text(text, _) { | ||
return text; | ||
} | ||
render(document) { | ||
if (document instanceof HIR) { | ||
return compile(this, document.rootNode); | ||
} | ||
return compile(this, new HIR(document).rootNode); | ||
} | ||
} | ||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjo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0FBQyxnQkFBZ0IsQ0FBQyxVQUFzQixFQUFFLE9BQWdCO1FBQ3hELElBQUksU0FBUyxHQUFJLElBQVksQ0FBQyxVQUFVLENBQUMsSUFBSSxDQUFDLENBQUM7UUFDL0MsSUFBSSxTQUFTLEVBQUU7WUFDYixPQUFPLEtBQUssQ0FBQyxDQUFDLFNBQVMsQ0FBQyxJQUFJLENBQUMsSUFBSSxFQUFFLFVBQVUsRUFBRSxPQUFPLENBQUMsQ0FBQztTQUN6RDtRQUNELE9BQU8sS0FBSyxDQUFDO0lBQ2YsQ0FBQztJQUVELENBQUMsSUFBSTtRQUNILE9BQU8sS0FBSyxDQUFDO0lBQ2YsQ0FBQztJQUVELElBQUksQ0FBQyxJQUFZLEVBQUUsQ0FBVTtRQUMzQixPQUFPLElBQUksQ0FBQztJQUNkLENBQUM7Q0FDRiJ9 |
{ | ||
"name": "@atjson/renderer-hir", | ||
"version": "0.11.9", | ||
"version": "0.12.0", | ||
"description": "A brand new TypeScript library.", | ||
@@ -22,3 +22,3 @@ "main": "dist/commonjs/index.js", | ||
}, | ||
"gitHead": "2bd36b1dda44bbc62d7f0cf7ecb11645fe87a0b7" | ||
"gitHead": "1a511e5498dd55f5c97c487955a3927fb7bb6ca7" | ||
} |
@@ -42,5 +42,6 @@ import Document, { Annotation } from '@atjson/document'; | ||
children: Annotation[]; | ||
document: Document; | ||
} | ||
function compile(renderer: Renderer, node: HIRNode, parent?: Annotation, previous?: Annotation, next?: Annotation): any { | ||
function compile(renderer: Renderer, node: HIRNode, context: Partial<Context>): any { | ||
let annotation = node.annotation; | ||
@@ -51,11 +52,9 @@ let childNodes = node.children(); | ||
if (parent == null) { | ||
if (context.parent == null) { | ||
generator = renderer.root(); | ||
} else { | ||
generator = renderer.renderAnnotation(annotation, { | ||
parent, | ||
previous: previous || null, | ||
next: next || null, | ||
...context, | ||
children: childAnnotations | ||
}); | ||
} as Context); | ||
} | ||
@@ -69,6 +68,16 @@ | ||
return generator.next(flatten(childNodes.map((childNode: HIRNode, idx: number) => { | ||
let childContext = { | ||
parent: annotation || null, | ||
previous: childAnnotations[idx - 1] || null, | ||
next: childAnnotations[idx + 1] || null, | ||
document: context.document! | ||
}; | ||
if (childNode.annotation instanceof TextAnnotation) { | ||
return renderer.text(childNode.annotation.attributes.text); | ||
return renderer.text(childNode.annotation.attributes.text, { | ||
...childContext, | ||
children: [] | ||
}); | ||
} else { | ||
return compile(renderer, childNode, annotation, childAnnotations[idx - 1], childAnnotations[idx + 1]); | ||
return compile(renderer, childNode, childContext); | ||
} | ||
@@ -80,2 +89,8 @@ }))).value; | ||
static render(document: Document) { | ||
let renderer = new this(); | ||
return compile(renderer, new HIR(document).rootNode, { document }); | ||
} | ||
*renderAnnotation(annotation: Annotation, context: Context): IterableIterator<any> { | ||
@@ -93,12 +108,5 @@ let generator = (this as any)[annotation.type]; | ||
text(text: string): string { | ||
text(text: string, _: Context): string { | ||
return text; | ||
} | ||
render(document: Document | HIR) { | ||
if (document instanceof HIR) { | ||
return compile(this, document.rootNode); | ||
} | ||
return compile(this, new HIR(document).rootNode); | ||
} | ||
} |
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
32620
304