Method: BeHtmlWith#build_xpath_too

Defined in:
lib/assert2/xhtml.rb

#build_xpath_too(element) ⇒ Object



276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
# File 'lib/assert2/xhtml.rb', line 276

def build_xpath_too(element)
  path = element.name.sub(/\!$/, '')
  element_kids = element.children.grep(Nokogiri::XML::Element)
  path << '[ '
  count = @references.length
  @references << element
  brackets_owed = 0

  if element_kids.length > 0
    child = element_kids[0]
    path << './descendant::' + build_xpath_too(child)
  end

  if element_kids.length > 1
    path << element_kids[1..-1].map{|child|
              '[ ./following-sibling::*[ ./descendant-or-self::' + build_xpath_too(child) + ' ] ]'
             }.join #(' and .')
  end
     path << ' and ' if element_kids.any?

  path << "refer(., '#{ count }') ]"  #  last so boolean short-circuiting optimizes
  return path
end