Skip to content

Commit 374e467

Browse files
committedNov 28, 2013
Support setting html content through Element#html()
1 parent dfdeedc commit 374e467

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed
 

‎opal/opal-jquery/element.rb

+8-2
Original file line numberDiff line numberDiff line change
@@ -211,8 +211,14 @@ def first
211211
`self.length ? self.first() : nil`
212212
end
213213

214-
def html
215-
`self.html() || ""`
214+
def html(content = undefined)
Has conversations. Original line has conversations.
215+
%x{
216+
if (content != null) {
217+
return self.html(content);
218+
}
219+
220+
return self.html() || '';
221+
}
216222
end
217223

218224
def id

‎spec/element_spec.rb

+18
Original file line numberDiff line numberDiff line change
@@ -184,3 +184,21 @@
184184
end
185185
end
186186
end
187+
188+
describe "Element#html" do
189+
html <<-HTML
190+
<div id="foo">bar</div>
191+
HTML
192+
193+
it "retrieves the inner html content for the element" do
194+
expect(Element.id('foo').html).to include('bar')
195+
end
196+
197+
it "can be used to set inner html of element by passing string" do
198+
foo = Element.id 'foo'
199+
foo.html "different content"
200+
201+
expect(foo.html).to_not include('bar')
202+
expect(foo.html).to include('different content')
203+
end
204+
end

0 commit comments

Comments
 (0)
Please sign in to comment.