|
15 | 15 | </template> |
16 | 16 |
|
17 | 17 | <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' |
23 | 23 |
|
24 | 24 | export default { |
25 | | - data() { |
| 25 | + data () { |
26 | 26 | return { |
27 | 27 | code: `Your component boilerplate will be displayed here.`, |
28 | 28 | lineNumbers: true, |
29 | 29 | height: null |
30 | | - }; |
| 30 | + } |
31 | 31 | }, |
32 | 32 | components: { |
33 | 33 | PrismEditor |
34 | 34 | }, |
35 | 35 | computed: { |
36 | 36 | // needs access to current component aka activeComponent |
37 | | - ...mapState(["componentMap", "activeComponent"]) |
| 37 | + ...mapState(['componentMap', 'activeComponent']) |
38 | 38 | }, |
39 | 39 | methods: { |
40 | | - getWindowHeight(e) { |
| 40 | + getWindowHeight (e) { |
41 | 41 | 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 |
44 | 44 | }, |
45 | 45 | // calls createTemplate and createBoiler to generate snippet |
46 | | - createCodeSnippet(componentName, children) { |
| 46 | + createCodeSnippet (componentName, children) { |
47 | 47 | let result = `${this.createTemplate( |
48 | 48 | componentName, |
49 | 49 | children |
50 | | - )}${this.createBoiler(componentName, children)}`; |
51 | | - return result; |
| 50 | + )}${this.createBoiler(componentName, children)}` |
| 51 | + return result |
52 | 52 | }, |
53 | | - createTemplate(componentName, children) { |
54 | | - let output = ``; |
55 | | - output += ` <div>\n`; |
| 53 | + createTemplate (componentName, children) { |
| 54 | + let output = `` |
| 55 | + output += ` <div>\n` |
56 | 56 | children.forEach(name => { |
57 | | - output += ` <${name}>\n </${name}>\n`; |
58 | | - }); |
59 | | - let templateTagStr = this.writeTemplateTag(componentName); |
60 | | - return `<template>\n ${output}${templateTagStr} </div>\n</template>`; |
| 57 | + output += ` <${name}>\n </${name}>\n` |
| 58 | + }) |
| 59 | + let templateTagStr = this.writeTemplateTag(componentName) |
| 60 | + return `<template>\n ${output}${templateTagStr} </div>\n</template>` |
61 | 61 | }, |
62 | | - writeTemplateTag(componentName) { |
| 62 | + writeTemplateTag (componentName) { |
63 | 63 | // console.log('writeTemplateTag invoked!') |
64 | 64 | // create reference object |
65 | 65 | const htmlElementMap = { |
66 | | - div: ["<div>", "</div>"], |
67 | | - button: ["<button>", "</button>"], |
68 | | - form: ["<form>", "</form>"], |
69 | | - img: ["<img>", ""], |
70 | | - link: ['<a href="#"/>', ""], |
71 | | - list: ["<li>", "</li>"], |
72 | | - paragraph: ["<p>", "</p>"], |
73 | | - "list-ol": ["<ol>", "</ol>"], |
74 | | - "list-ul": ["<ul>", "</ul>"], |
75 | | - input: ["<input />", ""], |
76 | | - navbar: ["<nav>", "</nav>"] |
77 | | - }; |
| 66 | + div: ['<div>', '</div>'], |
| 67 | + button: ['<button>', '</button>'], |
| 68 | + form: ['<form>', '</form>'], |
| 69 | + img: ['<img>', ''], |
| 70 | + link: ['<a href="#"/>', ''], |
| 71 | + list: ['<li>', '</li>'], |
| 72 | + paragraph: ['<p>', '</p>'], |
| 73 | + 'list-ol': ['<ol>', '</ol>'], |
| 74 | + 'list-ul': ['<ul>', '</ul>'], |
| 75 | + input: ['<input />', ''], |
| 76 | + navbar: ['<nav>', '</nav>'] |
| 77 | + } |
78 | 78 | // loop to iterate through compName arr |
79 | | - let htmlArr = this.componentMap[componentName].htmlList; |
80 | | - let outputStr = ``; |
| 79 | + let htmlArr = this.componentMap[componentName].htmlList |
| 80 | + let outputStr = `` |
81 | 81 | for (let el of htmlArr) { |
82 | | - outputStr += ` `; |
83 | | - outputStr += htmlElementMap[el.text][0]; |
84 | | - outputStr += htmlElementMap[el.text][1]; |
85 | | - outputStr += ` \n`; |
| 82 | + outputStr += ` ` |
| 83 | + outputStr += htmlElementMap[el.text][0] |
| 84 | + outputStr += htmlElementMap[el.text][1] |
| 85 | + outputStr += ` \n` |
86 | 86 | } |
87 | 87 | // console.log(`outputStr from writeTemplateTag: ${outputStr}`) |
88 | | - return outputStr; |
| 88 | + return outputStr |
89 | 89 | }, |
90 | | - createBoiler(componentName, children) { |
91 | | - let str = ""; |
| 90 | + createBoiler (componentName, children) { |
| 91 | + let str = '' |
92 | 92 | children.forEach(name => { |
93 | | - str += `import ${name} from '@/components/${name}.vue';\n`; |
94 | | - }); |
95 | | - let childrenComponentNames = ""; |
| 93 | + str += `import ${name} from '@/components/${name}.vue';\n` |
| 94 | + }) |
| 95 | + let childrenComponentNames = '' |
96 | 96 | children.forEach(name => { |
97 | | - childrenComponentNames += ` ${name},\n`; |
98 | | - }); |
99 | | - return `\n\n<script>\n${str}\nexport default {\n name: '${componentName}',\n components: {\n${childrenComponentNames} }\n};\n<\/script>\n\n<style scoped>\n</style>`; |
| 97 | + childrenComponentNames += ` ${name},\n` |
| 98 | + }) |
| 99 | + return `\n\n<script>\n${str}\nexport default {\n name: '${componentName}',\n components: {\n${childrenComponentNames} }\n};\n<\/script>\n\n<style scoped>\n</style>` |
100 | 100 | } |
101 | 101 | }, |
102 | | - mounted() { |
| 102 | + mounted () { |
103 | 103 | // https://vuejs.org/v2/api/#Vue-nextTick |
104 | 104 | // kinda like a promise, used for the window resize |
105 | 105 | this.$nextTick(() => { |
106 | | - window.addEventListener("resize", this.getWindowHeight); |
| 106 | + window.addEventListener('resize', this.getWindowHeight) |
107 | 107 |
|
108 | | - this.getWindowHeight(); |
109 | | - }); |
| 108 | + this.getWindowHeight() |
| 109 | + }) |
110 | 110 | }, |
111 | 111 | // updates code snippet, but broken cause children undefined, shows `function () { [native code] }` |
112 | | - updated() { |
| 112 | + updated () { |
113 | 113 | // console.log(`code: ${this.createCodeSnippet(this.activeComponent, this.componentMap[this.activeComponent].children)}`) |
114 | 114 | this.code = `${this.createCodeSnippet( |
115 | 115 | this.activeComponent, |
116 | 116 | this.componentMap[this.activeComponent].children |
117 | | - )}`; |
| 117 | + )}` |
118 | 118 | }, |
119 | | - beforeDestroy() { |
120 | | - window.removeEventListener("resize", this.getWindowHeight); |
| 119 | + beforeDestroy () { |
| 120 | + window.removeEventListener('resize', this.getWindowHeight) |
121 | 121 | } |
122 | | -}; |
| 122 | +} |
123 | 123 | </script> |
124 | 124 |
|
125 | 125 | <style lang="stylus" scoped> |
|
0 commit comments