https://github.com/rmosolgo/jsx-ruby
Transform JSX from Ruby. Includes a Tilt template.
https://github.com/rmosolgo/jsx-ruby
Last synced: 3 months ago
JSON representation
Transform JSX from Ruby. Includes a Tilt template.
- Host: GitHub
- URL: https://github.com/rmosolgo/jsx-ruby
- Owner: rmosolgo
- Created: 2015-04-01T05:26:51.000Z (almost 11 years ago)
- Default Branch: master
- Last Pushed: 2015-04-01T05:34:06.000Z (almost 11 years ago)
- Last Synced: 2025-10-06T14:49:43.906Z (3 months ago)
- Language: Ruby
- Size: 125 KB
- Stars: 8
- Watchers: 1
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# JSX [](https://travis-ci.org/rmosolgo/jsx-ruby) [](http://badge.fury.io/rb/jsx)
A Ruby interface to Facebook's JSX transformer, broken out of `react-rails`. You can:
- convert JSX willy-nilly
- Use `JSX::Template` with a Tilt environment (for example, Sinatra)
## Installation
```ruby
gem "jsx"
```
```
bundle install
```
## Ad Hoc Transform
You can access the transformer directly. Pass it some JavaScript with JSX. Optionally, pass `strip_types` or `harmony`. For example:
```ruby
compiled = JSX.transform("
Hello {name}
", strip_types: true, harmony: true)
# 'React.createElement("h1", {className: "greeting"}, "Hello ", name)'
```
## With Tilt
Tilt can automatically convert `.jsx` files. After loading Tilt and JSX, require `jsx/tilt`. For example:
```ruby
require 'tilt'
require 'jsx'
require 'jsx/tilt'
```
To use `harmony` or `strip_types` in this case, assign them to `JSX::Template.transform_options`. For example:
```ruby
JSX::Template.transform_options = {strip_types: true}
```
Now, the template will strip types from JSX code.
## License
- Facebook's JSX Transformer (part of React): [BSD](https://github.com/facebook/react/blob/master/LICENSE)
- This Ruby code: MIT