Class: Makiri::Element
- Defined in:
- lib/makiri/element.rb,
ext/makiri/makiri.c
Overview
An HTML element node. Attribute access lives in C.
Class Method Summary collapse
-
.new(name, document) ⇒ Makiri::Element
Create a detached element named
nameowned bydocument(Nokogiri-style constructor; delegates to Document#create_element).
Instance Method Summary collapse
-
#content_fragment ⇒ Object
A <template> element’s “template contents” — the separate DocumentFragment the HTML parser fills instead of making the parsed nodes children of the <template> (WHATWG DOM ‘HTMLTemplateElement.content`; browsers behave the same: template.children is empty, template.content holds the nodes).
Methods inherited from Node
#<<, #==, #[], #[]=, #add_child, #add_class, #add_next_sibling, #add_previous_sibling, #after, #ancestors, #append_class, #at, #at_css, #at_xpath, #attribute, #attribute?, #attribute_nodes, #attributes, #before, #blank?, #child, #children, #classes, #comment?, #content, #content=, #css, #delete, #document, #document?, #document_fragment?, #element?, #element_children, #elements, #eql?, #first_element_child, #hash, #inner_html, #inner_html=, #inner_text, #inspect, #key?, #keys, #last_element_child, #line, #matches?, #name, #name=, #next, #next_element, #next_sibling, #node_type, #outer_html, #outer_html=, #parent, #parse, #path, #previous, #previous_element, #previous_sibling, #processing_instruction?, #remove, #remove_class, #replace, #root, #search, #set_attribute, #text, #text?, #to_h, #to_html, #to_s, #traverse, #unlink, #value, #values, #xpath
Class Method Details
.new(name, document) ⇒ Makiri::Element
Create a detached element named name owned by document (Nokogiri-style constructor; delegates to Document#create_element). Attach it with Node#add_child and friends.
13 14 15 |
# File 'lib/makiri/element.rb', line 13 def self.new(name, document) document.create_element(name) end |
Instance Method Details
#content_fragment ⇒ Object
A <template> element’s “template contents” — the separate DocumentFragment the HTML parser fills instead of making the parsed nodes children of the <template> (WHATWG DOM ‘HTMLTemplateElement.content`; browsers behave the same: template.children is empty, template.content holds the nodes). Lexbor stores it on the template interface; we surface it as a Makiri::DocumentFragment so it can be traversed/queried (`tpl.content_fragment.css(“p”)`).
Returns nil for any node that is not an HTML <template>. Note: CSS/XPath over the *template element itself* deliberately do NOT descend into the content (matching the DOM, and unavoidable for CSS since it runs Lexbor’s selector engine over the real tree) — query the fragment instead.
188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 |
# File 'ext/makiri/glue/ruby_node.c', line 188
static VALUE
mkr_node_content_fragment(VALUE self)
{
lxb_dom_node_t *node = mkr_node_unwrap(self);
if (node->type != LXB_DOM_NODE_TYPE_ELEMENT
|| node->local_name != LXB_TAG_TEMPLATE
|| node->ns != LXB_NS_HTML) {
return Qnil;
}
lxb_dom_document_fragment_t *content = lxb_html_interface_template(node)->content;
if (content == NULL) {
return Qnil;
}
return mkr_wrap_node((lxb_dom_node_t *)content, mkr_node_document(self));
}
|