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

Commit 5a3d69d

Browse files
committed
Add render class method
Original commit 5f9a829
1 parent 47b1f21 commit 5a3d69d

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

lib/react/component/class_methods.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,18 @@ def deprecation_warning(message)
2727
end
2828
end
2929

30+
def render(*args, &block)
31+
if args[0].is_a? Hash
32+
define_method :render do
33+
yield
34+
end
35+
else
36+
define_method :render do
37+
send *args, &block
38+
end
39+
end
40+
end
41+
3042
def validator
3143
@validator ||= Validator.new(props_wrapper)
3244
end

spec/react/dsl_spec.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,18 @@
33
if opal?
44
describe 'the React DSL' do
55

6+
it "can define the render method with the render macro", only: true do
7+
stub_const 'Foo', Class.new
8+
Foo.class_eval do
9+
include React::Component
10+
render(:div, class: :foot) do
11+
"hello"
12+
end
13+
end
14+
15+
expect(React.render_to_static_markup(React.create_element(Foo))).to eq('<div class="foot">hello</div>')
16+
end
17+
618
it "will turn the last string in a block into a element" do
719
stub_const 'Foo', Class.new
820
Foo.class_eval do

0 commit comments

Comments
 (0)