Class: Dommy::DocumentType
- Inherits:
-
Object
- Object
- Dommy::DocumentType
- Includes:
- Bridge::Methods, EventTarget, Node
- Defined in:
- lib/dommy/document.rb
Overview
DocumentType (‘<!doctype html>`) — exposes name / publicId / systemId and nodeType=10. HTML5 doctypes carry empty public/system IDs, but `implementation.createDocumentType` can set them.
Constant Summary
Constants included from Node
Node::ATTRIBUTE_NODE, Node::CDATA_SECTION_NODE, Node::COMMENT_NODE, Node::DOCUMENT_FRAGMENT_NODE, Node::DOCUMENT_NODE, Node::DOCUMENT_POSITION_CONTAINED_BY, Node::DOCUMENT_POSITION_CONTAINS, Node::DOCUMENT_POSITION_DISCONNECTED, Node::DOCUMENT_POSITION_FOLLOWING, Node::DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC, Node::DOCUMENT_POSITION_PRECEDING, Node::DOCUMENT_TYPE_NODE, Node::ELEMENT_NODE, Node::HTML_NAMESPACE, Node::PROCESSING_INSTRUCTION_NODE, Node::TEXT_NODE
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #__internal_event_parent__ ⇒ Object
- #__js_call__(method, args) ⇒ Object
- #__js_get__(key) ⇒ Object
- #after(*nodes) ⇒ Object
- #before(*nodes) ⇒ Object
-
#initialize(name, public_id = "", system_id = "", owner_document: nil) ⇒ DocumentType
constructor
‘owner_document:` links a live doctype (document.doctype) to its document so the ChildNode methods (remove/before/after/replaceWith) act on the tree; a standalone doctype (DOMImplementation.createDocumentType) has none, so those methods are no-ops per spec.
-
#remove ⇒ Object
ChildNode mixin — the doctype’s parent is the document.
- #replace_with(*nodes) ⇒ Object
Methods included from Bridge::Methods
Methods included from EventTarget
#__internal_deliver_event__, #add_event_listener, capture_flag, #deliver_at, #dispatch_event, js_truthy?, #remove_event_listener
Methods included from Node
#compare_document_position, #get_root_node, #is_default_namespace, #is_equal_node, #is_same_node, #lookup_namespace_uri, #lookup_prefix
Constructor Details
#initialize(name, public_id = "", system_id = "", owner_document: nil) ⇒ DocumentType
‘owner_document:` links a live doctype (document.doctype) to its document so the ChildNode methods (remove/before/after/replaceWith) act on the tree; a standalone doctype (DOMImplementation.createDocumentType) has none, so those methods are no-ops per spec.
26 27 28 29 30 31 |
# File 'lib/dommy/document.rb', line 26 def initialize(name, public_id = "", system_id = "", owner_document: nil) @name = name.to_s @public_id = public_id.to_s @system_id = system_id.to_s @owner_document = owner_document end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
20 21 22 |
# File 'lib/dommy/document.rb', line 20 def name @name end |
Instance Method Details
#__internal_event_parent__ ⇒ Object
79 80 81 |
# File 'lib/dommy/document.rb', line 79 def __internal_event_parent__ nil end |
#__js_call__(method, args) ⇒ Object
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/dommy/document.rb', line 87 def __js_call__(method, args) case method when "hasChildNodes" false when "isEqualNode" is_equal_node(args[0]) when "isSameNode" is_same_node(args[0]) when "getRootNode" get_root_node(args[0]) when "compareDocumentPosition" compare_document_position(args[0]) when "appendChild", "insertBefore" raise DOMException::HierarchyRequestError, "a DocumentType may not have children" when "removeChild", "replaceChild" raise DOMException::NotFoundError, "the node to be removed is not a child of this node" when "before" before(*args) when "after" after(*args) when "replaceWith" replace_with(*args) when "remove" remove when "normalize" nil when "addEventListener" add_event_listener(args[0], args[1], args[2]) when "removeEventListener" remove_event_listener(args[0], args[1], args[2]) when "dispatchEvent" dispatch_event(args[0]) end end |
#__js_get__(key) ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/dommy/document.rb', line 61 def __js_get__(key) case key when "name" @name when "nodeName" # WHATWG: a DocumentType's nodeName is its name. @name when "nodeType" 10 when "publicId" @public_id when "systemId" @system_id end end |
#after(*nodes) ⇒ Object
46 47 48 49 50 51 |
# File 'lib/dommy/document.rb', line 46 def after(*nodes) return nil unless @owner_document @owner_document.__internal_insert_at_doctype__(nodes, after: true) nil end |
#before(*nodes) ⇒ Object
39 40 41 42 43 44 |
# File 'lib/dommy/document.rb', line 39 def before(*nodes) return nil unless @owner_document @owner_document.__internal_insert_at_doctype__(nodes, after: false) nil end |
#remove ⇒ Object
ChildNode mixin — the doctype’s parent is the document.
34 35 36 37 |
# File 'lib/dommy/document.rb', line 34 def remove @owner_document&.__internal_remove_doctype__(self) nil end |
#replace_with(*nodes) ⇒ Object
53 54 55 56 57 58 59 |
# File 'lib/dommy/document.rb', line 53 def replace_with(*nodes) return nil unless @owner_document @owner_document.__internal_insert_at_doctype__(nodes, after: false) remove nil end |