Skip to content

Commit 6c45903

Browse files
authored
Merge pull request #19 from allisons11/routeDeletion3
Route deletion
2 parents 14f5c04 + 82708ee commit 6c45903

12 files changed

+513
-509
lines changed

src/components/CodeSnippet.vue

Lines changed: 87 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -15,55 +15,54 @@
1515
</template>
1616

1717
<script>
18-
import { mapState } from 'vuex';
19-
import PrismEditor from 'vue-prism-editor';
20-
import 'prismjs';
21-
import 'prismjs/themes/prism-okaidia.css';
22-
import 'vue-prism-editor/dist/VuePrismEditor.css';
18+
import { mapState } from 'vuex'
19+
import PrismEditor from 'vue-prism-editor'
20+
import 'prismjs'
21+
import 'prismjs/themes/prism-okaidia.css'
22+
import 'vue-prism-editor/dist/VuePrismEditor.css'
2323
2424
export default {
25-
data() {
25+
data () {
2626
return {
2727
code: `Your component boilerplate will be displayed here.`,
2828
lineNumbers: true,
29-
height: null,
30-
};
29+
height: null
30+
}
3131
},
3232
components: {
33-
PrismEditor,
33+
PrismEditor
3434
},
3535
computed: {
3636
// needs access to current component aka activeComponent
37-
...mapState(['componentMap', 'activeComponent']),
37+
...mapState(['componentMap', 'activeComponent'])
3838
},
3939
methods: {
40-
getWindowHeight(e) {
40+
getWindowHeight (e) {
4141
let minHeight =
42-
window.outerHeight < 900 ? 22 : window.outerHeight < 1035 ? 24 : 27.5;
43-
this.height = minHeight;
42+
window.outerHeight < 900 ? 22 : window.outerHeight < 1035 ? 24 : 27.5
43+
this.height = minHeight
4444
},
4545
// calls createTemplate and createBoiler to generate snippet
46-
createCodeSnippet(componentName, children) {
46+
createCodeSnippet (componentName, children) {
4747
let result = `${this.createTemplate(
4848
componentName,
4949
children
50-
)}${this.createBoiler(componentName, children)}`;
51-
return result;
50+
)}${this.createBoiler(componentName, children)}`
51+
return result
5252
},
53-
createTemplate(componentName, children) {
54-
let output = ``;
55-
output += ` <div>\n`;
53+
createTemplate (componentName, children) {
54+
let output = ``
55+
output += ` <div>\n`
5656
// children.forEach(name => {
5757
// output += ` <${name}>\n </${name}>\n`;
5858
// });
59-
let templateTagStr = this.writeTemplateTag(componentName);
60-
return `<template>\n ${output}${templateTagStr} </div>\n</template>`;
59+
let templateTagStr = this.writeTemplateTag(componentName)
60+
return `<template>\n ${output}${templateTagStr} </div>\n</template>`
6161
},
6262
6363
// We need a helper function to recursively iterate through the given html element's children and their children's children.
6464
65-
66-
writeTemplateTag(componentName) {
65+
writeTemplateTag (componentName) {
6766
// console.log('writeTemplateTag invoked!')
6867
// create reference object
6968
const htmlElementMap = {
@@ -77,120 +76,115 @@ export default {
7776
'list-ol': ['<ol>', '</ol>'],
7877
'list-ul': ['<ul>', '</ul>'],
7978
input: ['<input />', ''],
80-
navbar: ['<nav>', '</nav>'],
81-
};
82-
83-
function writeNested(childrenArray, indent){
84-
if(!childrenArray.length){
85-
return ''
79+
navbar: ['<nav>', '</nav>']
8680
}
87-
let indented = indent + ' '
88-
let nestedString = ''
8981
90-
childrenArray.forEach(child => {
91-
nestedString += indented
92-
//console.log(child)
93-
if(!child.text){
94-
nestedString += `<${child}/>\n`
95-
}
96-
else{
97-
if(child.children.length){
98-
nestedString += htmlElementMap[child.text][0]
99-
nestedString += '\n';
100-
nestedString += writeNested(child.children,indented)
101-
nestedString += indented + htmlElementMap[child.text][1]
102-
nestedString += '\n'
103-
}
104-
else{
105-
nestedString += htmlElementMap[child.text][0]+htmlElementMap[child.text][1]+'\n';
106-
}
82+
function writeNested (childrenArray, indent) {
83+
if (!childrenArray.length) {
84+
return ''
10785
}
108-
})
109-
return nestedString
110-
}
86+
let indented = indent + ' '
87+
let nestedString = ''
11188
89+
childrenArray.forEach(child => {
90+
nestedString += indented
91+
// console.log(child)
92+
if (!child.text) {
93+
nestedString += `<${child}/>\n`
94+
} else {
95+
if (child.children.length) {
96+
nestedString += htmlElementMap[child.text][0]
97+
nestedString += '\n'
98+
nestedString += writeNested(child.children, indented)
99+
nestedString += indented + htmlElementMap[child.text][1]
100+
nestedString += '\n'
101+
} else {
102+
nestedString += htmlElementMap[child.text][0] + htmlElementMap[child.text][1] + '\n'
103+
}
104+
}
105+
})
106+
return nestedString
107+
}
112108
113109
// loop to iterate through compName arr
114-
let htmlArr = this.componentMap[componentName].htmlList;
115-
let outputStr = ``;
110+
let htmlArr = this.componentMap[componentName].htmlList
111+
let outputStr = ``
116112
for (let el of htmlArr) {
117-
//console.log(el)
118-
if(!el.text){
113+
// console.log(el)
114+
if (!el.text) {
119115
outputStr += ` <${el}/>\n`
120-
}
121-
else{
122-
outputStr += ` `;
123-
if(el.children.length){
124-
outputStr += htmlElementMap[el.text][0];
125-
outputStr += '\n'
126-
outputStr += writeNested(el.children,` `)
116+
} else {
127117
outputStr += ` `
128-
outputStr += htmlElementMap[el.text][1];
129-
outputStr += ` \n`;
130-
}
131-
else{
132-
outputStr += htmlElementMap[el.text][0]+htmlElementMap[el.text][1]+'\n';
118+
if (el.children.length) {
119+
outputStr += htmlElementMap[el.text][0]
120+
outputStr += '\n'
121+
outputStr += writeNested(el.children, ` `)
122+
outputStr += ` `
123+
outputStr += htmlElementMap[el.text][1]
124+
outputStr += ` \n`
125+
} else {
126+
outputStr += htmlElementMap[el.text][0] + htmlElementMap[el.text][1] + '\n'
133127
}
134128
}
135129
}
136130
// console.log(`outputStr from writeTemplateTag: ${outputStr}`)
137-
return outputStr;
131+
return outputStr
138132
},
139-
createBoiler(componentName, children) {
140-
let str = '';
133+
createBoiler (componentName, children) {
134+
let str = ''
141135
children.forEach(name => {
142-
str += `import ${name} from '@/components/${name}.vue';\n`;
143-
});
144-
let childrenComponentNames = '';
136+
str += `import ${name} from '@/components/${name}.vue';\n`
137+
})
138+
let childrenComponentNames = ''
145139
children.forEach(name => {
146-
childrenComponentNames += ` ${name},\n`;
147-
});
148-
return `\n\n<script>\n${str}\nexport default {\n name: '${componentName}',\n components: {\n${childrenComponentNames} }\n};\n<\/script>\n\n<style scoped>\n</style>`;
149-
},
140+
childrenComponentNames += ` ${name},\n`
141+
})
142+
return `\n\n<script>\n${str}\nexport default {\n name: '${componentName}',\n components: {\n${childrenComponentNames} }\n};\n<\/script>\n\n<style scoped>\n</style>`
143+
}
150144
},
151-
mounted() {
145+
mounted () {
152146
// https://vuejs.org/v2/api/#Vue-nextTick
153147
// kinda like a promise, used for the window resize
154148
this.$nextTick(() => {
155-
window.addEventListener('resize', this.getWindowHeight);
149+
window.addEventListener('resize', this.getWindowHeight)
156150
157-
this.getWindowHeight();
158-
});
151+
this.getWindowHeight()
152+
})
159153
},
160154
// updates code snippet, but broken cause children undefined, shows `function () { [native code] }`
161-
updated() {
155+
updated () {
162156
// console.log(`code: ${this.createCodeSnippet(this.activeComponent, this.componentMap[this.activeComponent].children)}`)
163157
// console.log('component map: ', this.componentMap);
164158
if (this.componentMap[this.activeComponent]) {
165159
this.code = `${this.createCodeSnippet(
166160
this.activeComponent,
167161
this.componentMap[this.activeComponent].children
168-
)}`;
162+
)}`
169163
} else {
170-
this.code = `Your component boilerplate will be displayed here.`;
164+
this.code = `Your component boilerplate will be displayed here.`
171165
}
172166
},
173-
beforeDestroy() {
174-
window.removeEventListener('resize', this.getWindowHeight);
167+
beforeDestroy () {
168+
window.removeEventListener('resize', this.getWindowHeight)
175169
},
176170
watch: {
177171
componentMap: {
178172
deep: true,
179-
handler() {
173+
handler () {
180174
// console.log('component Map has changed');
181175
if (this.componentMap[this.activeComponent]) {
182176
this.code = `${this.createCodeSnippet(
183177
this.activeComponent,
184178
this.componentMap[this.activeComponent].children
185-
)}`;
179+
)}`
186180
}
187-
},
181+
}
188182
},
189-
activeComponent: function() {
183+
activeComponent: function () {
190184
// console.log('watching active component');
191-
},
192-
},
193-
};
185+
}
186+
}
187+
}
194188
</script>
195189

196190
<style lang="stylus" scoped>

0 commit comments

Comments
 (0)