Sha256: 0bd08fce38f6efad387a4e17b997dd2dee7e1045b2601be29aa69c5fe07f159c

Contents?: true

Size: 997 Bytes

Versions: 1

Compression:

Stored size: 997 Bytes

Contents

require 'libxml'

  # Validates using LibXML via the libxml-ruby[http://libxml.rubyforge.org/] gem.
module AssertValidContent::LibXML

Installed = true

# Validates HTML and XHTML
class HTMLValidator < AssertValidContent::Validator
  def validate!( content )  #:nodoc:
    ::LibXML::XML::Error.set_handler { |err|  @errors << err  }
    begin
      doc = self.parser( content ).parse
    rescue ::LibXML::XML::Error ; end
    @errors.empty?
  end

protected
  def parser( content )  #:nodoc:
    ::LibXML::XML::HTMLParser.string content
  end
end

module Assertions
  def assert_valid_html( *srcs, &blk )
    assert_valid_content ::AssertValidContent::LibXML::HTMLValidator, *srcs, &blk
  end
end

# Validates XML
class XMLValidator < HTMLValidator
protected
  def parser( content )  #:nodoc:
    ::LibXML::XML::Parser.string content
  end
end

module Assertions
  def assert_valid_xml( *srcs, &blk )
    assert_valid_content ::AssertValidContent::LibXML::XMLValidator, *srcs, &blk
  end
end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
CodeMonkeySteve-assert_valid_content-0.2 lib/assert_valid_content/libxml.rb