Class: Dommy::DOMImplementation
- Inherits:
-
Object
- Object
- Dommy::DOMImplementation
- Includes:
- Bridge::Methods
- Defined in:
- lib/dommy/document.rb
Overview
document.implementation — the DOMImplementation.
Instance Method Summary collapse
- #__js_call__(method, args) ⇒ Object
-
#__js_get__(_key) ⇒ Object
method-only; any property read is absent.
-
#create_document(namespace, qualified_name, doctype = nil) ⇒ Object
createDocument(namespace, qualifiedName, doctype?) — a fresh XML document with, in tree order, the doctype (when given) then a document element (namespace, qualifiedName) when qualifiedName is non-empty.
-
#create_document_type(qualified_name, public_id, system_id) ⇒ Object
A created DocumentType's node document is the implementation's document.
-
#create_html_document(title = nil) ⇒ Object
createHTMLDocument(title?) — a fresh HTML document (doctype + html > head, body), with an optional
. -
#has_feature ⇒ Object
hasFeature()is a no-op that always returns true (DOM Standard). -
#initialize(document) ⇒ DOMImplementation
constructor
A new instance of DOMImplementation.
Methods included from Bridge::Methods
Constructor Details
#initialize(document) ⇒ DOMImplementation
Returns a new instance of DOMImplementation.
230 231 232 |
# File 'lib/dommy/document.rb', line 230 def initialize(document) @document = document end |
Instance Method Details
#__js_call__(method, args) ⇒ Object
322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 |
# File 'lib/dommy/document.rb', line 322 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" # title is an OPTIONAL DOMString: a missing or undefined argument leaves # the document title-less, but an explicit null coerces to "null". if args.empty? || args[0].equal?(Bridge::UNDEFINED) create_html_document else create_html_document(args[0].nil? ? "null" : args[0]) end when "hasFeature" has_feature end end |
#__js_get__(_key) ⇒ Object
method-only; any property read is absent
318 |
# File 'lib/dommy/document.rb', line 318 def __js_get__(_key) = Bridge::ABSENT # method-only; any property read is absent |
#create_document(namespace, qualified_name, doctype = nil) ⇒ Object
createDocument(namespace, qualifiedName, doctype?) — a fresh XML document with, in tree order, the doctype (when given) then a document element (namespace, qualifiedName) when qualifiedName is non-empty.
262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 |
# File 'lib/dommy/document.rb', line 262 def create_document(namespace, qualified_name, doctype = nil) doc = Document.new(nil, backend_doc: Backend.empty_xml_document) # createDocument's content type is keyed off the namespace. None is # "text/html", so tagName keeps its case; xhtml+xml still routes # createElement to the HTML namespace (so an XHTML document isEqualNode # an HTML one). doc.content_type = case namespace.to_s when Internal::Namespaces::HTML then "application/xhtml+xml" when Internal::Namespaces::SVG then "image/svg+xml" else "application/xml" end qn = qualified_name.to_s unless qn.empty? el = doc.send(:create_element_ns, namespace, qualified_name) Backend.set_document_root(doc.backend_doc, el.__dommy_backend_node__) end adopt_doctype_into(doc, doctype) doc end |
#create_document_type(qualified_name, public_id, system_id) ⇒ Object
A created DocumentType's node document is the implementation's document. When the backend ships a doctype factory (the HTML backend) and accepts the name, the result is a real, node-backed (but detached) DocumentType that can join the tree; otherwise it falls back to a synthetic one. (Qualified-name QName validation isn't enforced — createDocumentType is permissive, so the factory's stricter name check is bypassed via the synthetic fallback rather than raising; a couple of invalid-name WPT cases stay documented gaps.)
241 242 243 244 245 246 247 248 249 250 251 252 |
# File 'lib/dommy/document.rb', line 241 def create_document_type(qualified_name, public_id, system_id) qn = qualified_name.to_s pub = public_id.to_s sys = system_id.to_s node = begin Backend.create_document_type(qn, pub, sys, @document.backend_doc) rescue ArgumentError nil end node ? DocumentType.new(backend_node: node, document: @document) : DocumentType.new(qn, pub, sys, owner_document: @document) end |
#create_html_document(title = nil) ⇒ Object
createHTMLDocument(title?) — a fresh HTML document (doctype + html > head, body), with an optional
312 313 314 315 316 |
# File 'lib/dommy/document.rb', line 312 def create_html_document(title = nil) doc = Document.new(nil, backend_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 |
#has_feature ⇒ Object
hasFeature() is a no-op that always returns true (DOM Standard).
255 256 257 |
# File 'lib/dommy/document.rb', line 255 def has_feature(*) true end |