Class: Nokogiri::HTML5::DocumentFragment
- Inherits:
-
Nokogiri::HTML::DocumentFragment
- Object
- Nokogiri::HTML::DocumentFragment
- Nokogiri::HTML5::DocumentFragment
- Defined in:
- lib/nokogumbo/html5/document_fragment.rb
Instance Attribute Summary collapse
-
#document ⇒ Object
Returns the value of attribute document.
-
#errors ⇒ Object
Returns the value of attribute errors.
Class Method Summary collapse
-
.parse(tags, encoding = nil, options = {}) ⇒ Object
Parse a document fragment from
tags
, returning a Nodeset.
Instance Method Summary collapse
-
#extract_params(params) ⇒ Object
:nodoc:.
-
#initialize(doc, tags = nil, ctx = nil, options = {}) ⇒ DocumentFragment
constructor
Create a document fragment.
- #serialize(options = {}, &block) ⇒ Object
Constructor Details
#initialize(doc, tags = nil, ctx = nil, options = {}) ⇒ DocumentFragment
Create a document fragment.
10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/nokogumbo/html5/document_fragment.rb', line 10 def initialize(doc, = nil, ctx = nil, = {}) self.document = doc self.errors = [] return self unless max_attributes = [:max_attributes] || Nokogumbo::DEFAULT_MAX_ATTRIBUTES max_errors = [:max_errors] || Nokogumbo::DEFAULT_MAX_ERRORS max_depth = [:max_tree_depth] || Nokogumbo::DEFAULT_MAX_TREE_DEPTH = Nokogiri::HTML5.read_and_encode(, nil) Nokogumbo.fragment(self, , ctx, max_attributes, max_errors, max_depth) end |
Instance Attribute Details
#document ⇒ Object
Returns the value of attribute document.
6 7 8 |
# File 'lib/nokogumbo/html5/document_fragment.rb', line 6 def document @document end |
#errors ⇒ Object
Returns the value of attribute errors.
7 8 9 |
# File 'lib/nokogumbo/html5/document_fragment.rb', line 7 def errors @errors end |
Class Method Details
.parse(tags, encoding = nil, options = {}) ⇒ Object
Parse a document fragment from tags
, returning a Nodeset.
29 30 31 32 33 34 |
# File 'lib/nokogumbo/html5/document_fragment.rb', line 29 def self.parse(, encoding = nil, = {}) doc = HTML5::Document.new = HTML5.read_and_encode(, encoding) doc.encoding = 'UTF-8' new(doc, , nil, ) end |
Instance Method Details
#extract_params(params) ⇒ Object
:nodoc:
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/nokogumbo/html5/document_fragment.rb', line 36 def extract_params params # :nodoc: handler = params.find do |param| ![Hash, String, Symbol].include?(param.class) end params -= [handler] if handler hashes = [] while Hash === params.last || params.last.nil? hashes << params.pop break if params.empty? end ns, binds = hashes.reverse ns ||= begin ns = Hash.new children.each { |child| ns.merge!(child.namespaces) } ns end [params, handler, ns, binds] end |
#serialize(options = {}, &block) ⇒ Object
22 23 24 25 26 |
# File 'lib/nokogumbo/html5/document_fragment.rb', line 22 def serialize( = {}, &block) # Bypass XML::Document.serialize which doesn't support options even # though XML::Node.serialize does! XML::Node.instance_method(:serialize).bind(self).call(, &block) end |