diff --git a/components/locale-provider/demo/all.md b/components/locale-provider/demo/all.md index 4253a82107..22bb973090 100644 --- a/components/locale-provider/demo/all.md +++ b/components/locale-provider/demo/all.md @@ -9,7 +9,6 @@ title: 所有组件 import { LocaleProvider, Pagination, DatePicker, TimePicker, Calendar, Popconfirm, Table, Modal, Button, Select, Transfer, Radio } from 'antd'; import enUS from 'antd/lib/locale-provider/en_US'; -import ruRU from 'antd/lib/locale-provider/ru_RU'; const Option = Select.Option; const RangePicker = DatePicker.RangePicker; @@ -110,7 +109,6 @@ const App = React.createClass({ Change locale of components: English - русский язык 中文 diff --git a/site/bisheng-plugin-antd/lib/process-demo.js b/site/bisheng-plugin-antd/lib/process-demo.js index f42018acf8..4a6c4e14c2 100644 --- a/site/bisheng-plugin-antd/lib/process-demo.js +++ b/site/bisheng-plugin-antd/lib/process-demo.js @@ -1,4 +1,20 @@ +const fs = require('fs'); +const path = require('path'); const JsonML = require('jsonml.js/lib/utils'); +const pkgPath = path.join(process.cwd(), 'package.json'); +const pkgName = require(pkgPath).name; + +const nunjucks = require('nunjucks'); +nunjucks.configure({ autoescape: false }); + +const babel = require('babel-core'); +const babelrc = { + presets: ['es2015', 'react'].map((m) => { + return require.resolve(`babel-preset-${m}`); + }), +}; + +const tmpl = fs.readFileSync(path.join(__dirname, 'template.html')).toString(); function isStyleTag(node) { return node && JsonML.getTagName(node) === 'style'; @@ -37,9 +53,16 @@ module.exports = (markdownData) => { } markdownData.highlightedCode = contentChildren[codeIndex].slice(0, 2); - markdownData.preview = [ + const preview = [ 'pre', { lang: '__react' }, - ].concat(JsonML.getChildren(contentChildren[codeIndex])); + ]; + const componentsPath = path.join(process.cwd(), 'components'); + preview.push([ + 'code', + getCode(contentChildren[codeIndex]) + .replace(`${pkgName}/lib`, componentsPath), + ]); + markdownData.preview = preview; const styleNode = contentChildren.find((node) => { return isStyleTag(node) || @@ -52,5 +75,16 @@ module.exports = (markdownData) => { markdownData.highlightedStyle = JsonML.getAttributes(styleNode).highlighted; } + if (meta.iframe) { + const html = nunjucks.renderString(tmpl, { + id: meta.id, + style: markdownData.style, + script: babel.transform(getCode(markdownData.preview), babelrc).code, + }); + const fileName = `demo-${Math.random()}.html`; + fs.writeFile(path.join(process.cwd(), '_site', fileName), html); + markdownData.src = path.join('/', fileName); + } + return markdownData; }; diff --git a/site/bisheng-plugin-antd/lib/template.html b/site/bisheng-plugin-antd/lib/template.html new file mode 100644 index 0000000000..10ffe57299 --- /dev/null +++ b/site/bisheng-plugin-antd/lib/template.html @@ -0,0 +1,34 @@ + + + + Demo + + + + +
+ + + + + diff --git a/site/theme/template/Content/Demo.jsx b/site/theme/template/Content/Demo.jsx index c2d7226a32..a5cd27c925 100644 --- a/site/theme/template/Content/Demo.jsx +++ b/site/theme/template/Content/Demo.jsx @@ -1,7 +1,6 @@ import React from 'react'; import ReactDOM from 'react-dom'; import classNames from 'classnames'; -const isLocal = location.port; export default class Demo extends React.Component { static contextTypes = { @@ -61,7 +60,7 @@ export default class Demo extends React.Component {
{ meta.iframe ? -