@@ -27,7 +27,7 @@ export function useExportComponent() {
27
27
const createComponentCode = ( componentLocation , componentName , children ) => {
28
28
fs . writeFileSync (
29
29
componentLocation + ".vue" ,
30
- writeComments ( componentName ) +
30
+ // writeComments(componentName) +
31
31
writeTemplate ( componentName , children ) +
32
32
writeScript ( componentName , children ) +
33
33
writeStyle ( componentName )
@@ -37,26 +37,26 @@ export function useExportComponent() {
37
37
const writeTemplateTag = ( componentName ) => {
38
38
// create reference object
39
39
const htmlElementMap = {
40
- div : [ "<div> " , "</div>" ] ,
41
- button : [ "<button> " , "</button>" ] ,
42
- form : [ "<form> " , "</form>" ] ,
43
- img : [ "<img> " , "" ] ,
44
- link : [ '<a href="#"/> ' , "" ] ,
45
- list : [ "<li> " , "</li>" ] ,
46
- paragraph : [ "<p> " , "</p>" ] ,
47
- "list-ol" : [ "<ol> " , "</ol>" ] ,
48
- "list-ul" : [ "<ul> " , "</ul>" ] ,
49
- input : [ "<input /> " , "" ] ,
50
- navbar : [ "<nav> " , "</nav>" ] ,
51
- header :[ "<header> " , "</header>" ] ,
52
- footer :[ "<footer> " , "</footer>" ] ,
53
- meta : [ "<meta> " , "</meta>" ] ,
54
- h1 :[ "<h1> " , "</h1>" ] ,
55
- h2 :[ "<h2> " , "</h2>" ] ,
56
- h3 :[ "<h3> " , "</h3>" ] ,
57
- h4 :[ "<h4> " , "</h4>" ] ,
58
- h5 :[ "<h5> " , "</h5>" ] ,
59
- h6 :[ "<h6> " , "</h6>" ] ,
40
+ div : [ "<div" , "</div>" ] ,
41
+ button : [ "<button" , "</button>" ] ,
42
+ form : [ "<form" , "</form>" ] ,
43
+ img : [ "<img" , "" ] , //single
44
+ link : [ '<a href="#"' , "" ] , //single
45
+ list : [ "<li" , "</li>" ] ,
46
+ paragraph : [ "<p" , "</p>" ] ,
47
+ "list-ol" : [ "<ol" , "</ol>" ] ,
48
+ "list-ul" : [ "<ul" , "</ul>" ] ,
49
+ input : [ "<input" , "" ] , //single
50
+ navbar : [ "<nav" , "</nav>" ] ,
51
+ header : [ "<header" , "</header>" ] ,
52
+ footer : [ "<footer" , "</footer>" ] ,
53
+ meta : [ "<meta" , "</meta>" ] ,
54
+ h1 : [ "<h1" , "</h1>" ] ,
55
+ h2 : [ "<h2" , "</h2>" ] ,
56
+ h3 : [ "<h3" , "</h3>" ] ,
57
+ h4 : [ "<h4" , "</h4>" ] ,
58
+ h5 : [ "<h5" , "</h5>" ] ,
59
+ h6 : [ "<h6" , "</h6>" ] ,
60
60
} ;
61
61
// function to loop through nested elements
62
62
const writeNested = ( childrenArray , indent ) => {
@@ -65,51 +65,60 @@ export function useExportComponent() {
65
65
}
66
66
let indented = indent + " " ;
67
67
let nestedString = "" ;
68
+
68
69
childrenArray . forEach ( ( child ) => {
69
70
nestedString += indented ;
70
71
if ( ! child . text ) {
71
72
nestedString += `<${ child } />\n` ;
72
73
} else {
74
+ nestedString += htmlElementMap [ child . text ] [ 0 ] ;
75
+ if ( child . class !== "" ) {
76
+ nestedString += " " + "class = " + `"${ child . class } "` ;
77
+ }
78
+ if ( child . text === "img" || child . text === "input" || child . text === "link" ) {
79
+ nestedString += "/>" ;
80
+ } else { nestedString += ">" ; }
81
+
73
82
if ( child . children . length ) {
74
- nestedString += htmlElementMap [ child . text ] [ 0 ] ;
75
83
nestedString += "\n" ;
76
84
nestedString += writeNested ( child . children , indented ) ;
77
85
nestedString += indented + htmlElementMap [ child . text ] [ 1 ] ;
78
86
nestedString += "\n" ;
79
87
} else {
80
- nestedString +=
81
- htmlElementMap [ child . text ] [ 0 ] +
82
- htmlElementMap [ child . text ] [ 1 ] +
83
- "\n" ;
88
+ nestedString += htmlElementMap [ child . text ] [ 1 ] + "\n" ;
84
89
}
85
90
}
86
91
} ) ;
87
92
return nestedString ;
88
93
}
89
94
// iterate through component's htmllist
90
95
let htmlArr = this . componentMap [ componentName ] . htmlList ;
91
- let outputStr = `` ;
92
- // eslint-disable-next-line no-unused-vars
93
- for ( let el of htmlArr ) {
94
- if ( ! el . text ) {
95
- outputStr += ` <${ el } />\n` ;
96
- } else {
96
+ let outputStr = `` ;
97
+ // eslint-disable-next-line no-unused-vars
98
+ for ( let el of htmlArr ) {
99
+ if ( ! el . text ) {
100
+ outputStr += ` <${ el } />\n` ;
101
+ } else {
102
+ outputStr += ` ` ;
103
+ outputStr += htmlElementMap [ el . text ] [ 0 ]
104
+ //if conditional to check class
105
+ if ( el . class !== "" ) {
106
+ outputStr += " " + "class = " + `"${ el . class } "` ;
107
+ }
108
+ outputStr += ">" ;
109
+ if ( el . children . length ) {
110
+ outputStr += "\n" ;
111
+ outputStr += writeNested ( el . children , ` ` ) ;
97
112
outputStr += ` ` ;
98
- if ( el . children . length ) {
99
- outputStr += htmlElementMap [ el . text ] [ 0 ] ;
100
- outputStr += "\n" ;
101
- outputStr += writeNested ( el . children , ` ` ) ;
102
- outputStr += ` ` ;
103
- outputStr += htmlElementMap [ el . text ] [ 1 ] ;
104
- outputStr += ` \n` ;
105
- } else {
106
- outputStr +=
107
- htmlElementMap [ el . text ] [ 0 ] + htmlElementMap [ el . text ] [ 1 ] + "\n" ;
108
- }
113
+ outputStr += htmlElementMap [ el . text ] [ 1 ] ;
114
+ outputStr += ` \n` ;
115
+ } else {
116
+ outputStr += htmlElementMap [ el . text ] [ 1 ] + "\n" ;
109
117
}
110
118
}
111
- return outputStr ;
112
119
}
120
+ return outputStr ;
121
+ }
113
122
114
123
const writeComments = ( componentName ) => {
115
124
if ( this . componentMap [ componentName ] ?. noteList ?. length > 0 ) {
@@ -128,11 +137,18 @@ export function useExportComponent() {
128
137
* also creates the <template></template> tag for each component
129
138
*/
130
139
const writeTemplate = ( componentName , children ) => {
131
- let str = "" ;
132
- str += `<div>\n` ;
140
+ // let str = "";
141
+ // str += `<div>\n`;
133
142
// writes the HTML tag boilerplate
134
143
let templateTagStr = writeTemplateTag ( componentName ) ;
135
- return `<template>\n\t${ str } ${ templateTagStr } \t</div>\n</template>` ;
144
+
145
+ if ( this . componentMap [ componentName ] . htmlAttributes . class !== "" && this . componentMap [ componentName ] . htmlAttributes . id !== "" ) {
146
+ return `<template>\n <div id = "${ this . componentMap [ componentName ] . htmlAttributes . id } " class = "${ this . componentMap [ componentName ] . htmlAttributes . class } ">\n${ templateTagStr } </div>\n</template>` ;
147
+ } else if ( this . componentMap [ componentName ] . htmlAttributes . class !== "" && this . componentMap [ componentName ] . htmlAttributes . id === "" ) {
148
+ return `<template>\n <div class = "${ this . componentMap [ componentName ] . htmlAttributes . class } ">\n${ templateTagStr } </div>\n</template>` ;
149
+ } else if ( this . componentMap [ componentName ] . htmlAttributes . class === "" && this . componentMap [ componentName ] . htmlAttributes . id !== "" )
150
+ return `<template>\n <div id = "${ this . componentMap [ componentName ] . htmlAttributes . id } ">\n${ templateTagStr } </div>\n</template>` ;
151
+ else return `<template>\n <div>\n${ templateTagStr } </div>\n</template>` ;
136
152
}
137
153
138
154
/**
@@ -228,7 +244,27 @@ export function useExportComponent() {
228
244
* if component is 'App', writes css, else returns <style scoped>
229
245
*/
230
246
const writeStyle = ( componentName ) => {
231
- return `\n\n<style scoped>\n</style>` ;
247
+ let htmlArray = this . componentMap [ componentName ] . htmlList ;
248
+ let styleString = "" ;
249
+
250
+ console . log ( this . componentMap [ componentName ] )
251
+ if ( this . componentMap [ componentName ] . htmlAttributes . class !== "" ) {
252
+ styleString += `.${ this . componentMap [ componentName ] . htmlAttributes . class } {\nbackground-color: ${ this . componentMap [ componentName ] . color } ;
253
+ width: ${ this . componentMap [ componentName ] . w } px;
254
+ height: ${ this . componentMap [ componentName ] . h } px;
255
+ z-index: ${ this . componentMap [ componentName ] . z } ;
256
+ }\n`
257
+ }
258
+
259
+ for ( const html of htmlArray ) {
260
+ if ( html . class === ' ' ) styleString = "" ;
261
+ if ( html . class ) {
262
+ styleString += `.${ html . class } {\n
263
+ }\n`
264
+ }
265
+ }
266
+
267
+ return `\n <\/script>\n\n<style scoped>\n${ styleString } </style >` ;
232
268
}
233
269
234
270
const exportComponentFile = ( data ) => {
0 commit comments