Class: Nokolexbor::DocumentFragment
- Defined in:
- lib/nokolexbor/document_fragment.rb,
ext/nokolexbor/nl_document_fragment.c
Constant Summary
Constants inherited from Node
Node::ATTRIBUTE_NODE, Node::CDATA_SECTION_NODE, Node::COMMENT_NODE, Node::DOCUMENT_FRAG_NODE, Node::DOCUMENT_NODE, Node::DOCUMENT_TYPE_NODE, Node::ELEMENT_NODE, Node::ENTITY_NODE, Node::ENTITY_REF_NODE, Node::LOOKS_LIKE_XPATH, Node::NOTATION_NODE, Node::PI_NODE, Node::TEXT_NODE
Instance Attribute Summary
Attributes inherited from Node
Class Method Summary collapse
-
.new(document, tags = nil, ctx = nil) ⇒ DocumentFragment
Create a DocumentFragment from
tags
. -
.parse(tags) ⇒ DocumentFragment
Create a DocumentFragment from
tags
.
Instance Method Summary collapse
-
#fragment(data) ⇒ DocumentFragment
Create a DocumentFragment from
data
. -
#initialize(document, tags = nil, ctx = nil) ⇒ DocumentFragment
constructor
Create a new DocumentFragment from
tags
. -
#name ⇒ String
The name of DocumentFragment.
Methods inherited from Node
#<<, #==, #[], #[]=, #add_child, #add_class, #add_next_sibling, #add_previous_sibling, #add_sibling, #after, #ancestors, #append_class, #at, #at_css, #at_css_impl, #at_xpath, #attribute, #attribute_nodes, #attributes, #attrs, #before, #cdata?, #child, #children, #children=, #classes, #clone, #comment?, #content, #content=, #css, #css_impl, #css_path, #destroy, #document?, #each, #element?, #element_children, #first_element_child, #fragment?, #inner_html, #inspect, #key?, #keys, #kwattr_add, #kwattr_append, #kwattr_remove, #kwattr_values, #last_element_child, #matches?, #next, #next_element, #node_type, #nokogiri_at_css, #nokogiri_css, #parent, #parent=, #parse, #path, #prepend_child, #previous, #previous_element, #processing_instruction?, #remove, #remove_attr, #remove_class, #replace, #search, #source_location, #swap, #text?, #traverse, #value?, #values, #wrap, #write_to, #xpath
Constructor Details
#initialize(document, tags = nil, ctx = nil) ⇒ DocumentFragment
Create a new Nokolexbor::DocumentFragment from tags
.
If +ctx+ is present, it is used as a context node for the
subtree created.
16 17 18 19 20 21 22 23 |
# File 'lib/nokolexbor/document_fragment.rb', line 16 def initialize(document, = nil, ctx = nil) return self unless ctx ||= document node_set = ctx.parse() node_set.each { |child| child.parent = self } unless node_set.empty? nil end |
Class Method Details
.new(document, tags = nil, ctx = nil) ⇒ DocumentFragment
Create a Nokolexbor::DocumentFragment from tags
.
If ctx
is present, it is used as a context node for the subtree created.
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'ext/nokolexbor/nl_document_fragment.c', line 16
static VALUE
nl_document_fragment_new(int argc, VALUE *argv, VALUE klass)
{
lxb_dom_document_t *document;
VALUE rb_document;
VALUE rest;
rb_scan_args(argc, argv, "1*", &rb_document, &rest);
if (!rb_obj_is_kind_of(rb_document, cNokolexborDocument)) {
rb_raise(rb_eArgError, "Document must be a Nokolexbor::Document");
}
document = nl_rb_document_unwrap(rb_document);
lxb_dom_document_fragment_t *node = lxb_dom_document_create_document_fragment(document);
if (node == NULL) {
rb_raise(rb_eRuntimeError, "Error creating document fragment");
}
VALUE rb_node = nl_rb_node_create(&node->node, rb_document);
rb_obj_call_init(rb_node, argc, argv);
return rb_node;
}
|
.parse(tags) ⇒ DocumentFragment
Create a Nokolexbor::DocumentFragment from tags
.
8 9 10 |
# File 'lib/nokolexbor/document_fragment.rb', line 8 def self.parse() new(Nokolexbor::Document.new, , nil) end |
Instance Method Details
#fragment(data) ⇒ DocumentFragment
Create a Nokolexbor::DocumentFragment from data
.
38 39 40 |
# File 'lib/nokolexbor/document_fragment.rb', line 38 def fragment(data) document.fragment(data) end |
#name ⇒ String
Returns The name of Nokolexbor::DocumentFragment.
26 27 28 |
# File 'lib/nokolexbor/document_fragment.rb', line 26 def name "#document-fragment" end |