Skip to content

Commit

Permalink
ZETA-6955: migrate over more
Browse files Browse the repository at this point in the history
  • Loading branch information
CharlieGreenman committed Oct 25, 2023
1 parent 4b651fa commit 8fdd7bf
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions src/rz/angular/insert-into-html-tag/insert-into-html-tag.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,22 @@

import visit from 'unist-util-visit';
import { createUnifiedTree } from '../morph-angular-html';
import { parseHtml } from '../morph-angular-html';
import { EditHtmlFile } from '../interfaces/edit-html.interface';

// will insert code into an html block
export function insertIntoHtmlTag(editFile: EditHtmlFile, fileToBeModified: any): any {
const codeToAddTree = createUnifiedTree(editFile.codeBlock as string);
export function insertIntoHtmlTag(editFile: EditHtmlFile, astNode: any): any {
let counter = 0;

visit(fileToBeModified, {type: 'element', tagName: editFile.tagNameToInsertInto}, (node: any, index) => {
visit(codeToAddTree, {type: 'element', tagName: 'body'}, (nodeOfCodeToAdd: any, index) => {
if(!editFile.className || editFile.className === '' || node.properties.className?.includes(editFile.className)) {
const codeToAddTree = parseHtml(editFile.codeBlock as string);
astNode.rootNodes.forEach((node: any) => {
visit(node, {type: 'element', name: editFile.tagNameToInsertInto}, (node: any, index) => {
if(!editFile.className || editFile.className === '' || node.attrs.find((attr: any) => attr.value === editFile.className)) {
if(counter === 0) {
node.children.push(nodeOfCodeToAdd.children[0]);
node.children.push(codeToAddTree.rootNodes[0]);
counter++;
}
}
});
});

return fileToBeModified
return astNode
}

0 comments on commit 8fdd7bf

Please sign in to comment.