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 ?
- :
+ :
preview(React, ReactDOM)
}
{
diff --git a/site/theme/template/Layout/Footer.jsx b/site/theme/template/Layout/Footer.jsx
index c8167a7e54..a686769483 100644
--- a/site/theme/template/Layout/Footer.jsx
+++ b/site/theme/template/Layout/Footer.jsx
@@ -1,6 +1,6 @@
import React from 'react';
import { Select, Modal } from 'antd';
-import { version as antdVersion } from '../../../../package.json';
+import { version as antdVersion } from 'antd/package.json';
import { docVersions } from '../../';
const Option = Select.Option;
diff --git a/site/theme/template/Layout/index.jsx b/site/theme/template/Layout/index.jsx
index 91de01439c..45248fdca3 100644
--- a/site/theme/template/Layout/index.jsx
+++ b/site/theme/template/Layout/index.jsx
@@ -1,4 +1,5 @@
import React from 'react';
+import ReactDOM from 'react-dom';
import { addLocaleData, IntlProvider } from 'react-intl';
import Header from './Header';
import Footer from './Footer';
@@ -6,6 +7,11 @@ import enLocale from '../../en-US.js';
import cnLocale from '../../zh-CN.js';
import '../../static/style';
+// Expose to iframe
+window.react = React;
+window['react-dom'] = ReactDOM;
+window.antd = require('antd');
+
const isZhCN = (typeof localStorage !== 'undefined' && localStorage.getItem('locale') !== 'en-US');
// (typeof localStorage !== 'undefined' && localStorage.getItem('locale') === 'zh-CN') ||
// (navigator.language === 'zh-CN');