Sha256: e59ee07543b95799fcbd8458ac95c62fa94642d3dc0055a4dea3de1e82ef0eb0
Contents?: true
Size: 1.32 KB
Versions: 21
Compression:
Stored size: 1.32 KB
Contents
module Nokogiri module Decorators module Hpricot module Node def search *paths ns = paths.last.is_a?(Hash) ? paths.pop : {} converted = paths.map { |path| convert_to_xpath(path) }.flatten.uniq super(*converted + [ns]) end def /(path); search(path) end def xpath *args return super if args.length > 0 path end def raw_attributes; self end def get_element_by_id element_id search("//*[@id='#{element_id}']").first end def get_elements_by_tag_name tag search("//#{tag}") end def convert_to_xpath(rule) rule = rule.to_s case rule when %r{^//} [".#{Hpricot::XPathVisitor.xpath_namespace_helper(rule)}"] when %r{^/} [Hpricot::XPathVisitor.xpath_namespace_helper(rule)] when %r{^.//} [Hpricot::XPathVisitor.xpath_namespace_helper(rule)] else visitor = CSS::XPathVisitor.new visitor.extend(Hpricot::XPathVisitor) CSS.xpath_for(rule, :prefix => ".//", :visitor => visitor) end end def target name end def to_original_html to_html end end end end end
Version data entries
21 entries across 21 versions & 1 rubygems
Version | Path |
---|---|
nokogiri-1.2.3 | lib/nokogiri/decorators/hpricot/node.rb |