Skip to content

Commit

Permalink
Revert "Revert "refactor with bisheng""
Browse files Browse the repository at this point in the history
This reverts commit 7a07b12.
  • Loading branch information
RaoHai committed May 27, 2016
1 parent b7f1c40 commit ff31a5b
Show file tree
Hide file tree
Showing 72 changed files with 742 additions and 726 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@ nohup.out
_site
_data
dist
lib
/lib
elasticsearch-*
config/base.yaml
9 changes: 0 additions & 9 deletions 404.html

This file was deleted.

2 changes: 1 addition & 1 deletion components/icon/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ english: Icon
### 一. 方向性图标

```__react
import IconSet from '../../site/component/IconSet';
import IconSet from 'site/theme/template/IconSet';
const icons1 = ['step-backward', 'step-forward', 'fast-backward', 'fast-forward', 'shrink', 'arrow-salt', 'down', 'up', 'left', 'right', 'caret-down', 'caret-up', 'caret-left', 'caret-right', 'caret-circle-right', 'caret-circle-left', 'caret-circle-o-right', 'caret-circle-o-left', 'circle-right', 'circle-left', 'circle-o-right', 'circle-o-left', 'double-right', 'double-left', 'verticle-right', 'verticle-left', 'forward', 'backward', 'rollback', 'enter', 'retweet', 'swap', 'swap-left', 'swap-right', 'arrow-right', 'arrow-up', 'arrow-down', 'arrow-left', 'play-circle', 'play-circle-o', 'circle-up', 'circle-down', 'circle-o-up', 'circle-o-down', 'caret-circle-o-up', 'caret-circle-o-down', 'caret-circle-up', 'caret-circle-down'];
ReactDOM.render(<IconSet className="icons" icons={icons1} key="icons1" />, mountNode);
Expand Down
4 changes: 2 additions & 2 deletions components/input-number/demo/digit.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
- order: 3
- title: 小数
order: 3
title: 小数
---

和原生的数字输入框一样,value 的精度由 step 的小数位数决定。
Expand Down
2 changes: 0 additions & 2 deletions components/locale-provider/demo/all.md
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -110,7 +109,6 @@ const App = React.createClass({
<span style={{ marginRight: 16 }}>Change locale of components: </span>
<Radio.Group defaultValue={enUS} onChange={this.changeLocale}>
<Radio.Button key="en" value={enUS}>English</Radio.Button>
<Radio.Button key="ru" value={ruRU}>русский язык</Radio.Button>
<Radio.Button key="cn">中文</Radio.Button>
</Radio.Group>
</div>
Expand Down
1 change: 1 addition & 0 deletions docs/spec/colors.md
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ ReactDOM.render(<ExtendPalettes key="palettes" />, mountNode);
`````__react
const Values = require('values.js');
const CopyToClipboard = require('react-copy-to-clipboard');
const antd = require('antd');
const Button = antd.Button;
const InputNumber = antd.InputNumber;
const Slider = antd.Slider;
Expand Down
2 changes: 1 addition & 1 deletion docs/spec/layout/demo/aside-collapse.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ title: 可收起展开的侧边导航

````jsx
import { Menu, Breadcrumb, Icon } from 'antd';
import BrowserDemo from 'site/component/BrowserDemo';
import BrowserDemo from 'site/theme/template/BrowserDemo';
const SubMenu = Menu.SubMenu;

