Skip to content

Commit

Permalink
react apply text node
Browse files Browse the repository at this point in the history
  • Loading branch information
rubys committed Feb 17, 2015
1 parent 14622d4 commit beb0d63
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
8 changes: 7 additions & 1 deletion lib/ruby2js/filter/react.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,13 @@ def on_send(node)

if node.children[0] == nil and node.children[1] == :_
# text nodes
node.children[2]
if @reactApply
# if apply is set, emit code that pushes text
s(:send, s(:gvar, :$_), :push, node.children[2])
else
# simple/normal case: simply return the text
node.children[2]
end

elsif node.children[0] == nil and node.children[1] =~ /^_\w/
# map method calls starting with an underscore to React calls
Expand Down
5 changes: 5 additions & 0 deletions spec/react_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,11 @@ def to_js(string)
to_js( 'class Foo<React; def render; _a {_ "hi"}; end; end' ).
must_include 'return React.createElement("a", null, "hi")'
end

it "should apply text nodes" do
to_js( 'class Foo<React; def render; _a {text="hi"; _ text}; end; end' ).
must_include 'var text = "hi"; $_.push(text);'
end
end

describe "class attributes" do
Expand Down

0 comments on commit beb0d63

Please sign in to comment.