html-proofer 1.1.6 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: af929be3f389ca9ac9d1fc449552207eaf5d983a
4
- data.tar.gz: 4197105516d8e7e6cf4768ca57d5e45996aef9ee
3
+ metadata.gz: 216684fe16feed0b7dedc9facd8a4a878a8879bc
4
+ data.tar.gz: af2b3852d0ae1fec97402b28c93b996304317faa
5
5
  SHA512:
6
- metadata.gz: 82d3cffe4c8295939d0140a5e0ad297fed56dfbf0031700eb28eeb2bebb9e187f5cfc7587042a23b9534276f7530f63aeddfb7635993426bbbc1476a3ab4c06f
7
- data.tar.gz: d8a50d7cb65def4b4f7ca9be03d0ae1ceac83b495cb34f9d7501650a8cac2a1c072a2a25a8b186f1b5459a52559fb39afe8581f16ff388e4cbce4c21e8a91e06
6
+ metadata.gz: 0a5dc4f9572d363911a456b89ee85b5a08b1cba942b7ae2de53c19c0a514e2a9d3b10a1f6f8fe57988cd31b7ec9fd21b0cb9bbe6d073bb2ce0ebcebff3a6c70f
7
+ data.tar.gz: eeb376dbe6e5332583440905e630c5ebcc4c15962bef056d235a8ce9fecfa269e2d50bb54386e8606f32c0f1c9eca51f8d7e107b105f8ecaf79b71c97a4b187d
@@ -3,7 +3,7 @@ $:.push File.expand_path("../lib", __FILE__)
3
3
 
4
4
  Gem::Specification.new do |gem|
5
5
  gem.name = "html-proofer"
6
- gem.version = "1.1.6"
6
+ gem.version = "1.2.0"
7
7
  gem.authors = ["Garen Torikian"]
8
8
  gem.email = ["gjtorikian@gmail.com"]
9
9
  gem.description = %q{Test your rendered HTML files to make sure they're accurate.}
@@ -38,14 +38,14 @@ module HTML
38
38
  total_files = 0
39
39
  external_urls = {}
40
40
 
41
- logger.info "Running #{get_checks} checks on #{@src} on *#{@options[:ext]}... \n\n".white
41
+ logger.info colorize :white, "Running #{get_checks} checks on #{@src} on *#{@options[:ext]}... \n\n"
42
42
 
43
43
  files.each do |path|
44
44
  total_files += 1
45
45
  html = HTML::Proofer.create_nokogiri(path)
46
46
 
47
47
  get_checks.each do |klass|
48
- logger.debug "Checking #{klass.to_s.downcase} on #{path} ...".blue
48
+ logger.debug colorize :blue, "Checking #{klass.to_s.downcase} on #{path} ..."
49
49
  check = Object.const_get(klass).new(@src, path, html, @options)
50
50
  check.run
51
51
  external_urls.merge!(check.external_urls)
@@ -55,20 +55,20 @@ module HTML
55
55
 
56
56
  external_link_checker(external_urls) unless @options[:disable_external]
57
57
 
58
- logger.info "Ran on #{total_files} files!\n\n".green
58
+ logger.info colorize :green, "Ran on #{total_files} files!\n\n"
59
59
  else
60
60
  external_urls = Hash[*@src.map{ |s| [s, nil] }.flatten]
61
61
  external_link_checker(external_urls) unless @options[:disable_external]
62
62
  end
63
63
 
64
64
  if @failed_tests.empty?
65
- logger.info "HTML-Proofer finished successfully.".green
65
+ logger.info colorize :green, "HTML-Proofer finished successfully."
66
66
  else
67
67
  @failed_tests.sort.each do |issue|
68
68
  logger.error issue.to_s.red
69
69
  end
70
70
 
71
- raise "HTML-Proofer found #{@failed_tests.length} failures!".red
71
+ raise colorize :red, "HTML-Proofer found #{@failed_tests.length} failures!"
72
72
  end
73
73
  end
74
74
 
@@ -80,7 +80,7 @@ module HTML
80
80
  def external_link_checker(external_urls)
81
81
  external_urls = Hash[external_urls.sort]
82
82
 
83
- logger.info "Checking #{external_urls.length} external links...".yellow
83
+ logger.info colorize :yellow, "Checking #{external_urls.length} external links..."
84
84
 
85
85
  # Typhoeus won't let you pass any non-Typhoeus option
86
86
  @proofer_opts.each_key do |opt|
@@ -90,14 +90,18 @@ module HTML
90
90
  Ethon.logger = logger # log from Typhoeus/Ethon
91
91
 
92
92
  external_urls.each_pair do |href, filenames|
93
- request = Typhoeus::Request.new(href, @options.merge({:method => :head}))
94
- request.on_complete { |response| response_handler(response, filenames) }
95
- hydra.queue request
93
+ queue_request(:head, href, filenames)
96
94
  end
97
- logger.debug "Running requests for all #{hydra.queued_requests.size} external URLs...".yellow
95
+ logger.debug colorize :yellow, "Running requests for all #{hydra.queued_requests.size} external URLs..."
98
96
  hydra.run
99
97
  end
100
98
 
99
+ def queue_request(method, href, filenames)
100
+ request = Typhoeus::Request.new(href, @options.merge({:method => method}))
101
+ request.on_complete { |response| response_handler(response, filenames) }
102
+ hydra.queue request
103
+ end
104
+
101
105
  def response_handler(response, filenames)
102
106
  href = response.options[:effective_url]
103
107
  method = response.request.options[:method]
@@ -116,13 +120,11 @@ module HTML
116
120
  elsif (response_code == 405 || response_code == 420 || response_code == 503) && method == :head
117
121
  # 420s usually come from rate limiting; let's ignore the query and try just the path with a GET
118
122
  uri = URI(href)
119
- next_response = Typhoeus.get(uri.scheme + "://" + uri.host + uri.path, @options)
120
- response_handler(next_response, filenames)
123
+ queue_request(:get, uri.scheme + "://" + uri.host + uri.path, filenames)
121
124
  # just be lazy; perform an explicit get request. some servers are apparently not configured to
122
125
  # intercept HTTP HEAD
123
126
  elsif method == :head
124
- next_response = Typhoeus.get(href, @options)
125
- response_handler(next_response, filenames)
127
+ queue_request(:get, href, filenames)
126
128
  else
127
129
  # Received a non-successful http response.
128
130
  failed_test_msg = "External link #{href} failed: #{response_code} #{response.return_message}"
@@ -158,5 +160,13 @@ module HTML
158
160
  def log_level
159
161
  @options[:verbose] ? :debug : :info
160
162
  end
163
+
164
+ def colorize(color, string)
165
+ if $stdout.isatty && $stderr.isatty
166
+ Colored.colorize(string, :foreground => color)
167
+ else
168
+ string
169
+ end
170
+ end
161
171
  end
162
172
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: html-proofer
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.6
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Garen Torikian