@@ -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,66 @@ 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 . binding !== "" ) {
79
+ nestedString += " " + "v-model = " + `"${ child . binding } "` ;
80
+ }
81
+ if ( child . text === "img" || child . text === "input" || child . text === "link" ) {
82
+ nestedString += "/>" ;
83
+ } else { nestedString += ">" ; }
84
+
73
85
if ( child . children . length ) {
74
- nestedString += htmlElementMap [ child . text ] [ 0 ] ;
75
86
nestedString += "\n" ;
76
87
nestedString += writeNested ( child . children , indented ) ;
77
88
nestedString += indented + htmlElementMap [ child . text ] [ 1 ] ;
78
89
nestedString += "\n" ;
79
90
} else {
80
- nestedString +=
81
- htmlElementMap [ child . text ] [ 0 ] +
82
- htmlElementMap [ child . text ] [ 1 ] +
83
- "\n" ;
91
+ nestedString += htmlElementMap [ child . text ] [ 1 ] + "\n" ;
84
92
}
85
93
}
86
94
} ) ;
87
95
return nestedString ;
88
96
}
89
97
// iterate through component's htmllist
90
98
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 {
99
+ let outputStr = `` ;
100
+ // eslint-disable-next-line no-unused-vars
101
+ for ( let el of htmlArr ) {
102
+ if ( ! el . text ) {
103
+ outputStr += ` <${ el } />\n` ;
104
+ } else {
105
+ outputStr += ` ` ;
106
+ outputStr += htmlElementMap [ el . text ] [ 0 ]
107
+ //if conditional to check class
108
+ if ( el . class !== "" ) {
109
+ outputStr += " " + "class = " + `"${ el . class } "` ;
110
+ }
111
+ if ( el . binding !== "" ) {
112
+ outputStr += " " + "v-model = " + `"${ el . binding } "` ;
113
+ }
114
+ outputStr += ">" ;
115
+ if ( el . children . length ) {
116
+ outputStr += "\n" ;
117
+ outputStr += writeNested ( el . children , ` ` ) ;
97
118
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
- }
119
+ outputStr += htmlElementMap [ el . text ] [ 1 ] ;
120
+ outputStr += ` \n` ;
121
+ } else {
122
+ outputStr += htmlElementMap [ el . text ] [ 1 ] + "\n" ;
109
123
}
110
124
}
111
- return outputStr ;
112
125
}
126
+ return outputStr ;
127
+ }
113
128
114
129
const writeComments = ( componentName ) => {
115
130
if ( this . componentMap [ componentName ] ?. noteList ?. length > 0 ) {
@@ -128,11 +143,19 @@ export function useExportComponent() {
128
143
* also creates the <template></template> tag for each component
129
144
*/
130
145
const writeTemplate = ( componentName , children ) => {
131
- let str = "" ;
132
- str += `<div>\n` ;
146
+ // let str = "";
147
+ // str += `<div>\n`;
133
148
// writes the HTML tag boilerplate
134
149
let templateTagStr = writeTemplateTag ( componentName ) ;
135
- return `<template>\n\t${ str } ${ templateTagStr } \t</div>\n</template>` ;
150
+
151
+ //used to loop through - and apply class/id in code snippet
152
+ if ( this . componentMap [ componentName ] . htmlAttributes . class !== "" && this . componentMap [ componentName ] . htmlAttributes . id !== "" ) {
153
+ return `<template>\n <div id = "${ this . componentMap [ componentName ] . htmlAttributes . id } " class = "${ this . componentMap [ componentName ] . htmlAttributes . class } ">\n${ templateTagStr } </div>\n</template>` ;
154
+ } else if ( this . componentMap [ componentName ] . htmlAttributes . class !== "" && this . componentMap [ componentName ] . htmlAttributes . id === "" ) {
155
+ return `<template>\n <div class = "${ this . componentMap [ componentName ] . htmlAttributes . class } ">\n${ templateTagStr } </div>\n</template>` ;
156
+ } else if ( this . componentMap [ componentName ] . htmlAttributes . class === "" && this . componentMap [ componentName ] . htmlAttributes . id !== "" )
157
+ return `<template>\n <div id = "${ this . componentMap [ componentName ] . htmlAttributes . id } ">\n${ templateTagStr } </div>\n</template>` ;
158
+ else return `<template>\n <div>\n${ templateTagStr } </div>\n</template>` ;
136
159
}
137
160
138
161
/**
@@ -167,15 +190,23 @@ export function useExportComponent() {
167
190
} ) ;
168
191
// if true add data section and populate with props
169
192
let data = "" ;
193
+ data += " data () {\n return {" ;
170
194
if ( currentComponent . props . length ) {
171
- data += " data () {\n return {" ;
172
195
currentComponent . props . forEach ( ( prop ) => {
173
196
data += `\n ${ prop } : "PLACEHOLDER FOR VALUE",` ;
174
197
} ) ;
198
+ }
199
+ this . routes . HomeView . forEach ( ( element ) => {
200
+ element . htmlList . forEach ( ( html ) => {
201
+ if ( html . binding !== '' ) {
202
+ data += `\n ${ html . binding } : "PLACEHOLDER FOR VALUE",` ;
203
+ }
204
+ } )
205
+ } )
175
206
data += "\n" ;
176
207
data += " }\n" ;
177
208
data += " },\n" ;
178
- }
209
+
179
210
// if true add computed section and populate with state
180
211
let computed = "" ;
181
212
if ( currentComponent . state . length ) {
@@ -228,7 +259,35 @@ export function useExportComponent() {
228
259
* if component is 'App', writes css, else returns <style scoped>
229
260
*/
230
261
const writeStyle = ( componentName ) => {
231
- return `\n\n<style scoped>\n</style>` ;
262
+ let htmlArray = this . componentMap [ componentName ] . htmlList ;
263
+ let styleString = "" ;
264
+
265
+ this . routes . HomeView . forEach ( ( element ) => {
266
+ if ( element . htmlAttributes . class !== "" ) {
267
+ styleString += `.${ element . htmlAttributes . class } {\nbackground-color: ${ element . color } ;
268
+ width: ${ element . w } px;
269
+ height: ${ element . h } px;
270
+ z-index: ${ element . z } ;
271
+ }\n`
272
+ }
273
+ } )
274
+
275
+
276
+
277
+
278
+
279
+ for ( const html of htmlArray ) {
280
+ if ( html . class !== '' ) {
281
+ styleString += `.${ html . class } {\nheight: ${ html . h } %;
282
+ width: ${ html . w } %;
283
+ top: ${ html . x } %;
284
+ left: ${ html . y } %;
285
+ z-index: ${ html . z } ;
286
+ }\n`
287
+ }
288
+ }
289
+
290
+ return `\n\n<style scoped>\n${ styleString } </style >` ;
232
291
}
233
292
234
293
const exportComponentFile = ( data ) => {
0 commit comments