const AsideCollapse = React.createClass({
Expand Down
2 changes: 1 addition & 1 deletion docs/spec/layout/demo/aside.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ title: 侧边导航

````jsx
import { Menu, Breadcrumb, Icon } from 'antd';
import BrowserDemo from 'site/component/BrowserDemo';
import BrowserDemo from 'site/theme/template/BrowserDemo';
const SubMenu = Menu.SubMenu;

ReactDOM.render(
Expand Down
2 changes: 1 addition & 1 deletion docs/spec/layout/demo/ceiling.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ title: 吊顶规范

````jsx
import { Menu, Breadcrumb } from 'antd';
import BrowserDemo from 'site/component/BrowserDemo';
import BrowserDemo from 'site/theme/template/BrowserDemo';

ReactDOM.render(
<BrowserDemo>
Expand Down
2 changes: 1 addition & 1 deletion docs/spec/layout/demo/top-aside.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ title: 顶部导航 + 侧边栏

````jsx
import { Menu, Breadcrumb, Icon } from 'antd';
import BrowserDemo from 'site/component/BrowserDemo';
import BrowserDemo from 'site/theme/template/BrowserDemo';
const SubMenu = Menu.SubMenu;

ReactDOM.render(
Expand Down
2 changes: 1 addition & 1 deletion docs/spec/layout/demo/top.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ title: 顶部导航
````jsx
import { Menu, Breadcrumb } from 'antd';
import BrowserDemo from 'site/component/BrowserDemo';
import BrowserDemo from 'site/theme/template/BrowserDemo';

ReactDOM.render(
<BrowserDemo>
Expand Down
1 change: 1 addition & 0 deletions docs/spec/motion.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ english: Motion
`````__react
const cssAnimation = require('css-animation');
const antd = require('antd');
const Select = antd.Select;
const Option = Select.Option;
const OptGroup = Select.OptGroup;
Expand Down
7 changes: 6 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@
"babel-eslint": "^6.0.2",
"babel-jest": "^12.0.2",
"babel-plugin-antd": "^0.4.0",
"bisheng": "^0.5.0",
"bisheng-plugin-description": "^0.1.1",
"bisheng-plugin-react": "^0.1.0",
"bisheng-plugin-toc": "0.2.0",
"dom-scroll-into-view": "^1.1.0",
"enquire.js": "^2.1.1",
"es6-shim": "^0.35.0",
Expand Down Expand Up @@ -104,6 +108,7 @@
"react": "^15.0.0",
"react-addons-test-utils": "^15.0.0",
"react-copy-to-clipboard": "^4.0.1",
"react-document-title": "^2.0.1",
"react-dom": "^15.0.0",
"react-github-button": "^0.1.1",
"react-intl": "^2.0.1",
Expand All @@ -118,7 +123,7 @@
"dist": "antd-tools run dist",
"compile": "antd-tools run compile",
"clean": "antd-tools run clean",
"start": "antd-tools run start",
"start": "bisheng start -c ./site/bisheng.config.js",
"site": "antd-tools run site",
"pre-deploy": "cp CNAME _site && rsync -R components/*/demo/*.json _site",
"deploy": "antd-tools run update-self && antd-tools run deploy",
Expand Down
File renamed without changes.
File renamed without changes.
50 changes: 50 additions & 0 deletions site/bisheng-plugin-antd/lib/browser.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
const React = require('react');
const Link = require('react-router').Link;
const toReactComponent = require('jsonml-to-react-component');
const JsonML = require('jsonml.js/lib/utils');
const VideoPlayer = require('./VideoPlayer');
const ImagePreview = require('./ImagePreview');

function isHeading(node) {
return /h[1-6]/i.test(JsonML.getTagName(node));
}

module.exports = () => {
return {
converters: [
[(node) => JsonML.isElement(node) && isHeading(node), (node, index) => {
const children = JsonML.getChildren(node);
return React.createElement(JsonML.getTagName(node), {
key: index,
id: children,
...JsonML.getAttributes(node),
}, [
<span key="title">{children.map((child) => toReactComponent(child))}</span>,
<a href={`#${children}`} className="anchor" key="anchor">#</a>,
]);
}],
[(node) => JsonML.isElement(node) && JsonML.getTagName(node) === 'video', (node, index) =>
<VideoPlayer video={JsonML.getAttributes(node)} key={index} />,
],
[(node) => JsonML.isElement(node) && JsonML.getTagName(node) === 'a' && !(
JsonML.getAttributes(node).class ||
(JsonML.getAttributes(node).href &&
JsonML.getAttributes(node).href.indexOf('http') === 0) ||
/^#/.test(JsonML.getAttributes(node).href)
), (node, index) => {
return <Link to={JsonML.getAttributes(node).href} key={index}>{toReactComponent(JsonML.getChildren(node)[0])}</Link>;
}],
[(node) => {
return JsonML.isElement(node) &&
JsonML.getTagName(node) === 'p' &&
JsonML.getTagName(JsonML.getChildren(node)[0]) === 'img' &&
/preview-img/gi.test(JsonML.getAttributes(JsonML.getChildren(node)[0]).class);
}, (node, index) => {
const imgs = JsonML.getChildren(node)
.filter((img) => JsonML.isElement(img) && Object.keys(JsonML.getAttributes(img)).length > 0)
.map((img) => JsonML.getAttributes(img));
return <ImagePreview imgs={imgs} key={index} />;
}],
],
};
};
11 changes: 11 additions & 0 deletions site/bisheng-plugin-antd/lib/node.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const path = require('path');
const processDoc = require('./process-doc');
const processDemo = require('./process-demo');

