Skip to content

Commit

Permalink
Support setting html content through Element#html()
Browse files Browse the repository at this point in the history
  • Loading branch information
adambeynon committed Nov 28, 2013
1 parent dfdeedc commit 374e467
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
10 changes: 8 additions & 2 deletions opal/opal-jquery/element.rb
Expand Up @@ -211,8 +211,14 @@ def first
`self.length ? self.first() : nil`
end

def html
`self.html() || ""`
def html(content = undefined)

This comment has been minimized.

Copy link
@elia

elia Dec 1, 2013

Member

Missing back ticks or I'm the one missing something? :)

This comment has been minimized.

Copy link
@adambeynon

adambeynon Dec 1, 2013

Author Contributor

For the undefined part?

This comment has been minimized.

Copy link
@adambeynon

adambeynon Dec 1, 2013

Author Contributor

We handle undefined as an optional arg specially: https://github.com/opal/opal/blob/master/lib/opal/nodes/def.rb#L63. Lots of corelib methods have special meanings for undefined args, without a default. Rubinius does the same. Really, we should only do this in corelib as its not a public feature.

This comment has been minimized.

Copy link
@elia

elia via email Dec 2, 2013

Member
%x{
if (content != null) {
return self.html(content);
}
return self.html() || '';
}
end

def id
Expand Down
18 changes: 18 additions & 0 deletions spec/element_spec.rb
Expand Up @@ -184,3 +184,21 @@
end
end
end

describe "Element#html" do
html <<-HTML
<div id="foo">bar</div>
HTML

it "retrieves the inner html content for the element" do
expect(Element.id('foo').html).to include('bar')
end

it "can be used to set inner html of element by passing string" do
foo = Element.id 'foo'
foo.html "different content"

expect(foo.html).to_not include('bar')
expect(foo.html).to include('different content')
end
end

0 comments on commit 374e467

Please sign in to comment.