First commits be like
This commit is contained in:
5
sunpy/node/nodes/basenode.js
Normal file
5
sunpy/node/nodes/basenode.js
Normal file
@@ -0,0 +1,5 @@
|
||||
export class BaseNode {
|
||||
constructor(node) {
|
||||
this.node = node;
|
||||
}
|
||||
}
|
||||
22
sunpy/node/nodes/propertynode.js
Normal file
22
sunpy/node/nodes/propertynode.js
Normal file
@@ -0,0 +1,22 @@
|
||||
import { SwapNode } from "./swapnode.js";
|
||||
import { PropertyReader } from "../propertyreader.js";
|
||||
|
||||
export class PropertyNode extends SwapNode {
|
||||
constructor(node, swapNode, propertyReader) {
|
||||
super(node, swapNode);
|
||||
|
||||
if (!(propertyReader instanceof PropertyReader))
|
||||
throw TypeError("propertyReader must be an instance of PropertyReader");
|
||||
|
||||
this.propertyReader = propertyReader;
|
||||
|
||||
super.replaceNodes();
|
||||
}
|
||||
|
||||
/**
|
||||
* @override
|
||||
*/
|
||||
linker(node, swapNode) {
|
||||
this.properties = this.propertyReader.read(node.innerText);
|
||||
}
|
||||
}
|
||||
35
sunpy/node/nodes/swapnode.js
Normal file
35
sunpy/node/nodes/swapnode.js
Normal file
@@ -0,0 +1,35 @@
|
||||
import { BaseNode } from "./basenode.js";
|
||||
|
||||
export class SwapNode extends BaseNode {
|
||||
constructor(node, swapNode) {
|
||||
super(node);
|
||||
|
||||
if (!(swapNode instanceof Node))
|
||||
throw TypeError("swapNode must be instance of Node");
|
||||
|
||||
this.swapNode = swapNode;
|
||||
|
||||
this.hasReplaceNodes = false;
|
||||
}
|
||||
|
||||
replaceNodes() {
|
||||
if (this.hasReplaceNodes)
|
||||
return false;
|
||||
|
||||
this.linker(this.node, this.swapNode);
|
||||
|
||||
this.node.parentNode.replaceChild(this.swapNode, this.node);
|
||||
this.node = this.swapNode;
|
||||
|
||||
delete this.swapNode;
|
||||
|
||||
return this.hasReplaceNodes = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Override this to have access to the script tag that gets converted to the new node inplace
|
||||
* @param {Node} node Node of the original script tag
|
||||
* @param {Node} swapNode Node of the new element that replaces the script tag inline
|
||||
*/
|
||||
linker(node, swapNode) {}
|
||||
}
|
||||
Reference in New Issue
Block a user