Class: Nokolexbor::DocumentFragment

Inherits:
Node
  • Object
show all
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

#document

Class Method Summary collapse

Instance Method Summary collapse

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, #attributes, #attrs, #before, #cdata?, #child, #children, #children=, #classes, #clone, #comment?, #content, #content=, #css, #css_impl, #destroy, #document?, #each, #element?, #first_element_child, #fragment?, #inner_html, #key?, #keys, #keywordify, #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, #prepend_child, #previous, #previous_element, #processing_instruction?, #remove, #remove_attr, #remove_class, #replace, #search, #text?, #traverse, #values, #wrap, #write_to, #xpath

Constructor Details

#initialize(document, tags = nil, ctx = nil) ⇒ DocumentFragment

Returns a new instance of DocumentFragment.



9
10
11
12
13
14
15
16
# File 'lib/nokolexbor/document_fragment.rb', line 9

def initialize(document, tags = nil, ctx = nil)
  return self unless tags

  ctx ||= document
  node_set = ctx.parse(tags)
  node_set.each { |child| child.parent = self } unless node_set.empty?
  nil
end

Class Method Details

.new(*args) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'ext/nokolexbor/nl_document_fragment.c', line 7

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) ⇒ Object



5
6
7
# File 'lib/nokolexbor/document_fragment.rb', line 5

def self.parse(tags)
  new(Nokolexbor::Document.new, tags, nil)
end

Instance Method Details

#fragment(data) ⇒ Object



27
28
29
# File 'lib/nokolexbor/document_fragment.rb', line 27

def fragment(data)
  document.fragment(data)
end

#nameObject



18
19
20
# File 'lib/nokolexbor/document_fragment.rb', line 18

def name
  "#document-fragment"
end