lib/string_doc.rb in pakyow-presenter-1.0.0.rc3 vs lib/string_doc.rb in pakyow-presenter-1.0.0.rc4
- old
+ new
@@ -169,17 +169,30 @@
instance.instance_variable_set(:@collapsed, @collapsed)
instance
end
+ def finalize_labels(keep: [])
+ @nodes.each do |node|
+ node.finalize_labels(keep: keep)
+ end
+ end
+
include Enumerable
def each(descend: false, &block)
return enum_for(:each, descend: descend) unless block_given?
@nodes.each do |node|
- yield node
+ case node
+ when MetaNode
+ node.each do |each_meta_node|
+ yield each_meta_node
+ end
+ else
+ yield node
+ end
if descend || node.label(:descend) != false
if node.children.is_a?(StringDoc)
node.children.each(descend: descend, &block)
else
@@ -193,11 +206,22 @@
#
def each_significant_node(type, descend: false)
return enum_for(:each_significant_node, type, descend: descend) unless block_given?
each(descend: descend) do |node|
- yield node if (node.is_a?(Node) || node.is_a?(MetaNode)) && node.significant?(type)
+ case node
+ when MetaNode
+ if node.significant?(type)
+ node.each do |each_meta_node|
+ yield each_meta_node
+ end
+ end
+ when Node
+ if node.significant?(type)
+ yield node
+ end
+ end
end
end
# Yields each node matching the significant type, without descending into nodes that are of that type.
#
@@ -205,11 +229,18 @@
return enum_for(:each_significant_node_without_descending_into_type, type, descend: descend) unless block_given?
@nodes.each do |node|
if node.is_a?(Node) || node.is_a?(MetaNode)
if node.significant?(type)
- yield node
+ case node
+ when MetaNode
+ node.each do |each_meta_node|
+ yield each_meta_node
+ end
+ when Node
+ yield node
+ end
else
if descend || node.label(:descend) != false
if node.children.is_a?(StringDoc)
node.children.each_significant_node_without_descending_into_type(type, descend: descend, &block)
else
@@ -365,10 +396,10 @@
# Removes a node from the document.
#
def remove_node(node_to_delete)
tap do
@nodes.delete_if { |node|
- node.object_id == node_to_delete.object_id
+ node.equal?(node_to_delete)
}
end
end
# Replaces a node from the document.