Skip to content
This repository was archived by the owner on Oct 19, 2018. It is now read-only.

Commit 17435c9

Browse files
committed
Update README and add license
1 parent 82cf81b commit 17435c9

File tree

2 files changed

+66
-14
lines changed

2 files changed

+66
-14
lines changed

LICENSE

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Copyright (c) 2015 Yi-Cheng Chang (http://github.com/zetachang)
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy
4+
of this software and associated documentation files (the "Software"), to deal
5+
in the Software without restriction, including without limitation the rights
6+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7+
copies of the Software, and to permit persons to whom the Software is
8+
furnished to do so, subject to the following conditions:
9+
10+
The above copyright notice and this permission notice shall be included in
11+
all copies or substantial portions of the Software.
12+
13+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19+
THE SOFTWARE.

README.md

+47-14
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@
22

33
**React.rb is a [Opal Ruby](http://opalrb.org) wrapper of [React.js library](http://facebook.github.io/react/)**.
44

5-
It let you write reactive UI component with Ruby's elegancy and compiled to run in Javascript.
5+
It let you write reactive UI component with Ruby's elegancy and compiled to run in Javascript. :heart:
66

77
## Installation
88

99
```ruby
10-
gem `react.rb`
10+
# Gemfile
11+
gem "react.rb"
1112
```
1213

1314
and in your Opal application,
@@ -38,7 +39,7 @@ React.render_static_markup(React.create_element(HelloMessage)) # => '<div>Hello
3839

3940
### More complicated one
4041

41-
To hook into native ReactComponent life cycle, the native `this` will be passed to the class's initializer. And all corresponding life cycle methods (`componentDidMount`, etc) will be invoked on the instance with using the corresponding snake case method name.
42+
To hook into native ReactComponent life cycle, the native `this` will be passed to the class's initializer. And all corresponding life cycle methods (`componentDidMount`, etc) will be invoked on the instance using the corresponding snake-case method name.
4243

4344
```ruby
4445
class HelloMessage
@@ -55,7 +56,7 @@ class HelloMessage
5556
end
5657
end
5758

58-
puts React.render_static_markup(React.create_element(HelloMessage, name: 'John'))
59+
puts React.render_to_static_markup(React.create_element(HelloMessage, name: 'John'))
5960

6061
# => will_mount!
6162
# => '<div>Hello John!</div>'
@@ -67,32 +68,55 @@ Hey, we are using Ruby, simply include `React::Component` to save your typing an
6768

6869
```ruby
6970
class HelloMessage
71+
include React::Component
72+
MSG = {great: 'Cool!', bad: 'Cheer up!'}
73+
7074
define_state(:foo) { "Default greeting" }
7175

7276
before_mount do
73-
self.foo = self.foo + " <3 "
77+
self.foo = "#{self.foo}: #{MSG[params[:mood]]}"
78+
end
79+
80+
after_mount :log
81+
82+
def log
83+
puts "mounted!"
7484
end
7585

7686
def render
7787
div do
78-
span { self.foo + " Hello #{params[:name]}!" }
88+
span { self.foo + " #{params[:name]}!" }
7989
end
8090
end
8191
end
8292

83-
React.render_static_markup(React.create_element(HelloMessage, name: 'John')) # => '<div>Hello John!</div>'
93+
class App
94+
include React::Component
95+
96+
def render
97+
present HelloMessage, name: 'John', mood: 'great'
98+
end
99+
end
100+
101+
puts React.render_to_static_markup(React.create_element(App))
102+
# => '<div><span>Default greeting: Cool! John!</span></div>'
103+
React.render(React.create_element(App), `document.body`)
104+
# mounted!
84105
```
85106

86-
* Callback of life cycle could be created through `before_mount`, `after_mount`, etc
87-
* `this.props` is provided through method `self.params`
88-
* Use class method `define_method` to create setter & getter of `this.state` for you
107+
* Callback of life cycle could be created through helpers `before_mount`, `after_mount`, etc
108+
* `this.props` is accessed through method `self.params`
109+
* Use helper method `define_state` to create setter & getter of `this.state` for you
110+
* For the detailed mapping to the original API, see [this issue](https://github.com/zetachang/react.rb/issues/2) for reference. Complete reference will come soon.
89111

90112
### Props validation
91113

92-
How about props validation? Inspired from [Grape API](https://github.com/intridea/grape), props validation rule could be create easily through `params` class method as below,
114+
How about props validation? Inspired from [Grape API](https://github.com/intridea/grape), props validation rule could be created easily through `params` class method as below,
93115

94116
```ruby
95117
class App
118+
include React::Component
119+
96120
params do
97121
requires :username, type: String
98122
requires :enum, values: ['foo', 'bar', 'awesome']
@@ -101,7 +125,9 @@ class App
101125
optional :flash_message, type: String, default: 'Welcome!' # no need to feed through `getDefaultProps`
102126
end
103127

104-
def render; end
128+
def render
129+
div
130+
end
105131
end
106132
```
107133

@@ -110,6 +136,13 @@ end
110136
* React Tutorial: see [example/react-tutorial](example/react-tutorial), the original CommentBox example.
111137
* TodoMVC: see [example/todos](example/todos), your beloved TodoMVC <3.
112138

139+
## TODOS
140+
141+
* Mixins examples
142+
* Documentation
143+
* API wrapping coverage of the original js library (pretty close though)
144+
* React Native?
145+
113146
## Developing
114147

115148
To run the test case of the project yourself.
@@ -121,7 +154,7 @@ To run the test case of the project yourself.
121154

122155
## Contributions
123156

124-
This project is still in early stage, so discussion, bug report and PR are really welcome :wink.
157+
This project is still in early stage, so discussion, bug report and PR are really welcome :wink:.
125158

126159
## Contact
127160

@@ -130,4 +163,4 @@ This project is still in early stage, so discussion, bug report and PR are reall
130163

131164
## License
132165

133-
In short, IPSqueezableViewController is available under the MIT license. See the LICENSE file for more info.
166+
In short, React.rb is available under the MIT license. See the LICENSE file for more info.

0 commit comments

Comments
 (0)