Skip to content

Commit

Permalink
Proposal of implementation for siblings() tree traversal utility plat…
Browse files Browse the repository at this point in the history
  • Loading branch information
Ssruno committed Jan 22, 2018
1 parent e42b1e9 commit 81bb4ab
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions lib/pincers/core/search_context.rb
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,19 @@ def last
if elements.last.nil? then nil else wrap_siblings [elements.last] end
end

# Implementation of siblings() from JQuery
def siblings(_selector=nil)
if _selector
parser = Pincers::CSS::Parser.new _selector
exp = parser.to_xpath("")
exp = exp.first if exp.length == 1

search(:xpath => "preceding-sibling::#{exp} | following-sibling::#{exp}")
else
search( :xpath => 'preceding-sibling::* | following-sibling::*' )
end
end

def search(_selector=nil, _options={}, &_block)
if _selector.is_a? Hash
_options = _selector
Expand Down

0 comments on commit 81bb4ab

Please sign in to comment.