module.exports = (markdownData) => {
const isDemo = path.dirname(markdownData.meta.filename).endsWith('/demo');
if (isDemo) {
return processDemo(markdownData);
}
return processDoc(markdownData);
};
90 changes: 90 additions & 0 deletions site/bisheng-plugin-antd/lib/process-demo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
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';
}

function getCode(node) {
return JsonML.getChildren(
JsonML.getChildren(node)[0]
)[0];
}

module.exports = (markdownData) => {
const meta = markdownData.meta;
meta.id = meta.filename.replace(/\.md$/, '').replace(/\//g, '-');

const contentChildren = JsonML.getChildren(markdownData.content);
const chineseIntroStart = contentChildren.findIndex((node) => {
return JsonML.getTagName(node) === 'h2' &&
JsonML.getChildren(node)[0] === 'zh-CN';
});
const englishIntroStart = contentChildren.findIndex((node) => {
return JsonML.getTagName(node) === 'h2' &&
JsonML.getChildren(node)[0] === 'en-US';
});
const codeIndex = contentChildren.findIndex((node) => {
return JsonML.getTagName(node) === 'pre' &&
JsonML.getAttributes(node).lang === 'jsx';
});
if (chineseIntroStart > -1 /* equal to englishIntroStart > -1 */) {
markdownData.content = {
'zh-CN': contentChildren.slice(chineseIntroStart + 1, englishIntroStart),
'en-US': contentChildren.slice(englishIntroStart + 1, codeIndex),
};
} else {
markdownData.content = contentChildren.slice(0, codeIndex);
}

markdownData.highlightedCode = contentChildren[codeIndex].slice(0, 2);
const preview = [
'pre', { lang: '__react' },
];
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) ||
(JsonML.getTagName(node) === 'pre' && JsonML.getAttributes(node).lang === 'css');
});
if (isStyleTag(styleNode)) {
markdownData.style = JsonML.getChildren(styleNode)[0];
} else if (styleNode) {
markdownData.style = getCode(styleNode);
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;
};
19 changes: 19 additions & 0 deletions site/bisheng-plugin-antd/lib/process-doc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
const JsonML = require('jsonml.js/lib/utils');

module.exports = (markdownData) => {
const contentChildren = JsonML.getChildren(markdownData.content);
const apiStartIndex = contentChildren.findIndex((node) => {
return JsonML.getTagName(node) === 'h2' &&
JsonML.getChildren(node)[0] === 'API';
});

if (apiStartIndex > -1) {
const content = contentChildren.slice(0, apiStartIndex);
markdownData.content = ['section'].concat(content);

const api = contentChildren.slice(apiStartIndex);
markdownData.api = ['section'].concat(api);
}

return markdownData;
};
34 changes: 34 additions & 0 deletions site/bisheng-plugin-antd/lib/template.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<!DOCTYPE html>
<html>
<head>
<title>Demo</title>
<link rel="stylesheet" href="../index.css" />
<style>
html, body {
height: 100%;
margin: 0;
background: none;
}
{{ style }}
</style>
</head>
<body>
<div id="{{ id }}" class="code-box-demo"></div>
<script>
function require(module) {
if (module === 'react-router') {
return window.ReactRouter;
}
return window.parent[module];
}

var React = require('react');
var ReactDOM = require('react-dom');
var mountNode = document.getElementById('{{ id }}');
</script>
<script src="https://npmcdn.com/react-router/umd/ReactRouter.min.js"></script>
<script>
{{ script }}
</script>
</body>
</html>
34 changes: 34 additions & 0 deletions site/bisheng.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
const path = require('path');

module.exports = {
source: [
'./components',
'./docs',
'CHANGELOG.md', // TODO: fix it in bisheng
],
theme: './site/theme',
htmlTemplate: './site/theme/static/template.html',
plugins: [
'bisheng-plugin-description',
'bisheng-plugin-toc?maxDepth=2',
'bisheng-plugin-react?lang=__react',
'./site/bisheng-plugin-antd',
],
webpackConfig(config) {
config.resolve.alias = {
antd: process.cwd(),
site: path.join(process.cwd(), 'site'),
};

config.babel.plugins.push([
require.resolve('babel-plugin-antd'),
{
style: true,
libraryName: 'antd',
libDir: 'components',
},
]);

return config;
},
};
Loading

0 comments on commit ff31a5b

Please sign in to comment.