diff --git a/build/genExamples.js b/build/genExamples.js new file mode 100644 index 000000000..36aa3bac1 --- /dev/null +++ b/build/genExamples.js @@ -0,0 +1,93 @@ +var markdownIt = require('markdown-it'); +var markdownItContainer = require('markdown-it-container'); +var fs = require('fs'); +var path = require('path'); +var cheerio = require('cheerio'); +var striptags = require('./strip-tags'); +var Components = require('../components.json'); + +var parser = markdownIt('default', { + html: true +}); + +var renderVueTemplate = function (html, componentName) { + var $ = cheerio.load(html, { + decodeEntities: false, + lowerCaseAttributeNames: false, + lowerCaseTags: false + }) + + var output = { + style: $.html('style'), + script: $.html('script'), + 'example-block': $.html('example-block') + } + var result + + $('style').remove() + $('script').remove() + + var script = ''; + if (output.script) { + script = output.script.replace(''; + } + + result = `\n' + + output.style + '\n' + + script; + + return result +} + +function convert(str) { + str = str.replace(/(&#x)(\w{4});/gi, function($0) { + return String.fromCharCode(parseInt(encodeURIComponent($0).replace(/(%26%23x)(\w{4})(%3B)/g, '$2'), 16)); + }); + return str; +} + +parser.use(markdownItContainer, 'demo', { + validate: function(params) { + return params.trim().match(/^demo\s*(.*)$/); + }, + + render: function(tokens, idx) { + var m = tokens[idx].info.trim().match(/^demo\s*(.*)$/); + if (tokens[idx].nesting === 1) { + var description = (m && m.length > 1) ? m[1] : ''; + var content = tokens[idx + 1].content; + var html = convert(striptags.strip(content, ['script', 'style'])); + + return ` + ${html} + \n`; + } + return ''; + } +}); + +var docsDir = path.resolve(__dirname, '../docs'); +for (var item in Components) { + var itemMdFile = `${docsDir}/examples-docs/${item}.md`; + if (!fs.existsSync(itemMdFile)) { + continue; + } + + var itemMd = fs.readFileSync(`${docsDir}/examples-docs/${item}.md`).toString(); + var content = parser.render(itemMd); + var result = renderVueTemplate(content, item); + + var exampleVueName = `${docsDir}/examples/${item}.vue`; + + if (!fs.existsSync(exampleVueName)) { + fs.closeSync(fs.openSync(exampleVueName, 'w')); + } + fs.writeFileSync(exampleVueName, result, { + encoding: 'utf8' + }); +} + +console.log('generate examples success!'); + diff --git a/docs/ExamplesApp.vue b/docs/ExamplesApp.vue index d939f4f6e..d252e9614 100644 --- a/docs/ExamplesApp.vue +++ b/docs/ExamplesApp.vue @@ -64,7 +64,7 @@ export default { } } - .page-title { + .demo-title { font-size: 20px; margin: 20px auto; text-align: center; @@ -72,8 +72,8 @@ export default { line-height: 1; } - .page-sub-title { + .demo-sub-title { font-size: 16px; - padding: 10px 0; + padding: 10px 15px; } diff --git a/docs/components/example-block.vue b/docs/components/example-block.vue new file mode 100644 index 000000000..742290f02 --- /dev/null +++ b/docs/components/example-block.vue @@ -0,0 +1,14 @@ + + + diff --git a/docs/examples-docs/badge.md b/docs/examples-docs/badge.md index 7490ccc20..5178c8a06 100644 --- a/docs/examples-docs/badge.md +++ b/docs/examples-docs/badge.md @@ -2,7 +2,7 @@ ### 基础用法 -:::demo +:::demo 基础用法 ```html diff --git a/docs/examples-docs/button.md b/docs/examples-docs/button.md index b4de07f6d..8f69387e6 100644 --- a/docs/examples-docs/button.md +++ b/docs/examples-docs/button.md @@ -39,7 +39,7 @@ ### 禁用状态 -:::demo +:::demo 禁用状态 ```html @@ -53,7 +53,7 @@ 只接受large, normal, small, mini四种尺寸,默认normal。 -:::demo +:::demo 按钮尺寸 ```html @@ -78,7 +78,7 @@ 按钮默认是button标签,可以使用tag属性修改为一个a标签。 -:::demo +:::demo 自定义按钮标签 ```html @@ -92,7 +92,7 @@ 表示loading状态 -:::demo +:::demo loading按钮 ```html @@ -109,7 +109,7 @@ 一组按钮。 -:::demo +:::demo button group ```html
确认付款 diff --git a/docs/examples-docs/card.md b/docs/examples-docs/card.md index 5220232bc..281fc69a1 100644 --- a/docs/examples-docs/card.md +++ b/docs/examples-docs/card.md @@ -4,7 +4,7 @@ 当没有底部按钮时,右侧内容会居中显示。 -:::demo +:::demo 基础用法 ```html @@ -33,7 +33,7 @@ export default { 传入`label`属性,属性值为描述信息的值。 -:::demo +:::demo 标题带描述信息 ```html @@ -46,7 +46,7 @@ export default { 传入`icon`属性。 -:::demo +:::demo 带图标 ```html @@ -59,7 +59,7 @@ export default { 传入`url`属性,传入`isLink`属性则会在右侧显示箭头。 -:::demo +:::demo 可点击的链接 ```html @@ -72,7 +72,7 @@ export default { 如以上用法不能满足你的需求,可以使用对应的`slot`来自定义显示的内容。包含三个`slot`,默认`slot`,`icon`和`title`的`slot`。 -:::demo +:::demo 高级用法 ```html diff --git a/docs/examples-docs/checkbox.md b/docs/examples-docs/checkbox.md index c8cabae7e..a1d07b536 100644 --- a/docs/examples-docs/checkbox.md +++ b/docs/examples-docs/checkbox.md @@ -39,7 +39,7 @@ export default { ### 基础用法 -:::demo +:::demo 基础用法 ```html
复选框1 @@ -59,7 +59,7 @@ export default { ### 禁用状态 -:::demo +:::demo 禁用状态 ```html
复选框2 @@ -79,7 +79,7 @@ export default { ### Checkbox组 -:::demo +:::demo Checkbox组 ```html
@@ -112,7 +112,7 @@ export default { ### 禁用Checkbox组 -:::demo +:::demo 禁用Checkbox组 ```html
@@ -139,7 +139,7 @@ export default { ### 与Cell组件一起使用 -:::demo +:::demo 与Cell组件一起使用 ```html diff --git a/docs/examples-docs/dialog.md b/docs/examples-docs/dialog.md index da4a96912..aa9c2e495 100644 --- a/docs/examples-docs/dialog.md +++ b/docs/examples-docs/dialog.md @@ -30,7 +30,7 @@ export default { ### 基础用法 -:::demo +:::demo 基础用法 ```html alert diff --git a/docs/examples-docs/field.md b/docs/examples-docs/field.md index 8516c48a2..bf78de558 100644 --- a/docs/examples-docs/field.md +++ b/docs/examples-docs/field.md @@ -6,7 +6,7 @@ 根据`type`属性显示不同的输入框。 -:::demo +:::demo 基础用法 ```html @@ -20,7 +20,7 @@ 不传入`label`属性即可。 -:::demo +:::demo 无label的输入框 ```html @@ -32,7 +32,7 @@ 监听组件的`change`事件。 -:::demo +:::demo 监听change事件 ```html diff --git a/docs/examples-docs/loading.md b/docs/examples-docs/loading.md index 46aabee91..bb3458293 100644 --- a/docs/examples-docs/loading.md +++ b/docs/examples-docs/loading.md @@ -21,7 +21,7 @@ ### 基础用法 -:::demo +:::demo 基础用法 ```html

渐变深色spinner

diff --git a/docs/examples-docs/panel.md b/docs/examples-docs/panel.md index f33211c0c..543292b01 100644 --- a/docs/examples-docs/panel.md +++ b/docs/examples-docs/panel.md @@ -35,7 +35,7 @@ ### 基础用法 -:::demo +:::demo 基础用法 ```html
@@ -49,7 +49,7 @@ 使用具名`slot`自定义内容。 -:::demo +:::demo 高级用法 ```html ``` diff --git a/docs/examples-docs/popup.md b/docs/examples-docs/popup.md index f28fe762d..c8096ab65 100644 --- a/docs/examples-docs/popup.md +++ b/docs/examples-docs/popup.md @@ -2,7 +2,7 @@ ### 基础用法 -:::demo +:::demo 基础用法 ```html
从下方弹出popup diff --git a/docs/examples-docs/radio.md b/docs/examples-docs/radio.md index 92e66068b..41685985a 100644 --- a/docs/examples-docs/radio.md +++ b/docs/examples-docs/radio.md @@ -29,7 +29,7 @@ export default { ### 基础用法 -:::demo +:::demo 基础用法 ```html
单选框1 @@ -50,7 +50,7 @@ export default { ### 禁用状态 -:::demo +:::demo 禁用状态 ```html
未选中禁用 @@ -71,7 +71,7 @@ export default { ### radio组 -:::demo +:::demo radio组 ```html
@@ -94,7 +94,7 @@ export default { ### 与Cell组件一起使用 -:::demo +:::demo 与Cell组件一起使用 ```html diff --git a/docs/examples-docs/search.md b/docs/examples-docs/search.md index af2d6505e..db18c7e76 100644 --- a/docs/examples-docs/search.md +++ b/docs/examples-docs/search.md @@ -12,7 +12,7 @@ export default { ### 基础用法 -:::demo +:::demo 基础用法 ```html \ No newline at end of file diff --git a/docs/examples/button.vue b/docs/examples/button.vue index 0c31c3bf1..ecbc26d0f 100644 --- a/docs/examples/button.vue +++ b/docs/examples/button.vue @@ -1,82 +1,81 @@ - + \ No newline at end of file diff --git a/docs/examples/card.vue b/docs/examples/card.vue index 8dbe6a4f0..e3ae90791 100644 --- a/docs/examples/card.vue +++ b/docs/examples/card.vue @@ -1,37 +1,24 @@ - + + \ No newline at end of file diff --git a/docs/examples/cell.vue b/docs/examples/cell.vue index 5180d5ccb..8973ac33d 100644 --- a/docs/examples/cell.vue +++ b/docs/examples/cell.vue @@ -1,45 +1,48 @@ - + - - + \ No newline at end of file diff --git a/docs/examples/checkbox.vue b/docs/examples/checkbox.vue index e4ac8b63f..d784aee41 100644 --- a/docs/examples/checkbox.vue +++ b/docs/examples/checkbox.vue @@ -1,38 +1,62 @@ - + - - + \ No newline at end of file diff --git a/docs/examples/dialog.vue b/docs/examples/dialog.vue index c4766c7c4..84234f0c7 100644 --- a/docs/examples/dialog.vue +++ b/docs/examples/dialog.vue @@ -1,19 +1,14 @@ - - - + \ No newline at end of file diff --git a/docs/examples/field.vue b/docs/examples/field.vue index 265090b22..af4575e8e 100644 --- a/docs/examples/field.vue +++ b/docs/examples/field.vue @@ -1,44 +1,21 @@ - - - +import Vue from "vue";import ExampleBlock from "../components/example-block";Vue.component("example-block", ExampleBlock); \ No newline at end of file diff --git a/docs/examples/image-preview.vue b/docs/examples/image-preview.vue index c7be82c6f..24e5d5956 100644 --- a/docs/examples/image-preview.vue +++ b/docs/examples/image-preview.vue @@ -1,30 +1,4 @@ - + +import Vue from "vue";import ExampleBlock from "../components/example-block";Vue.component("example-block", ExampleBlock); \ No newline at end of file diff --git a/docs/examples/layout.vue b/docs/examples/layout.vue deleted file mode 100644 index e69de29bb..000000000 diff --git a/docs/examples/loading.vue b/docs/examples/loading.vue index 35d406d04..ff83d7b07 100644 --- a/docs/examples/loading.vue +++ b/docs/examples/loading.vue @@ -1,28 +1,26 @@ - + \ No newline at end of file diff --git a/docs/examples/panel.vue b/docs/examples/panel.vue index f3bb9a73e..bdce2d348 100644 --- a/docs/examples/panel.vue +++ b/docs/examples/panel.vue @@ -1,80 +1,65 @@ - + \ No newline at end of file diff --git a/docs/examples/picker.vue b/docs/examples/picker.vue index d9d41f34b..8ba5993fe 100644 --- a/docs/examples/picker.vue +++ b/docs/examples/picker.vue @@ -1,13 +1,10 @@ - + \ No newline at end of file diff --git a/docs/examples/popup.vue b/docs/examples/popup.vue index 5fce33dd5..b7ca322c1 100644 --- a/docs/examples/popup.vue +++ b/docs/examples/popup.vue @@ -1,93 +1,35 @@ - - - +import Vue from "vue";import ExampleBlock from "../components/example-block";Vue.component("example-block", ExampleBlock); \ No newline at end of file diff --git a/docs/examples/radio.vue b/docs/examples/radio.vue index 780c71f39..c6e78c9b1 100644 --- a/docs/examples/radio.vue +++ b/docs/examples/radio.vue @@ -1,41 +1,55 @@ - + - - + \ No newline at end of file diff --git a/docs/examples/search.vue b/docs/examples/search.vue index 4f3893c13..0debad168 100644 --- a/docs/examples/search.vue +++ b/docs/examples/search.vue @@ -1,4 +1,11 @@ + + - - - - + \ No newline at end of file diff --git a/docs/examples/steps.vue b/docs/examples/steps.vue index 7c122680b..a9fc11a45 100644 --- a/docs/examples/steps.vue +++ b/docs/examples/steps.vue @@ -1,27 +1,39 @@ - + - - + \ No newline at end of file diff --git a/docs/examples/switch.vue b/docs/examples/switch.vue index 87c399acf..cf6776b7f 100644 --- a/docs/examples/switch.vue +++ b/docs/examples/switch.vue @@ -1,67 +1,44 @@ - + \ No newline at end of file diff --git a/docs/examples/tag.vue b/docs/examples/tag.vue index 0bcc78040..717c19bdc 100644 --- a/docs/examples/tag.vue +++ b/docs/examples/tag.vue @@ -1,47 +1,33 @@ - + \ No newline at end of file diff --git a/docs/examples/waterfall.vue b/docs/examples/waterfall.vue index 71b84f287..683d2b7ac 100644 --- a/docs/examples/waterfall.vue +++ b/docs/examples/waterfall.vue @@ -1,64 +1,18 @@ - - - +import Vue from "vue";import ExampleBlock from "../components/example-block";Vue.component("example-block", ExampleBlock); \ No newline at end of file