Skip to content

Commit 3b1a198

Browse files
Merge pull request #19 from ziggrace/sean/snippet
Sean/snippet
2 parents 0f893b8 + cbba2e2 commit 3b1a198

File tree

2 files changed

+86
-19
lines changed

2 files changed

+86
-19
lines changed

src/components/dashboard_items/CodeSnippet.vue

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,6 @@ export default {
4141
computed: {
4242
// needs access to current component aka activeComponent
4343
...mapState(['componentMap', 'activeComponent', 'activeComponentObj']),
44-
activeObj (){
45-
return this.activeComponentObj
46-
}
4744
},
4845
methods: {
4946
getWindowHeight (e) {
@@ -60,7 +57,7 @@ export default {
6057
return result
6158
},
6259
// Creates beginner boilerplate
63-
createTemplate (componentName, children) {
60+
createTemplate (componentName) {
6461
// not sure why output was set up like this, was imputted into return statement
6562
// using string literal
6663
// let output = ``
@@ -140,12 +137,12 @@ export default {
140137
141138
// add import mapstate and mapactions if they exist
142139
let imports = ''
143-
if (this.activeObj.actions.length || this.activeObj.state.length){
140+
if (this.activeComponentObj.actions.length || this.activeComponentObj.state.length){
144141
imports += 'import { '
145-
if (this.activeObj.actions.length && this.activeObj.state.length) {
142+
if (this.activeComponentObj.actions.length && this.activeComponentObj.state.length) {
146143
imports += 'mapState, mapActions'
147144
}
148-
else if (this.activeObj.state.length) imports += 'mapState'
145+
else if (this.activeComponentObj.state.length) imports += 'mapState'
149146
else imports += 'mapActions'
150147
imports += ' } from "vuex"\n'
151148
}
@@ -163,9 +160,9 @@ export default {
163160
164161
// if true add data section and populate with props
165162
let data = ''
166-
if (this.activeObj.props.length){
163+
if (this.activeComponentObj.props.length){
167164
data += ' data () {\n return {'
168-
this.activeObj.props.forEach(prop => {
165+
this.activeComponentObj.props.forEach(prop => {
169166
data += `\n ${prop}: "PLACEHOLDER FOR VALUE",`
170167
})
171168
data += '\n'
@@ -175,10 +172,10 @@ export default {
175172
176173
// if true add computed section and populate with state
177174
let computed = ''
178-
if (this.activeObj.state.length){
175+
if (this.activeComponentObj.state.length){
179176
computed += ' computed: {'
180177
computed += '\n ...mapState(['
181-
this.activeObj.state.forEach((state) =>{
178+
this.activeComponentObj.state.forEach((state) =>{
182179
computed += `\n "${state}",`
183180
})
184181
computed += '\n ]),\n'
@@ -187,10 +184,10 @@ export default {
187184
188185
// if true add methods section and populate with actions
189186
let methods = ''
190-
if (this.activeObj.actions.length){
187+
if (this.activeComponentObj.actions.length){
191188
methods += ' methods: {'
192189
methods += '\n ...mapActions(['
193-
this.activeObj.actions.forEach((action) => {
190+
this.activeComponentObj.actions.forEach((action) => {
194191
methods += `\n "${action}",`
195192
})
196193
methods += '\n ]),\n'

src/components/file_system_interface/ExportProject.vue

Lines changed: 76 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -223,17 +223,87 @@ export default {
223223
* @description imports child components into <script>
224224
*/
225225
writeScript (componentName, children) {
226-
let str = ''
226+
// let str = ''
227+
// children.forEach(name => {
228+
// str += `import ${name} from '@/components/${name}.vue';\n`
229+
// })
230+
// let childrenComponentNames = ''
231+
// children.forEach(name => {
232+
// childrenComponentNames += `\t\t${name},\n`
233+
// })
234+
// return `\n\n<script>\n${str}\nexport default {\n\tname: '${componentName}'
235+
// ,\n\tcomponents: {\n${childrenComponentNames}\t}\n};\n<\/script>`
236+
// },
237+
// add import mapstate and mapactions if they exist
238+
let imports = ''
239+
if (this.activeComponentObj.actions.length || this.activeComponentObj.state.length){
240+
imports += 'import { '
241+
if (this.activeComponentObj.actions.length && this.activeComponentObj.state.length) {
242+
imports += 'mapState, mapActions'
243+
}
244+
else if (this.activeComponentObj.state.length) imports += 'mapState'
245+
else imports += 'mapActions'
246+
imports += ' } from "vuex"\n'
247+
}
248+
249+
// add imports for children
227250
children.forEach(name => {
228-
str += `import ${name} from '@/components/${name}.vue';\n`
251+
imports += `import ${name} from '@/components/${name}.vue';\n`
229252
})
253+
254+
// add components section
230255
let childrenComponentNames = ''
231256
children.forEach(name => {
232-
childrenComponentNames += `\t\t${name},\n`
257+
childrenComponentNames += ` ${name},\n`
233258
})
234-
return `\n\n<script>\n${str}\nexport default {\n\tname: '${componentName}',\n\tcomponents: {\n${childrenComponentNames}\t}\n};\n<\/script>`
235-
},
236259
260+
// if true add data section and populate with props
261+
let data = ''
262+
if (this.activeComponentObj.props.length){
263+
data += ' data () {\n return {'
264+
this.activeComponentObj.props.forEach(prop => {
265+
data += `\n ${prop}: "PLACEHOLDER FOR VALUE",`
266+
})
267+
data += '\n'
268+
data += ' }\n'
269+
data += ' },\n'
270+
}
271+
272+
// if true add computed section and populate with state
273+
let computed = ''
274+
if (this.activeComponentObj.state.length){
275+
computed += ' computed: {'
276+
computed += '\n ...mapState(['
277+
this.activeComponentObj.state.forEach((state) =>{
278+
computed += `\n "${state}",`
279+
})
280+
computed += '\n ]),\n'
281+
computed += ' },\n'
282+
}
283+
284+
// if true add methods section and populate with actions
285+
let methods = ''
286+
if (this.activeComponentObj.actions.length){
287+
methods += ' methods: {'
288+
methods += '\n ...mapActions(['
289+
this.activeComponentObj.actions.forEach((action) => {
290+
methods += `\n "${action}",`
291+
})
292+
methods += '\n ]),\n'
293+
methods += ' },\n'
294+
}
295+
296+
// concat all code within script tags
297+
let output = '\n\n<script>\n'
298+
output += imports + '\nexport default {\n name: ' + componentName
299+
output += ',\n components: {\n'
300+
output += childrenComponentNames + ' },\n'
301+
output += data
302+
output += computed
303+
output += methods
304+
output += '};\n<\/script>'
305+
return output
306+
},
237307
/**
238308
* @description writes the <style> in vue component
239309
* if component is 'App', writes css, else returns <style scoped>
@@ -402,7 +472,7 @@ export default {
402472
}
403473
},
404474
computed: {
405-
...mapState(['componentMap', 'imagePath'])
475+
...mapState(['componentMap', 'imagePath', 'activeComponentObj'])
406476
}
407477
}
408478

0 commit comments

Comments
 (0)