class SiteHealth::HTMLProofer
Checks for various HTML misstakes (backed by the excellent HTMLProofer
gem)
Protected Instance Methods
build_test_failures(failed_tests)
click to toggle source
@return [Array<String>] list failures
# File lib/site_health/checkers/html_proofer.rb, line 32 def build_test_failures(failed_tests) failed_tests.map do |failed_test| next if ignore_test_failure?(failed_test) failed_test.split('.html:').last.strip # Removes file name from error message end.compact end
check()
click to toggle source
# File lib/site_health/checkers/html_proofer.rb, line 14 def check tempfile(page.body) do |file| proofer = ::HTMLProofer.check_file(file.path, config.html_proofer.to_h) # NOTE: HTMLProofer raises if errors are found begin proofer.run rescue StandardError end errors = build_test_failures(proofer.failed_tests).each do |error| add_issue(title: error) end add_data(errors: errors) end end
ignore_test_failure?(failed_test)
click to toggle source
HTMLProofer
expects internal links to be present on disk, Jekyll-style, since we're checking remote pages we ignore those failures @return [TrueClass, FalseClass] returns true if the failed test should be ignored
# File lib/site_health/checkers/html_proofer.rb, line 43 def ignore_test_failure?(failed_test) return false unless config.html_proofer.ignore_missing_internal_links return true if failed_test.include?('internally linking to') return true if failed_test.include?('internal image') return true if failed_test.include?('internal script') false end
tempfile(string) { |file| ... }
click to toggle source
Creates a tempfile around the passed block @return [Object] whatever the passed block returns @yieldparam [Tempfile] the temporary file
# File lib/site_health/checkers/html_proofer.rb, line 55 def tempfile(string) file = Tempfile.new([name, '.html']) begin file.write(string) ensure file.close end yield(file).tap { file.unlink } end