Sha256: f08e9c93ed3f00837e0841e42c008682440046ec71984de4683d59641bcc688a

Contents?: true

Size: 936 Bytes

Versions: 1

Compression:

Stored size: 936 Bytes

Contents

require 'rexml/document'
require 'rehtml'
module OpenfireAdmin
  module ElementHelper
    def at(xpath)
      xpath = ".#{xpath}" if !self.is_a?(REXML::Document) and xpath =~ /^\//
      elm = REXML::XPath.first(self,xpath)
      elm.extend(ElementHelper)
      elm
    end
    def search(xpath)
      xpath = ".#{xpath}" if !self.is_a?(REXML::Document) and xpath =~ /^\//
      ret = REXML::XPath.match(self,xpath).map{|elm|
        elm.extend(ElementHelper)
        elm
        block_given? ? (yield elm) : elm
      }
    end
    def [](arg, name=nil)
      if arg.is_a?(Symbol)
        self.attributes[arg.to_s]
      else
        super
      end
    end
  end
  # html parser wrapper
  class HtmlParser
    def initialize(html)
      @doc = REHTML.to_rexml(html)
      @doc.extend(ElementHelper)
    end
    def search(xpath, &proc)
      @doc.search(xpath, &proc)
    end
    def at(xpath)
      @doc.at(xpath)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
openfire_admin-0.0.3 lib/openfire_admin/html_parser.rb