Skip to content

Commit

Permalink
dom/element: improve #inner_dom and add specs
Browse files Browse the repository at this point in the history
  • Loading branch information
meh committed Feb 2, 2014
1 parent 8144d58 commit a4bd2f3
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
8 changes: 6 additions & 2 deletions opal/browser/dom/element.rb
Original file line number Diff line number Diff line change
Expand Up @@ -228,15 +228,19 @@ def id=(value)
end

def inner_dom(&block)
clear

# FIXME: when block passing is fixed
doc = document
clear; Builder.new(doc, self, &block)
Builder.new(doc, self, &block)

self
end

def inner_dom=(node)
clear; self << node
clear

self << node
end

def /(*paths)
Expand Down
17 changes: 17 additions & 0 deletions spec/dom/element_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,23 @@
end
end

describe '#inner_dom' do
html <<-HTML
<div id="lol">
<div id="wut"></div>
</div>
HTML

it 'builds the DOM and inserts it' do
$document["lol"].inner_dom {
div.omg!
}

expect($document["#lol #omg"]).to be_truthy
expect($document["#lol #wut"]).to be_falsy
end
end

describe '#inspect' do
it 'uses the node name' do
el = $document.create_element('div')
Expand Down

0 comments on commit a4bd2f3

Please sign in to comment.