class ValidateWebsite::Static
Class for validation Static
website
Constants
- CONTENT_TYPES
- START_MESSAGE_TYPE
Attributes
history_count[R]
Public Class Methods
fake_httpresponse(body, content_types = CONTENT_TYPES)
click to toggle source
Fake http response for Spidr static crawling see github.com/ruby/ruby/blob/trunk/lib/net/http/response.rb
@param [String] response body @param [Array] content types @return [Net::HTTPResponse] fake http response
# File lib/validate_website/static.rb, line 43 def self.fake_httpresponse(body, content_types = CONTENT_TYPES) response = Net::HTTPResponse.new '1.1', 200, 'OK' response.instance_variable_set(:@read, true) response.body = body content_types.each do |c| response.add_field('content-type', c) end response end
new(options = {}, validation_type = :static)
click to toggle source
Calls superclass method
ValidateWebsite::Core::new
# File lib/validate_website/static.rb, line 14 def initialize(options = {}, validation_type = :static) @history_count = 0 super start_message("#{START_MESSAGE_TYPE} in #{Dir.pwd} (#{@site} as site)") end
Public Instance Methods
crawl(options = {})
click to toggle source
@param [Hash] options
# File lib/validate_website/static.rb, line 22 def crawl(options = {}) @options = @options.merge(options) @site = @options[:site] files = Dir.glob(@options[:pattern]) files.each do |file| next unless File.file?(file) next if @options[:exclude]&.match(file) @history_count += 1 check_static_file(file) end print_status_line(files.size, 0, @not_founds_count, @errors_count) end
Private Instance Methods
check_page(file, page)
click to toggle source
# File lib/validate_website/static.rb, line 61 def check_page(file, page) if page.html? && options[:markup] keys = %i[ignore html5_validator] slice = options.slice(*keys) validate(page.doc, page.body, file, slice) end check_static_not_found(page.links, page.url.to_s) if options[:not_found] end
check_static_file(file)
click to toggle source
# File lib/validate_website/static.rb, line 55 def check_static_file(file) page = StaticLink.new(file, @site).page check_page(file, page) check_css_syntax(page) if page.css? && options[:css_syntax] end
check_static_not_found(links, site = @site)
click to toggle source
check files linked on static document see lib/validate_website/runner.rb
# File lib/validate_website/static.rb, line 72 def check_static_not_found(links, site = @site) static_links = links.map { |l| StaticLink.new(l, site) } static_links.each do |static_link| next unless static_link.check? unless File.exist?(static_link.file_path) not_found_error(static_link.file_path) next end next unless static_link.css? check_static_not_found static_link.extract_urls_from_fake_css_response end end