Methods

Class Index [+]

Quicksearch

Nokogiri::HTML::DocumentFragment

Attributes

errors[RW]

Public Class Methods

new(document, tags = nil, ctx = nil) click to toggle source
    # File lib/nokogiri/html/document_fragment.rb, line 17
17:       def initialize document, tags = nil, ctx = nil
18:         return self unless tags
19: 
20:         if ctx
21:           preexisting_errors = document.errors.dup
22:           node_set = ctx.parse("<div>#{tags}</div>")
23:           node_set.first.children.each { |child| child.parent = self } unless node_set.empty?
24:           self.errors = document.errors - preexisting_errors
25:         else
26:           # This is a horrible hack, but I don't care
27:           if tags.strip =~ /^<body/
28:             path = "/html/body"
29:           else
30:             path = "/html/body/node()"
31:           end
32: 
33:           temp_doc = HTML::Document.parse "<html><body>#{tags}", nil, document.encoding
34:           temp_doc.xpath(path).each { |child| child.parent = self }
35:           self.errors = temp_doc.errors
36:         end
37:         children
38:       end
parse(tags, encoding = nil) click to toggle source
  

Create a Nokogiri::XML::DocumentFragment from tags, using encoding

    # File lib/nokogiri/html/document_fragment.rb, line 8
 8:       def self.parse tags, encoding = nil
 9:         doc = HTML::Document.new
10: 
11:         encoding ||= tags.respond_to?(:encoding) ? tags.encoding.name : 'UTF-8'
12:         doc.encoding = encoding
13: 
14:         new(doc, tags)
15:       end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.