feat: reorganize builder
This commit is contained in:
parent
ff7bb041ef
commit
362b7aa15e
18 changed files with 1094 additions and 310 deletions
47
lib/generators/RootNodeGenerator.js
Normal file
47
lib/generators/RootNodeGenerator.js
Normal file
|
@ -0,0 +1,47 @@
|
|||
/**
|
||||
* Generates HTML for the root node of the AST.
|
||||
*/
|
||||
class RootNodeGenerator {
|
||||
/**
|
||||
* Creates a new root node generator.
|
||||
* @param {Object} options - Options for the generator
|
||||
* @param {Object} parentGenerator - Parent HTML generator for recursion
|
||||
*/
|
||||
constructor(options, parentGenerator) {
|
||||
this.options = options;
|
||||
this.parentGenerator = parentGenerator;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines if this generator can handle the given node.
|
||||
* @param {Object} node - The node to check
|
||||
* @returns {boolean} - True if this generator can handle the node
|
||||
*/
|
||||
canHandle(node) {
|
||||
return node.type === "root";
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates HTML for the root node.
|
||||
* @param {Object} node - The node to generate HTML for
|
||||
* @returns {string} - The generated HTML
|
||||
*/
|
||||
generate(node) {
|
||||
if (this.options.debug) {
|
||||
console.log(`\n[RootNodeGenerator] Processing root node with ${node.children.length} children`);
|
||||
}
|
||||
|
||||
let html = "";
|
||||
|
||||
node.children.forEach((child, index) => {
|
||||
if (this.options.debug) {
|
||||
console.log(`[RootNodeGenerator] Processing child ${index + 1}/${node.children.length}`);
|
||||
}
|
||||
html += this.parentGenerator.generateHTML(child);
|
||||
});
|
||||
|
||||
return html;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = RootNodeGenerator;
|
Loading…
Add table
Add a link
Reference in a new issue