@@ -40,7 +40,7 @@ export default {
40
40
},
41
41
computed: {
42
42
// needs access to current component aka activeComponent
43
- ... mapState ([' componentMap' , ' activeComponent' ])
43
+ ... mapState ([' componentMap' , ' activeComponent' , ' activeComponentObj ' ])
44
44
},
45
45
methods: {
46
46
getWindowHeight (e ) {
@@ -58,10 +58,12 @@ export default {
58
58
},
59
59
// Creates beginner boilerplate
60
60
createTemplate (componentName , children ) {
61
- let output = ` `
62
- output += ` <div>\n `
61
+ // not sure why output was set up like this, was imputted into return statement
62
+ // using string literal
63
+ // let output = ``
64
+ // output += ` <div>\n`
63
65
let templateTagStr = this .writeTemplateTag (componentName)
64
- return ` <template>\n ${ output } ${ templateTagStr} </div>\n </template>`
66
+ return ` <template>\n <div> \n ${ templateTagStr} </div>\n </template>`
65
67
},
66
68
// Creates <template> boilerplate
67
69
writeTemplateTag (componentName ) {
@@ -132,16 +134,83 @@ export default {
132
134
},
133
135
// Creates boiler text for <script> and <style>
134
136
createBoiler (componentName , children ) {
135
- let str = ' '
137
+
138
+ // add import mapstate and mapactions if they exist
139
+ let imports = ' '
140
+ if (this .activeComponentObj .actions .length || this .activeComponentObj .state .length ){
141
+ imports += ' import { '
142
+ if (this .activeComponentObj .actions .length && this .activeComponentObj .state .length ) {
143
+ imports += ' mapState, mapActions'
144
+ }
145
+ else if (this .activeComponentObj .state .length ) imports += ' mapState'
146
+ else imports += ' mapActions'
147
+ imports += ' } from "vuex"\n '
148
+ }
149
+
150
+ // add imports for children
136
151
children .forEach (name => {
137
- str += ` import ${ name} from '@/components/${ name} .vue';\n `
152
+ imports += ` import ${ name} from '@/components/${ name} .vue';\n `
138
153
})
154
+
155
+ // add components section
139
156
let childrenComponentNames = ' '
140
157
children .forEach (name => {
141
158
childrenComponentNames += ` ${ name} ,\n `
142
159
})
160
+
161
+ // if true add data section and populate with props
162
+ let data = ' '
163
+ if (this .activeComponentObj .props .length ){
164
+ data += ' data () {\n return {'
165
+ this .activeComponentObj .props .forEach (prop => {
166
+ data += ` \n ${ prop} : "PLACEHOLDER FOR VALUE",`
167
+ })
168
+ data += ' \n '
169
+ data += ' }\n '
170
+ data += ' },\n '
171
+ }
172
+
173
+ // if true add computed section and populate with state
174
+ let computed = ' '
175
+ if (this .activeComponentObj .state .length ){
176
+ computed += ' computed: {'
177
+ computed += ' \n ...mapState(['
178
+ this .activeComponentObj .state .forEach ((state ) => {
179
+ computed += ` \n "${ state} ",`
180
+ })
181
+ computed += ' \n ]),\n '
182
+ computed += ' },\n '
183
+ }
184
+
185
+ // if true add methods section and populate with actions
186
+ let methods = ' '
187
+ if (this .activeComponentObj .actions .length ){
188
+ methods += ' methods: {'
189
+ methods += ' \n ...mapActions(['
190
+ this .activeComponentObj .actions .forEach ((action ) => {
191
+ methods += ` \n "${ action} ",`
192
+ })
193
+ methods += ' \n ]),\n '
194
+ methods += ' },\n '
195
+ }
196
+
197
+ // concat all code within script tags
198
+ let output = ' \n\n <script>\n '
199
+ output += imports + ' \n export default {\n name: ' + componentName
200
+ output += ' ,\n components: {\n '
201
+ output += childrenComponentNames + ' },\n '
202
+ output += data
203
+ output += computed
204
+ output += methods
205
+ output += ' };\n <\/ script>\n\n <style scoped>\n </style>'
206
+ // add props/data
207
+
208
+
143
209
// eslint-disable-next-line no-useless-escape
144
- return ` \n\n <script>\n ${ str} \n export default {\n name: '${ componentName} ',\n components: {\n ${ childrenComponentNames} }\n };\n <\/ script>\n\n <style scoped>\n </style>`
210
+ // return `\n\n<script>\n${str}\nexport default {\n name: '${componentName}',\n
211
+ // components: {\n${childrenComponentNames} }\n};\n<\/script>\n\n<style scoped>\n
212
+ // </style>`
213
+ return output
145
214
}
146
215
},
147
216
mounted () {
0 commit comments