@@ -27,7 +27,7 @@ export function useExportComponent() {
2727 const createComponentCode = ( componentLocation , componentName , children ) => {
2828 fs . writeFileSync (
2929 componentLocation + ".vue" ,
30- writeComments ( componentName ) +
30+ // writeComments(componentName) +
3131 writeTemplate ( componentName , children ) +
3232 writeScript ( componentName , children ) +
3333 writeStyle ( componentName )
@@ -37,26 +37,26 @@ export function useExportComponent() {
3737 const writeTemplateTag = ( componentName ) => {
3838 // create reference object
3939 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>" ] ,
6060 } ;
6161 // function to loop through nested elements
6262 const writeNested = ( childrenArray , indent ) => {
@@ -65,51 +65,66 @@ export function useExportComponent() {
6565 }
6666 let indented = indent + " " ;
6767 let nestedString = "" ;
68+
6869 childrenArray . forEach ( ( child ) => {
6970 nestedString += indented ;
7071 if ( ! child . text ) {
7172 nestedString += `<${ child } />\n` ;
7273 } 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+
7385 if ( child . children . length ) {
74- nestedString += htmlElementMap [ child . text ] [ 0 ] ;
7586 nestedString += "\n" ;
7687 nestedString += writeNested ( child . children , indented ) ;
7788 nestedString += indented + htmlElementMap [ child . text ] [ 1 ] ;
7889 nestedString += "\n" ;
7990 } else {
80- nestedString +=
81- htmlElementMap [ child . text ] [ 0 ] +
82- htmlElementMap [ child . text ] [ 1 ] +
83- "\n" ;
91+ nestedString += htmlElementMap [ child . text ] [ 1 ] + "\n" ;
8492 }
8593 }
8694 } ) ;
8795 return nestedString ;
8896 }
8997 // iterate through component's htmllist
9098 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 , ` ` ) ;
97118 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" ;
109123 }
110124 }
111- return outputStr ;
112125 }
126+ return outputStr ;
127+ }
113128
114129 const writeComments = ( componentName ) => {
115130 if ( this . componentMap [ componentName ] ?. noteList ?. length > 0 ) {
@@ -128,11 +143,19 @@ export function useExportComponent() {
128143 * also creates the <template></template> tag for each component
129144 */
130145 const writeTemplate = ( componentName , children ) => {
131- let str = "" ;
132- str += `<div>\n` ;
146+ // let str = "";
147+ // str += `<div>\n`;
133148 // writes the HTML tag boilerplate
134149 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>` ;
136159 }
137160
138161 /**
@@ -167,15 +190,23 @@ export function useExportComponent() {
167190 } ) ;
168191 // if true add data section and populate with props
169192 let data = "" ;
193+ data += " data () {\n return {" ;
170194 if ( currentComponent . props . length ) {
171- data += " data () {\n return {" ;
172195 currentComponent . props . forEach ( ( prop ) => {
173196 data += `\n ${ prop } : "PLACEHOLDER FOR VALUE",` ;
174197 } ) ;
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+ } )
175206 data += "\n" ;
176207 data += " }\n" ;
177208 data += " },\n" ;
178- }
209+
179210 // if true add computed section and populate with state
180211 let computed = "" ;
181212 if ( currentComponent . state . length ) {
@@ -228,7 +259,35 @@ export function useExportComponent() {
228259 * if component is 'App', writes css, else returns <style scoped>
229260 */
230261 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 >` ;
232291 }
233292
234293 const exportComponentFile = ( data ) => {
0 commit comments