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

Commit f2d5b72

Browse files
committed
closes #105, updates DSL test spec
1 parent a952cd2 commit f2d5b72

File tree

6 files changed

+148
-17
lines changed

6 files changed

+148
-17
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
[![Join the chat at https://gitter.im/zetachang/react.rb](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/zetachang/react.rb?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
44
[![Build Status](https://travis-ci.org/zetachang/react.rb.svg)](https://travis-ci.org/zetachang/react.rb)
55
[![Code Climate](https://codeclimate.com/github/zetachang/react.rb/badges/gpa.svg)](https://codeclimate.com/github/zetachang/react.rb)
6+
[![Gem Version](https://badge.fury.io/rb/reactive-ruby.svg)](https://badge.fury.io/rb/reactive-ruby)
67

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

lib/react/component.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def method_missing(n, *args, &block)
4444
unless name && name.method_defined?(:render)
4545
return super
4646
end
47-
RenderingContext.build_or_render(node_only, name, *args, &block)
47+
React::RenderingContext.build_or_render(node_only, name, *args, &block)
4848
end
4949
end
5050
end
@@ -241,7 +241,7 @@ def method_missing(n, *args, &block)
241241
name = "p"
242242
end
243243

244-
RenderingContext.build_or_render(node_only, name, *args, &block)
244+
React::RenderingContext.build_or_render(node_only, name, *args, &block)
245245
end
246246

247247
def watch(value, &on_change)
@@ -256,7 +256,7 @@ def define_state(*args, &block)
256256

257257
def _render_wrapper
258258
State.set_state_context_to(self) do
259-
RenderingContext.render(nil) {render || ""}.tap { |element| @waiting_on_resources = element.waiting_on_resources if element.respond_to? :waiting_on_resources }
259+
React::RenderingContext.render(nil) {render || ""}.tap { |element| @waiting_on_resources = element.waiting_on_resources if element.respond_to? :waiting_on_resources }
260260
end
261261
rescue Exception => e
262262
self.class.process_exception(e, self)

lib/react/element.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,18 +60,18 @@ def method_missing(class_name, args = {}, &new_block)
6060
new_props = properties.dup
6161
new_props["class"] = "#{new_props['class']} #{class_name} #{args.delete("class")} #{args.delete('className')}".split(" ").uniq.join(" ")
6262
new_props.merge! args
63-
RenderingContext.replace(
63+
React::RenderingContext.replace(
6464
self,
6565
React::RenderingContext.build { React::RenderingContext.render(type, new_props, &new_block) }
6666
)
6767
end
6868

6969
def as_node
70-
RenderingContext.as_node(self)
70+
React::RenderingContext.as_node(self)
7171
end
7272

7373
def delete
74-
RenderingContext.delete(self)
74+
React::RenderingContext.delete(self)
7575
end
7676
end
7777
end

path_release_steps.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
2+
For example assuming you are releasing fix to 0.8.18
3+
4+
1. Checkout 0-8-stable
5+
2. Update tests, fix the bug and commit the changes.
6+
3. Build & Release to RubyGems (Remember the version in version.rb should already be 0.8.19)
7+
4. Create a tag 'v0.8.19' pointing to that commit.
8+
5. Bump the version in 0-8-stable to 0.8.20 so it will be ready for the next patch level release.

reactive-ruby.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Gem::Specification.new do |s|
99

1010
s.author = 'David Chang'
1111
s.email = 'zeta11235813@gmail.com'
12-
s.homepage = 'https://reactive-ruby.github.io'
12+
s.homepage = 'https://reactrb.org'
1313
s.summary = 'Opal Ruby wrapper of React.js library.'
1414
s.license = 'MIT'
1515
s.description = "Write React UI components in pure Ruby."

spec/react/dsl_spec.rb

Lines changed: 132 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,137 @@
22

33
if opal?
44
describe 'the React DSL' do
5-
it "will treat the component class name as a first class component name" # Foo()
6-
it "can add class names by the haml .class notation" # Foo.my_class
7-
it "can use the 'class' keyword for classes" # Foo(class: "my-class")
8-
it "will turn the last string in a block into a span" # Foo { "hello there" }
9-
it "has a .span short hand String method" # "hello there".span
10-
it "has a .br short hand String method"
11-
it "has a .td short hand String method"
12-
it "has a .para short hand String method"
13-
it "can generate a unrendered node using the .as_node method" # div { "hello" }.as_node
14-
it "can use the dangerously_set_inner_HTML param" # div { dangerously_set_inner_HTML: "<div>danger</div>" }
5+
6+
it "will turn the last string in a block into a element" do
7+
stub_const 'Foo', Class.new
8+
Foo.class_eval do
9+
include React::Component
10+
def render
11+
div { "hello" }
12+
end
13+
end
14+
15+
expect(React.render_to_static_markup(React.create_element(Foo))).to eq('<div>hello</div>')
16+
end
17+
18+
it "has a .span short hand String method" do
19+
stub_const 'Foo', Class.new
20+
Foo.class_eval do
21+
include React::Component
22+
def render
23+
div { "hello".span; "goodby".span }
24+
end
25+
end
26+
27+
expect(React.render_to_static_markup(React.create_element(Foo))).to eq('<div><span>hello</span><span>goodby</span></div>')
28+
end
29+
30+
it "has a .br short hand String method" do
31+
stub_const 'Foo', Class.new
32+
Foo.class_eval do
33+
include React::Component
34+
def render
35+
div { "hello".br }
36+
end
37+
end
38+
39+
expect(React.render_to_static_markup(React.create_element(Foo))).to eq('<div><span>hello<br></span></div>')
40+
end
41+
42+
it "has a .td short hand String method" do
43+
stub_const 'Foo', Class.new
44+
Foo.class_eval do
45+
include React::Component
46+
def render
47+
table { tr { "hello".td } }
48+
end
49+
end
50+
51+
expect(React.render_to_static_markup(React.create_element(Foo))).to eq('<table><tr><td>hello</td></tr></table>')
52+
end
53+
54+
it "has a .para short hand String method" do
55+
stub_const 'Foo', Class.new
56+
Foo.class_eval do
57+
include React::Component
58+
def render
59+
div { "hello".para }
60+
end
61+
end
62+
63+
expect(React.render_to_static_markup(React.create_element(Foo))).to eq('<div><p>hello</p></div>')
64+
end
65+
66+
it "will treat the component class name as a first class component name" do
67+
stub_const 'Mod::Bar', Class.new
68+
Mod::Bar.class_eval do
69+
include React::Component
70+
def render
71+
"a man walks into a bar"
72+
end
73+
end
74+
stub_const 'Foo', Class.new(React::Component::Base)
75+
Foo.class_eval do
76+
def render
77+
Mod::Bar()
78+
end
79+
end
80+
81+
expect(React.render_to_static_markup(React.create_element(Foo))).to eq('<span>a man walks into a bar</span>')
82+
end
83+
84+
it "can add class names by the haml .class notation" do
85+
stub_const 'Mod::Bar', Class.new(React::Component::Base)
86+
Mod::Bar.class_eval do
87+
collect_other_params_as :attributes
88+
def render
89+
"a man walks into a bar".span(attributes)
90+
end
91+
end
92+
stub_const 'Foo', Class.new(React::Component::Base)
93+
Foo.class_eval do
94+
def render
95+
Mod::Bar().the_class
96+
end
97+
end
98+
99+
expect(React.render_to_static_markup(React.create_element(Foo))).to eq('<span class="the-class">a man walks into a bar</span>')
100+
end
101+
102+
it "can use the 'class' keyword for classes" do
103+
stub_const 'Foo', Class.new
104+
Foo.class_eval do
105+
include React::Component
106+
def render
107+
span(class: "the-class") { "hello" }
108+
end
109+
end
110+
111+
expect(React.render_to_static_markup(React.create_element(Foo))).to eq('<span class="the-class">hello</span>')
112+
end
113+
114+
it "can generate a unrendered node using the .as_node method" do # div { "hello" }.as_node
115+
stub_const 'Foo', Class.new #(React::Component::Base)
116+
Foo.class_eval do
117+
include React::Component
118+
def render
119+
span { "hello".span.as_node.class.name }.as_node.render
120+
end
121+
end
122+
123+
expect(React.render_to_static_markup(React.create_element(Foo))).to eq('<span>React::Element</span>')
124+
end
125+
126+
it "can use the dangerously_set_inner_HTML param" do
127+
stub_const 'Foo', Class.new
128+
Foo.class_eval do
129+
include React::Component
130+
def render
131+
div(dangerously_set_inner_HTML: { __html: "Hello&nbsp;&nbsp;Goodby" })
132+
end
133+
end
134+
135+
expect(React.render_to_static_markup(React.create_element(Foo))).to eq('<div>Hello&nbsp;&nbsp;Goodby</div>')
136+
end
15137
end
16138
end

0 commit comments

Comments
 (0)