lib/xml/mixup.rb in xml-mixup-0.1.3 vs lib/xml/mixup.rb in xml-mixup-0.1.4
- old
+ new
@@ -1,36 +1,37 @@
require 'xml/mixup/version'
require 'nokogiri'
+require 'set'
module XML::Mixup
#
# these are node attachment protocols
private
ADJACENT = {
- parent: lambda do |node, parent|
- if parent.node_type == 9 and node.node_type == 1
- parent.root = node
- elsif node.node_type == 11
- node.children.each do |child|
- parent.add_child(child)
- end
- else
- parent.add_child(node)
- end
- end,
- before: lambda do |node, sibling|
- sibling.add_previous_sibling node
- end,
- after: lambda { |node, sibling| sibling.add_next_sibling node },
- replace: lambda { |node, target| target.replace node },
- }.freeze
+ parent: lambda do |node, parent|
+ if parent.node_type == 9 and node.node_type == 1
+ parent.root = node
+ elsif node.node_type == 11
+ node.children.each do |child|
+ parent.add_child(child)
+ end
+ else
+ parent.add_child(node)
+ end
+ end,
+ before: lambda do |node, sibling|
+ sibling.add_previous_sibling node
+ end,
+ after: lambda { |node, sibling| sibling.add_next_sibling node },
+ replace: lambda { |node, target| target.replace node },
+ }.freeze
- RESERVED = %w{comment cdata doctype dtd elem element
- pi processing-instruction tag}.map {|x| "##{x}"}.to_set.freeze
+ RESERVED = Set.new(%w{comment cdata doctype dtd elem element
+ pi processing-instruction tag}.map {|x| "##{x}"}).freeze
public
# Generate a handy blank document.
#
@@ -476,10 +477,10 @@
def element tag, doc: nil, ns: {}, attr: {}, args: []
raise 'Document node must be present' unless doc
prefix = local = nil
if tag.respond_to? :to_a
prefix, local = tag
- tag = tag.join ':'
+ tag = tag[0..1].join ':'
end
elem = doc.create_element tag.to_s
ns.sort.each do |p, u|
elem.add_namespace((p.nil? ? p : p.to_s), u.to_s)
end