Skip to content

Commit 0c4bd1b

Browse files
committed
Changes to work with React 0.12 and follow @zpao's recommendations
1 parent 7c85e4a commit 0c4bd1b

File tree

3 files changed

+18
-22
lines changed

3 files changed

+18
-22
lines changed

lib/generators/react/component_generator.rb

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,16 @@ class ComponentGenerator < ::Rails::Generators::NamedBase
1111
Available field types:
1212
1313
Basic prop types do not take any additional arguments. If you do not specify
14-
a prop type, the generic renderable will be used. The basic types available are:
14+
a prop type, the generic node will be used. The basic types available are:
1515
1616
any
1717
array
1818
bool
19-
component
19+
element
2020
func
2121
number
2222
object
23-
renderable
23+
node
2424
shape
2525
string
2626
@@ -51,15 +51,15 @@ class ComponentGenerator < ::Rails::Generators::NamedBase
5151
:banner => "field[:type] field[:type] ..."
5252

5353
REACT_PROP_TYPES = {
54-
"renderable" => 'React.PropTypes.renderable',
54+
"node" => 'React.PropTypes.node',
5555
"bool" => 'React.PropTypes.bool',
5656
"boolean" => 'React.PropTypes.bool',
5757
"string" => 'React.PropTypes.string',
5858
"number" => 'React.PropTypes.number',
5959
"object" => 'React.PropTypes.object',
6060
"array" => 'React.PropTypes.array',
6161
"shape" => 'React.PropTypes.shape({})',
62-
"component" => 'React.PropTypes.component',
62+
"element" => 'React.PropTypes.element',
6363
"func" => 'React.PropTypes.func',
6464
"function" => 'React.PropTypes.func',
6565
"any" => 'React.PropTypes.any',
@@ -103,13 +103,13 @@ def parse_attributes!
103103
end
104104
end
105105

106-
def self.lookup(type = "renderable", options = "")
106+
def self.lookup(type = "node", options = "")
107107
react_prop_type = REACT_PROP_TYPES[type]
108108
if react_prop_type.blank?
109109
if type =~ /^[[:upper:]]/
110110
react_prop_type = REACT_PROP_TYPES['instanceOf']
111111
else
112-
react_prop_type = REACT_PROP_TYPES['renderable']
112+
react_prop_type = REACT_PROP_TYPES['node']
113113
end
114114
end
115115

@@ -119,7 +119,7 @@ def self.lookup(type = "renderable", options = "")
119119
react_prop_type
120120
end
121121

122-
def lookup(type = "renderable", options = "")
122+
def lookup(type = "node", options = "")
123123
self.class.lookup(type, options)
124124
end
125125
end
Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
/** @jsx React.DOM */
21
var <%= file_name.camelize %> = React.createClass({
32
<% if attributes.size > 0 -%>
43
propTypes: {
@@ -10,13 +9,15 @@ var <%= file_name.camelize %> = React.createClass({
109

1110
render: function() {
1211
<% if attributes.size > 0 -%>
13-
return <div>
12+
return (
13+
<div>
1414
<% attributes.each do |attribute| -%>
15-
<div><%= attribute[:name].titleize %>: {this.props.<%= attribute[:name] %>}</div>
15+
<div><%= attribute[:name].titleize %>: {this.props.<%= attribute[:name] %>}</div>
1616
<% end -%>
17-
</div>;
17+
</div>
18+
);
1819
<% else -%>
1920
return <div />;
2021
<% end -%>
2122
}
22-
})
23+
});

test/generators/component_generator_test.rb

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,9 @@ def filename
1616
assert_file filename
1717
end
1818

19-
test "creates the component file with jsx pragma" do
20-
run_generator %w(GeneratedComponent)
21-
assert_file filename, %r{/\*\* @jsx React\.DOM \*/}
22-
end
23-
24-
test "creates the component file with a renderable argument" do
19+
test "creates the component file with a node argument" do
2520
run_generator %w(GeneratedComponent name)
26-
assert_file filename, %r{name: React.PropTypes.renderable}
21+
assert_file filename, %r{name: React.PropTypes.node}
2722
end
2823

2924
test "creates the component file with various standard proptypes" do
@@ -52,8 +47,8 @@ def filename
5247
end
5348

5449
test "generates working jsx" do
55-
expected_name_div = Regexp.escape('React.DOM.div(null, "Name: ", this.props.name)')
56-
expected_shape_div = Regexp.escape('React.DOM.div(null, "Address: ", this.props.address)')
50+
expected_name_div = Regexp.escape('React.createElement("div", null, "Name: ", this.props.name)')
51+
expected_shape_div = Regexp.escape('React.createElement("div", null, "Address: ", this.props.address)')
5752

5853
run_generator %w(GeneratedComponent name:string address:shape)
5954
jsx = React::JSX.transform(File.read(File.join(destination_root, filename)))

0 commit comments

Comments
 (0)