Sha256: 9ec6191199aa737d3c8e5b8e4e41e06305e2a9e3cd19710b945eed67196547ac

Contents?: true

Size: 1.84 KB

Versions: 7

Compression:

Stored size: 1.84 KB

Contents

require 'nokogiri/version'
require 'nokogiri/xml'
require 'nokogiri/xslt'
require 'nokogiri/html'
require 'nokogiri/decorators'
require 'nokogiri/css'
require 'nokogiri/html/builder'
require 'nokogiri/hpricot'

# Modify the PATH on windows so that the external DLLs will get loaded.
ENV['PATH'] = [File.expand_path(
  File.join(File.dirname(__FILE__), "..", "ext", "nokogiri")
), ENV['PATH']].compact.join(';') if RUBY_PLATFORM =~ /mswin/i

require 'nokogiri/native' unless RUBY_PLATFORM =~ /java/

module Nokogiri
  class << self
    attr_accessor :error_handler

    ###
    # Parse an HTML or XML document.  +string+ contains the document.
    def parse string, url = nil, encoding = nil, options = nil
      doc =
        if string =~ /^\s*<[^Hh>]*html/i # Probably html
          Nokogiri::HTML.parse(string, url, encoding, options || 2145)
        else
          Nokogiri::XML.parse(string, url, encoding, options || 2159)
        end
      yield doc if block_given?
      doc
    end

    def make input = nil, opts = {}, &blk
      if input
        Nokogiri::XML::Node.new_from_str(input)
      else
        Nokogiri(&blk)
      end
    end
    
    ###
    # Parse a document and add the Slop decorator.  The Slop decorator
    # implements method_missing such that methods may be used instead of CSS
    # or XPath.  For example:
    #
    #   doc = Nokogiri::Slop(<<-eohtml)
    #     <html>
    #       <body>
    #         <p>first</p>
    #         <p>second</p>
    #       </body>
    #     </html>
    #   eohtml
    #   assert_equal('second', doc.html.body.p[1].text)
    #
    def Slop(*args, &block)
      Nokogiri(*args, &block).slop!
    end
  end

  self.error_handler = lambda { |syntax_error| }  
end

def Nokogiri(*args, &block)
  if block_given?
    builder = Nokogiri::HTML::Builder.new(&block)
    return builder.doc
  else
    Nokogiri.parse(*args)
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
nokogiri-1.1.0 lib/nokogiri.rb
nokogiri-1.0.7-x86-mswin32-60 lib/nokogiri.rb
nokogiri-1.0.7 lib/nokogiri.rb
nokogiri-1.1.1-x86-mswin32-60 lib/nokogiri.rb
nokogiri-1.1.0-x86-mswin32-60 lib/nokogiri.rb
nokogiri-1.1.1-java lib/nokogiri.rb
nokogiri-1.1.1 lib/nokogiri.rb