Skip to content

Commit f5d6abc

Browse files
committed
handles nested components
1 parent b28c769 commit f5d6abc

File tree

3 files changed

+47
-9
lines changed

3 files changed

+47
-9
lines changed

src/components/CodeSnippet.vue

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,15 +53,16 @@ export default {
5353
createTemplate(componentName, children) {
5454
let output = ``;
5555
output += ` <div>\n`;
56-
children.forEach(name => {
57-
output += ` <${name}>\n </${name}>\n`;
58-
});
56+
// children.forEach(name => {
57+
// output += ` <${name}>\n </${name}>\n`;
58+
// });
5959
let templateTagStr = this.writeTemplateTag(componentName);
6060
return `<template>\n ${output}${templateTagStr} </div>\n</template>`;
6161
},
6262
6363
// We need a helper function to recursively iterate through the given html element's children and their children's children.
6464
65+
6566
writeTemplateTag(componentName) {
6667
// console.log('writeTemplateTag invoked!')
6768
// create reference object
@@ -78,14 +79,48 @@ export default {
7879
input: ['<input />', ''],
7980
navbar: ['<nav>', '</nav>'],
8081
};
82+
83+
function writeNested(childrenArray, indent){
84+
if(!childrenArray.length){
85+
return ''
86+
}
87+
let indented = indent + ' '
88+
let nestedString = indented
89+
90+
childrenArray.forEach(child => {
91+
console.log(child)
92+
if(!child.text){
93+
nestedString += `<${child}/>\n`
94+
}
95+
else{
96+
nestedString += htmlElementMap[child.text][0]
97+
nestedString += '\n';
98+
nestedString += writeNested(child.children,indented)
99+
nestedString += indented + htmlElementMap[child.text][1]
100+
nestedString += '\n'
101+
}
102+
})
103+
return nestedString
104+
}
105+
106+
81107
// loop to iterate through compName arr
82108
let htmlArr = this.componentMap[componentName].htmlList;
83109
let outputStr = ``;
84110
for (let el of htmlArr) {
111+
console.log(el)
112+
if(!el.text){
113+
outputStr += ` <${el}/>\n`
114+
}
115+
else{
85116
outputStr += ` `;
86117
outputStr += htmlElementMap[el.text][0];
118+
outputStr += '\n'
119+
outputStr += writeNested(el.children,` `)
120+
outputStr += ` `
87121
outputStr += htmlElementMap[el.text][1];
88122
outputStr += ` \n`;
123+
}
89124
}
90125
// console.log(`outputStr from writeTemplateTag: ${outputStr}`)
91126
return outputStr;

src/components/ComponentDisplay.vue

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ export default {
119119
]),
120120
// used in VueDraggableResizeable component
121121
activeRouteArray() {
122-
console.log("active route array method", this.routes[this.activeRoute]);
122+
// console.log("active route array method", this.routes[this.activeRoute]);
123123
return this.routes[this.activeRoute];
124124
},
125125
// used to delete components
@@ -140,11 +140,11 @@ export default {
140140
if (!Object.keys(component.parent).length) return lineage;
141141
for(var parents in component.parent) {
142142
//for each parent in our component
143-
console.log('parents', parents)
143+
// console.log('parents', parents)
144144
lineage.push(parents); //push the parent into lineage
145-
console.log('lineage pre push', component, lineage)
145+
// console.log('lineage pre push', component, lineage)
146146
checkParents(component.parent[parents], lineage);
147-
console.log('lineage post recursive call', lineage)
147+
// console.log('lineage post recursive call', lineage)
148148
}
149149
// lineage.push(component.parent[component.componentName]);
150150
// return checkParents(component.parent, lineage);
@@ -159,7 +159,7 @@ export default {
159159
// console.log(this.componentMap[this.activeComponent].children)
160160
this.testModel = this.componentMap[this.activeComponent].children;
161161
lineage = checkParents(this.componentMap[this.activeComponent]);
162-
console.log('Lineage', lineage);
162+
//console.log('Lineage', lineage);
163163
}
164164
const routes = Object.keys(this.routes);
165165
const exceptions = new Set(["App", ...lineage, ...routes, ...this.testModel]);

src/store/state/index.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@ let hardA = {
1111
h: 200,
1212
htmlList: [{
1313
children:[{
14-
children:[],
14+
children:[{
15+
text: 'button',
16+
children:[]
17+
}],
1518
text:'form'
1619
}],
1720
text: "div"

0 commit comments

Comments
 (0)