Skip to content

Commit 955b472

Browse files
committed
Add a JSX Compiler tool.
1 parent c5612b3 commit 955b472

File tree

7 files changed

+100
-11
lines changed

7 files changed

+100
-11
lines changed

docs/_config.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
---
1+
---
22
pygments: true
33
name: React
44
react_version: 0.3.0
5-
exclude:
5+
exclude:
66
- Gemfile
77
- Gemfile.lock
88
- README.md
99
- Rakefile
10-
redcarpet:
11-
extensions:
10+
redcarpet:
11+
extensions:
1212
- fenced_code_blocks
1313
markdown: redcarpet
1414
baseurl: /react

docs/_css/react.scss

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@
33
@import '_typography';
44
@import '_solarized';
55

6+
@mixin code-typography {
7+
font-family: 'source-code-pro', Menlo, 'Courier New', Consolas, monospace;
8+
font-size: 13px;
9+
line-height: 20px;
10+
}
11+
612
$skinnyContentWidth: 650px;
713
$contentWidth: 920px;
814
$contentPadding: 20px;
@@ -396,6 +402,26 @@ section.black content {
396402
padding-bottom: 40px;
397403
}
398404

405+
/* JSX Compiler */
406+
407+
.jsxCompiler {
408+
margin: 0 auto;
409+
padding-top: 20px;
410+
width: 1220px;
411+
412+
#jsxCompiler {
413+
margin-top: 20px;
414+
}
415+
416+
.playgroundPreview {
417+
padding: 14px;
418+
width: 600px;
419+
420+
pre {
421+
@include code-typography;
422+
}
423+
}
424+
}
399425

400426
/* Button */
401427

@@ -482,9 +508,7 @@ p {
482508
/* Code Mirror */
483509

484510
div.CodeMirror pre, div.CodeMirror-linenumber, code {
485-
font-family: 'source-code-pro', Menlo, 'Courier New', Consolas, monospace;
486-
font-size: 13px;
487-
line-height: 20px;
511+
@include code-typography;
488512
}
489513

490514
div.CodeMirror-linenumber:after {

docs/_js/jsx-compiler.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/**
2+
* @jsx React.DOM
3+
*/
4+
5+
var HELLO_COMPONENT = "\
6+
/** @jsx React.DOM */\n\
7+
var HelloMessage = React.createClass({\n\
8+
render: function() {\n\
9+
return <div>{'Hello ' + this.props.name}</div>;\n\
10+
}\n\
11+
});\n\
12+
\n\
13+
React.renderComponent(<HelloMessage name=\"John\" />, mountNode);\
14+
";
15+
16+
React.renderComponent(
17+
<ReactPlayground codeText={HELLO_COMPONENT} renderCode={true} />,
18+
document.getElementById('jsxCompiler')
19+
);

docs/_js/live_editor.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,19 @@ var ReactPlayground = React.createClass({
111111
} catch (e) { }
112112

113113
try {
114-
eval(this.getDesugaredCode());
114+
if (this.props.renderCode) {
115+
React.renderComponent(
116+
React.DOM.pre(null, this.getDesugaredCode()),
117+
mountNode
118+
);
119+
} else {
120+
eval(this.getDesugaredCode());
121+
}
115122
} catch (e) {
116-
React.renderComponent(<div content={e.toString()} class={{playgroundError: true}} />, mountNode);
123+
React.renderComponent(
124+
<div content={e.toString()} class={{playgroundError: true}} />,
125+
mountNode
126+
);
117127
}
118128
}
119129
});

docs/docs/syntax.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,11 @@ var app = <Nav color="blue"><Profile>click</Profile></Nav>;
5252
var app = Nav({color:'blue'}, Profile({}, 'click'));
5353
```
5454

55-
The [Getting Started](getting-started.html) guide shows how to setup JSX
56-
compilation.
55+
Use the [JSX Compiler](/react/jsx-compiler.html) to try out JSX and see how it
56+
desguars into native JavaScript.
57+
58+
If you want to use JSX, the [Getting Started](getting-started.html) guide shows
59+
how to setup compilation.
5760

5861
> Note:
5962
>

docs/js/jsx-compiler.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/**
2+
* @jsx React.DOM
3+
*/
4+
5+
var HELLO_COMPONENT = "\
6+
/** @jsx React.DOM */\n\
7+
var HelloMessage = React.createClass({\n\
8+
render: function() {\n\
9+
return <div>{'Hello ' + this.props.name}</div>;\n\
10+
}\n\
11+
});\n\
12+
\n\
13+
React.renderComponent(<HelloMessage name=\"John\" />, mountNode);\
14+
";
15+
16+
React.renderComponent(
17+
ReactPlayground( {codeText:HELLO_COMPONENT, renderCode:true}, null ),
18+
document.getElementById('jsxCompiler')
19+
);

docs/jsx-compiler.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
---
2+
layout: default
3+
title: JSX Compiler Service
4+
id: jsx-compiler
5+
---
6+
<div class="jsxCompiler">
7+
<h1>JSX Compiler</h1>
8+
<p>
9+
This tool demonstrates how <a href="/react/docs/syntax.html">JSX syntax</a>
10+
is desguared into native JavaScript.
11+
</p>
12+
<div id="jsxCompiler"></div>
13+
<script type="text/javascript" src="js/jsx-compiler.js"></script>
14+
</div>

0 commit comments

Comments
 (0)