Sha256: 0533a613015fadf9d210e2fb78af173aec9f9779c760443e4a25c369e6bd2248

Contents?: true

Size: 1.12 KB

Versions: 2

Compression:

Stored size: 1.12 KB

Contents

require 'nokogiri'

module Nokogiri
  module Hpricot
    STag = String
    Elem = XML::Node
    NamedCharacters = Nokogiri::HTML::NamedCharacters
    class << self
      def parse(*args)
        doc = Nokogiri.parse(*args)
        add_decorators(doc)
      end

      def XML(string)
        doc = Nokogiri::XML.parse(string)
        add_decorators(doc)
      end

      def make string
        ns = XML::NodeSet.new
        ns << XML::Text.new(string, XML::Document.new)
        ns
      end

      def add_decorators(doc)
        doc.decorators['node'] << Decorators::Hpricot::Node
        doc.decorators['element'] << Decorators::Hpricot::Node
        doc.decorators['document'] << Decorators::Hpricot::Node
        doc.decorators['nodeset'] << Decorators::Hpricot::NodeSet
        doc.decorate!
        doc
      end
    end
  end
  
  class << self
    def Hpricot(*args, &block)
      if block_given?
        builder = Nokogiri::HTML::Builder.new(&block)
        Nokogiri::Hpricot.add_decorators(builder.doc)
      else
        doc = Nokogiri::HTML.parse(*args)
        Nokogiri::Hpricot.add_decorators(doc)
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
nokogiri-1.0.4-x86-mswin32-60 lib/nokogiri/hpricot.rb
nokogiri-1.0.4 lib/nokogiri/hpricot.rb