Skip to content
Snippets Groups Projects

Feature to create directly addressed Todos when mentioned in beginning

All threads resolved!
Compare and Show latest version
3 files
+ 108
148
Compare changes
  • Side-by-side
  • Inline
Files
3
+ 16
10
@@ -15,7 +15,6 @@ def css(document, query, reference_options = {})
@@ -15,7 +15,6 @@ def css(document, query, reference_options = {})
# When using "a.foo" Nokogiri compiles this to "//a[...]" but
# When using "a.foo" Nokogiri compiles this to "//a[...]" but
# "descendant::a[...]" is quite a bit faster and achieves the same result.
# "descendant::a[...]" is quite a bit faster and achieves the same result.
xpath = Nokogiri::CSS.xpath_for(query)[0].gsub(%r{^//}, 'descendant::')
xpath = Nokogiri::CSS.xpath_for(query)[0].gsub(%r{^//}, 'descendant::')
nodes = document.xpath(xpath)
nodes = document.xpath(xpath)
filter_nodes(nodes, reference_options)
filter_nodes(nodes, reference_options)
end
end
@@ -28,25 +27,32 @@ def filter_nodes(nodes, reference_options)
@@ -28,25 +27,32 @@ def filter_nodes(nodes, reference_options)
end
end
end
end
# Selects nodes which are present in the beginning of the document.
# Selects child nodes if they are present in the beginning among other siblings.
#
#
# nodes - A Nokogiri::XML::NodeSet.
# nodes - A Nokogiri::XML::NodeSet.
#
#
# Returns an array of Nokogiri::XML::Element objects.
# Returns an array of Nokogiri::XML::Element objects.
def filter_nodes_at_beginning(nodes)
def filter_nodes_at_beginning(nodes)
parent = nodes.first.parent
parents_and_nodes = nodes.group_by(&:parent)
children = parent.children
nodes = nodes.to_a
filtered_nodes = []
filtered_nodes = []
children.each do |child|
parents_and_nodes.each do |parent, nodes|
next if child.text.blank?
children = parent.children
node = nodes.shift
nodes = nodes.to_a
break unless node == child
filtered_nodes << node
children.each do |child|
 
next if can_be_skipped?(child)
 
node = nodes.shift
 
break unless node == child
 
filtered_nodes << node
 
end
end
end
filtered_nodes
filtered_nodes
end
end
 
 
def can_be_skipped?(node)
 
node.text.blank? || node.text.strip == ','
 
end
end
end
end
end
Loading