Methods

Class Index [+]

Quicksearch

Nokogiri::HTML::DocumentFragment

Public Class Methods

new(document, tags = nil, ctx = nil) click to toggle source
    # File lib/nokogiri/html/document_fragment.rb, line 15
15:       def initialize document, tags = nil, ctx = nil
16:         return self unless tags
17: 
18:         children = if ctx
19:                      ctx.parse("<div>#{tags.strip}</div>").first.children
20:                    else
21:                      ###
22:                      # This is a horrible hack, but I don't care
23:                      if tags.strip =~ /^<body/
24:                        path = "/html/body"
25:                      else
26:                        path = "/html/body/node()"
27:                      end
28: 
29:                      HTML::Document.parse(
30:                        "<html><body>#{tags.strip}</body></html>",
31:                        nil,
32:                        document.encoding
33:                      ).xpath(path)
34:                    end
35:         children.each { |child| child.parent = self }
36:       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 6
 6:       def self.parse tags, encoding = nil
 7:         doc = HTML::Document.new
 8: 
 9:         encoding ||= tags.respond_to?(:encoding) ? tags.encoding.name : 'UTF-8'
10:         doc.encoding = encoding
11: 
12:         new(doc, tags)
13:       end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.