# frozen_string_literal: true module BrokenLinkFinder # Class responsible for reporting in a HTML format. class HTMLReporter < Reporter # Returns a new HTMLReporter instance. # stream is any Object that responds to :puts and :print. def initialize(stream, sort, broken_links, ignored_links, broken_link_map, crawl_stats) super end # Pretty print a report detailing the full link summary. def call(broken_verbose: true, ignored_verbose: false) puts '
Crawled %s
%s page(s) containing %s unique link(s) in %s seconds
element.
if verbose || (values.length <= NUM_VALUES)
values.each { |value| puts_group_item value, type: :broken }
else # Only print N values and summarise the rest.
NUM_VALUES.times { |i| puts_group_item values[i], type: :broken }
objects = sort_by_page? ? 'link(s)' : 'page(s)'
puts "+ #{values.length - NUM_VALUES} other #{objects}, remove --concise to see them all
"
end
puts '
element.
if verbose || (values.length <= NUM_VALUES)
values.each { |value| puts_group_item value, type: :ignored }
else # Only print N values and summarise the rest.
NUM_VALUES.times { |i| puts_group_item values[i], type: :ignored }
objects = sort_by_page? ? 'link(s)' : 'page(s)'
puts "+ #{values.length - NUM_VALUES} other #{objects}, use --verbose to see them all
"
end
puts '
#{text}
" end def puts_group(link, type:) href = build_url(link) a_element = "#{link}" case type when :broken msg = sort_by_page? ? "The following broken links were found on '#{a_element}':" : "The broken link '#{a_element}' was found on the following pages:" klass = 'broken_links_group' when :ignored msg = sort_by_page? ? "The following links were ignored on '#{a_element}':" : "The link '#{a_element}' was ignored on the following pages:" klass = 'ignored_links_group' else raise "type: must be :broken or :ignored, not: #{type}" end puts ""
puts msg + '
'
end
def puts_group_item(value, type:)
klass = (type == :broken) ? 'broken_links_group_item' : 'ignored_links_group_item'
puts "#{value}
"
end
def build_url(link)
href = @broken_link_map[link]
href || link
end
alias_method :report, :call
end
end