@@ -143,14 +143,55 @@ export default {
143
143
input: [' <input />' , ' ' ],
144
144
navbar: [' <nav>' , ' </nav>' ]
145
145
}
146
+
147
+ /* Function to loop through nested elements */
148
+ function writeNested (childrenArray , indent ) {
149
+ if (! childrenArray .length ) {
150
+ return ' '
151
+ }
152
+ let indented = indent + ' '
153
+ let nestedString = ' '
154
+
155
+ childrenArray .forEach (child => {
156
+ nestedString += indented
157
+ // console.log(child)
158
+ if (! child .text ) {
159
+ nestedString += ` <${ child} />\n `
160
+ } else {
161
+ if (child .children .length ) {
162
+ nestedString += htmlElementMap[child .text ][0 ]
163
+ nestedString += ' \n '
164
+ nestedString += writeNested (child .children , indented)
165
+ nestedString += indented + htmlElementMap[child .text ][1 ]
166
+ nestedString += ' \n '
167
+ } else {
168
+ nestedString += htmlElementMap[child .text ][0 ] + htmlElementMap[child .text ][1 ] + ' \n '
169
+ }
170
+ }
171
+ })
172
+ return nestedString
173
+ }
174
+
146
175
// loop to iterate through compName arr
147
176
let htmlArr = this .componentMap [compName].htmlList
148
- let outputStr = ' '
177
+ let outputStr = ` `
149
178
for (let el of htmlArr) {
150
- outputStr += ' \t\t '
151
- outputStr += htmlElementMap[el .text ][0 ]
152
- outputStr += htmlElementMap[el .text ][1 ]
153
- outputStr += ` \n `
179
+ // console.log(el)
180
+ if (! el .text ) {
181
+ outputStr += ` <${ el} />\n `
182
+ } else {
183
+ outputStr += ` `
184
+ if (el .children .length ) {
185
+ outputStr += htmlElementMap[el .text ][0 ]
186
+ outputStr += ' \n '
187
+ outputStr += writeNested (el .children , ` ` )
188
+ outputStr += ` `
189
+ outputStr += htmlElementMap[el .text ][1 ]
190
+ outputStr += ` \n `
191
+ } else {
192
+ outputStr += htmlElementMap[el .text ][0 ] + htmlElementMap[el .text ][1 ] + ' \n '
193
+ }
194
+ }
154
195
}
155
196
console .log (` outputStr from writeTemplateTag: ${ outputStr} ` )
156
197
return outputStr
@@ -199,15 +240,6 @@ export default {
199
240
} else {
200
241
// console.log(`else (if compName === 'App'`);
201
242
str += ` <div>\n `
202
- children .forEach (name => {
203
- str += ` \t\t <${
204
- // name.componentName
205
- name
206
- } >\n\t\t </${
207
- // name.componentName
208
- name
209
- } >\n `
210
- })
211
243
}
212
244
// writes the html tag boilerplate
213
245
let templateTagStr = this .writeTemplateTag (compName)
0 commit comments