Added ReferenceFilter#nodes
This method returns an Array of the HTML nodes as yielded by ReferenceFilter#each_node. The method's return value is memoized to allow multiple calls without having to re-query the input document.
This commit is contained in:
parent
2fbfb85492
commit
8a6c3f27e9
|
@ -80,6 +80,11 @@ module Banzai
|
|||
end
|
||||
end
|
||||
|
||||
# Returns an Array containing all HTML nodes.
|
||||
def nodes
|
||||
@nodes ||= each_node.to_a
|
||||
end
|
||||
|
||||
# Yields the link's URL and text whenever the node is a valid <a> tag.
|
||||
def yield_valid_link(node)
|
||||
link = CGI.unescape(node.attr('href').to_s)
|
||||
|
|
|
@ -33,4 +33,13 @@ describe Banzai::Filter::ReferenceFilter, lib: true do
|
|||
expect { |b| filter.each_node(&b) }.not_to yield_control
|
||||
end
|
||||
end
|
||||
|
||||
describe '#nodes' do
|
||||
it 'returns an Array of the HTML nodes' do
|
||||
document = Nokogiri::HTML.fragment('<a href="foo">foo</a>')
|
||||
filter = described_class.new(document, project: project)
|
||||
|
||||
expect(filter.nodes).to eq([document.children[0]])
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue