Module: Dommy::Backend::Nokogiri

Defined in:
lib/dommy/backend/nokogiri_adapter.rb

Overview

Nokogiri (libxml2-based) backend. Mature, full XML namespace support. Default backend.

Constant Summary collapse

Element =

Class references for ‘is_a?` / type-checking from Dommy internals.

::Nokogiri::XML::Element
Document =
::Nokogiri::XML::Document
Text =
::Nokogiri::XML::Text
Comment =
::Nokogiri::XML::Comment
DocumentFragment =
::Nokogiri::XML::DocumentFragment
Node =
::Nokogiri::XML::Node

Class Method Summary collapse

Class Method Details

.add_namespace_definition(node, prefix, href) ⇒ Object



46
47
48
# File 'lib/dommy/backend/nokogiri_adapter.rb', line 46

def add_namespace_definition(node, prefix, href)
  node.add_namespace_definition(prefix, href)
end

.create_comment(content, doc) ⇒ Object



38
39
40
# File 'lib/dommy/backend/nokogiri_adapter.rb', line 38

def create_comment(content, doc)
  ::Nokogiri::XML::Comment.new(doc, content)
end

.create_element(name, doc) ⇒ Object



30
31
32
# File 'lib/dommy/backend/nokogiri_adapter.rb', line 30

def create_element(name, doc)
  ::Nokogiri::XML::Node.new(name, doc)
end

.create_text(content, doc) ⇒ Object



34
35
36
# File 'lib/dommy/backend/nokogiri_adapter.rb', line 34

def create_text(content, doc)
  ::Nokogiri::XML::Text.new(content, doc)
end

.fragment(html, owner_doc:) ⇒ Object



24
25
26
27
28
# File 'lib/dommy/backend/nokogiri_adapter.rb', line 24

def fragment(html, owner_doc:)
  # owner_doc is unused by Nokogiri — the fragment carries its
  # own document. The Parser layer copies nodes into the target.
  ::Nokogiri::HTML5.fragment(html.to_s, max_errors: 0)
end

.namespace_of(node) ⇒ Object



42
43
44
# File 'lib/dommy/backend/nokogiri_adapter.rb', line 42

def namespace_of(node)
  node.namespace
end

.parse(html) ⇒ Object



20
21
22
# File 'lib/dommy/backend/nokogiri_adapter.rb', line 20

def parse(html)
  ::Nokogiri::HTML5(html.to_s, max_errors: 0)
end