@@ -22,13 +22,11 @@ import { useExportComponent } from "../composables/useExportComponent.js";
22
22
import { mapState } from " vuex" ;
23
23
const { fs , ipcRenderer } = window ;
24
24
25
- import writeNested from " ../../mixins/writeNested" ;
26
- import { result } from " lodash" ;
25
+ // import writeNested from "../../mixins/writeNested";
27
26
28
27
29
28
export default {
30
29
name: " ExportProjectComponent" ,
31
- mixins: [writeNested],
32
30
methods: {
33
31
useExportComponentBound () {
34
32
useExportComponent .bind (this )();
@@ -227,7 +225,42 @@ test('renders ${componentName}', () => {
227
225
`
228
226
</el-badge>` ],
229
227
};
230
-
228
+ // function to loop through nested elements
229
+ function writeNested (childrenArray , indent ) {
230
+ if (! childrenArray .length ) {
231
+ return " " ;
232
+ }
233
+ let indented = indent + " " ;
234
+ let nestedString = " " ;
235
+
236
+ childrenArray .forEach ((child ) => {
237
+ nestedString += indented;
238
+ if (! child .text ) {
239
+ nestedString += ` <${ child} />\n ` ;
240
+ } else {
241
+ nestedString += htmlElementMap[child .text ][0 ];
242
+ if (child .class !== " " ) {
243
+ nestedString += " " + " class = " + ` "${ child .class } "` ;
244
+ }
245
+ if (child .binding !== " " ) {
246
+ nestedString += " " + " v-model = " + ` "${ child .binding } "` ;
247
+ }
248
+ if (child .text === " img" || child .text === " input" || child .text === " link" ) {
249
+ nestedString += " />" ;
250
+ } else { nestedString += " >" ; }
251
+
252
+ if (child .children .length ) {
253
+ nestedString += " \n " ;
254
+ nestedString += writeNested (child .children , indented);
255
+ nestedString += indented + htmlElementMap[child .text ][1 ];
256
+ nestedString += " \n " ;
257
+ } else {
258
+ nestedString += htmlElementMap[child .text ][1 ] + " \n " ;
259
+ }
260
+ }
261
+ });
262
+ return nestedString;
263
+ }
231
264
// iterate through component's htmllist
232
265
let htmlArr = this .componentMap [componentName].htmlList ;
233
266
let outputStr = ` ` ;
@@ -328,12 +361,18 @@ test('renders ${componentName}', () => {
328
361
return ` <template>\n <div id = "${ compID} ">\n ${ templateTagStr}${ routeStr} </div>\n </template>` ;
329
362
}
330
363
else {
331
-
332
- return ` <template>\n <div>\n\t ${ str}${ templateTagStr}${ routeStr} </div>\n </template>` ;
364
+ const arrOfChildComp = this .componentMap [componentName].children ;
365
+ arrOfChildComp .forEach (childName => {
366
+ let childNameClass = this .componentMap [childName].htmlAttributes .class ;
367
+ let childNameClassFullStr = (childNameClass === " " ) ? " " : ` class = '${ childNameClass} '` ;
368
+ routeStr += ` <${ childName}${ childNameClassFullStr} ></${ childName} >\n `
369
+ });
370
+
371
+ return ` <template>\n <div>\n ${ str}${ templateTagStr}${ routeStr} </div>\n </template>` ;
333
372
}
334
373
}
335
374
else {
336
- return ` <template>\n\t ${ str}${ templateTagStr}${ routeStr} \t </div>\n </template>`
375
+ return ` <template>\n <div> \n \t${ str}${ templateTagStr}${ routeStr} \t </div>\n </template>`
337
376
}
338
377
},
339
378
/**
@@ -366,6 +405,20 @@ test('renders ${componentName}', () => {
366
405
}
367
406
368
407
let childrenComponentNames = " " ;
408
+ let childComponentImportNames = " " ;
409
+
410
+ const arrOfChildComp = this .componentMap [componentName].children ;
411
+
412
+ arrOfChildComp .forEach (childName => {
413
+ // Build child component text string
414
+ if (childName !== arrOfChildComp[arrOfChildComp .length - 1 ]){
415
+ childrenComponentNames += " " + childName + " ,\n " ;
416
+ }
417
+ else {
418
+ childrenComponentNames += " " + childName + " \n " ;
419
+ }
420
+ childComponentImportNames += ` import ${ childName} from '../components/${ childName} .vue';\n `
421
+ })
369
422
370
423
let data = " " ;
371
424
data += " data () {\n return {" ;
@@ -416,6 +469,8 @@ test('renders ${componentName}', () => {
416
469
} else {
417
470
output = " \n\n <script>\n " ;
418
471
472
+ output+= ` \n ${ childComponentImportNames} ` ;
473
+
419
474
output += imports + " \n export default {\n name: '" + componentName + " '" ;
420
475
421
476
}
0 commit comments