Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a JSX Compiler tool. #23

Merged
merged 3 commits into from
May 30, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ docs/css/react.css
docs/js/JSXTransformer.js
docs/js/react.min.js
docs/js/docs.js
docs/js/jsx-compiler.js
docs/js/live_editor.js
docs/js/examples
docs/downloads
Expand Down
8 changes: 4 additions & 4 deletions docs/_config.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
---
---
pygments: true
name: React
react_version: 0.3.0
exclude:
exclude:
- Gemfile
- Gemfile.lock
- README.md
- Rakefile
redcarpet:
extensions:
redcarpet:
extensions:
- fenced_code_blocks
markdown: redcarpet
baseurl: /react
30 changes: 27 additions & 3 deletions docs/_css/react.scss
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@
@import '_typography';
@import '_solarized';

@mixin code-typography {
font-family: 'source-code-pro', Menlo, 'Courier New', Consolas, monospace;
font-size: 13px;
line-height: 20px;
}

$skinnyContentWidth: 650px;
$contentWidth: 920px;
$contentPadding: 20px;
Expand Down Expand Up @@ -396,6 +402,26 @@ section.black content {
padding-bottom: 40px;
}

/* JSX Compiler */

.jsxCompiler {
margin: 0 auto;
padding-top: 20px;
width: 1220px;

#jsxCompiler {
margin-top: 20px;
}

.playgroundPreview {
padding: 14px;
width: 600px;

pre {
@include code-typography;
}
}
}

/* Button */

Expand Down Expand Up @@ -482,9 +508,7 @@ p {
/* Code Mirror */

div.CodeMirror pre, div.CodeMirror-linenumber, code {
font-family: 'source-code-pro', Menlo, 'Courier New', Consolas, monospace;
font-size: 13px;
line-height: 20px;
@include code-typography;
}

div.CodeMirror-linenumber:after {
Expand Down
19 changes: 19 additions & 0 deletions docs/_js/jsx-compiler.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/**
* @jsx React.DOM
*/

var HELLO_COMPONENT = "\
/** @jsx React.DOM */\n\
var HelloMessage = React.createClass({\n\
render: function() {\n\
return <div>{'Hello ' + this.props.name}</div>;\n\
}\n\
});\n\
\n\
React.renderComponent(<HelloMessage name=\"John\" />, mountNode);\
";

React.renderComponent(
<ReactPlayground codeText={HELLO_COMPONENT} renderCode={true} />,
document.getElementById('jsxCompiler')
);
14 changes: 12 additions & 2 deletions docs/_js/live_editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,19 @@ var ReactPlayground = React.createClass({
} catch (e) { }

try {
eval(this.getDesugaredCode());
if (this.props.renderCode) {
React.renderComponent(
<pre>{this.getDesugaredCode()}</pre>,
mountNode
);
} else {
eval(this.getDesugaredCode());
}
} catch (e) {
React.renderComponent(<div content={e.toString()} class={{playgroundError: true}} />, mountNode);
React.renderComponent(
<div content={e.toString()} class={{playgroundError: true}} />,
mountNode
);
}
}
});
Expand Down
7 changes: 5 additions & 2 deletions docs/docs/syntax.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,11 @@ var app = <Nav color="blue"><Profile>click</Profile></Nav>;
var app = Nav({color:'blue'}, Profile({}, 'click'));
```

The [Getting Started](getting-started.html) guide shows how to setup JSX
compilation.
Use the [JSX Compiler](/react/jsx-compiler.html) to try out JSX and see how it
desguars into native JavaScript.

If you want to use JSX, the [Getting Started](getting-started.html) guide shows
how to setup compilation.

> Note:
>
Expand Down
14 changes: 14 additions & 0 deletions docs/jsx-compiler.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
layout: default
title: JSX Compiler Service
id: jsx-compiler
---
<div class="jsxCompiler">
<h1>JSX Compiler</h1>
<p>
This tool demonstrates how <a href="/react/docs/syntax.html">JSX syntax</a>
is desguared into native JavaScript.
</p>
<div id="jsxCompiler"></div>
<script type="text/javascript" src="js/jsx-compiler.js"></script>
</div>