Class: Dommy::DOMImplementation

Inherits:
Object
  • Object
show all
Includes:
Bridge::Methods
Defined in:
lib/dommy/document.rb

Overview

‘document.implementation` — the DOMImplementation. Only the node factories WPT exercises are provided; createDocument/createHTMLDocument are not yet implemented (foreign documents).

Instance Method Summary collapse

Methods included from Bridge::Methods

included

Constructor Details

#initialize(document) ⇒ DOMImplementation

Returns a new instance of DOMImplementation.



254
255
256
# File 'lib/dommy/document.rb', line 254

def initialize(document)
  @document = document
end

Instance Method Details

#__js_call__(method, args) ⇒ Object



288
289
290
291
292
293
294
295
296
297
# File 'lib/dommy/document.rb', line 288

def __js_call__(method, args)
  case method
  when "createDocumentType"
    create_document_type(args[0], args[1], args[2])
  when "createDocument"
    create_document(args[0], args[1], args[2])
  when "createHTMLDocument"
    create_html_document(args[0])
  end
end

#__js_get__(_key) ⇒ Object



284
# File 'lib/dommy/document.rb', line 284

def __js_get__(_key) = nil

#create_document(namespace, qualified_name, _doctype = nil) ⇒ Object

createDocument(namespace, qualifiedName, doctype?) — a fresh XML document, with a document element (namespace, qualifiedName) when qualifiedName is non-empty. (The doctype argument is accepted but not stored, as document equality compares only structure that survives wrap_node.)



266
267
268
269
270
271
272
273
274
# File 'lib/dommy/document.rb', line 266

def create_document(namespace, qualified_name, _doctype = nil)
  doc = Document.new(nil, nokogiri_doc: Backend.document_class.new)
  qn = qualified_name.to_s
  unless qn.empty?
    el = doc.send(:create_element_ns, namespace, qualified_name)
    doc.nokogiri_doc.root = el.__dommy_backend_node__
  end
  doc
end

#create_document_type(qualified_name, public_id, system_id) ⇒ Object



258
259
260
# File 'lib/dommy/document.rb', line 258

def create_document_type(qualified_name, public_id, system_id)
  DocumentType.new(qualified_name, public_id, system_id)
end

#create_html_document(title = nil) ⇒ Object

createHTMLDocument(title?) — a fresh HTML document (doctype + html > head, body), with an optional <title>.



278
279
280
281
282
# File 'lib/dommy/document.rb', line 278

def create_html_document(title = nil)
  doc = Document.new(nil, nokogiri_doc: Backend.parse("<!DOCTYPE html><html><head></head><body></body></html>"))
  doc.title = title.to_s unless title.nil? || title.equal?(Bridge::UNDEFINED)
  doc
end