html-proofer 2.2.0 → 2.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0f952166651bac28c33d10ed6aa595797ecadcc6
4
- data.tar.gz: a0f9677119b32b2191b4e749a141c902f21f804e
3
+ metadata.gz: 5e5d2a78c7071f5534b4fb0d22c34337d9b92a6c
4
+ data.tar.gz: 4e89db1b52488116724d07608297d3abfb6581bb
5
5
  SHA512:
6
- metadata.gz: f293738658311d6e823917b9ede779d0314c0c3521e7b48629eec0ad2360952105626095984daf7126f6170d799b03f903553b2d7bd83b3a01e92de8d0a42f63
7
- data.tar.gz: 5945181a2600773c2102a7b256504cbc9902fa3645b53e4f73e6b46ea41422d73c79295f3012db6d76c44d46d2b1dda9ad639ee75f2515ce2142d4ea82e08d77
6
+ metadata.gz: 84e99216d622692010d127c80f4cf4a128b5391535169418a9715d99f1d0ccdfcbe3edf976ee769ce2d5021b1989c6e232d00de72ae8574f82eb29b925a0e269
7
+ data.tar.gz: 57e675836bb4a138dcfd84a0751772bbd99d05d3605dc8c1f922197683fe92a65563f0618393720a5ed3f44101025977f94f2dbf7cba96161def098148ad98ce
data/.travis.yml CHANGED
@@ -7,9 +7,6 @@ rvm:
7
7
  env:
8
8
  global:
9
9
  - NOKOGIRI_USE_SYSTEM_LIBRARIES=true
10
- addons:
11
- code_climate:
12
- repo_token:
13
10
 
14
11
  sudo: false
15
12
  cache: bundler
data/Gemfile CHANGED
@@ -1,5 +1,3 @@
1
1
  source 'http://rubygems.org'
2
2
 
3
3
  gemspec
4
-
5
- gem 'codeclimate-test-reporter', :group => :test, :require => nil
data/README.md CHANGED
@@ -4,7 +4,7 @@ If you generate HTML files, _then this tool might be for you_.
4
4
 
5
5
  `HTML::Proofer` is a set of tests to validate your HTML output. These tests check if your image references are legitimate, if they have alt tags, if your internal links are working, and so on. It's intended to be an all-in-one checker for your output.
6
6
 
7
- [![Build Status](https://travis-ci.org/gjtorikian/html-proofer.svg?branch=master)](https://travis-ci.org/gjtorikian/html-proofer) [![Gem Version](https://badge.fury.io/rb/html-proofer.svg)](http://badge.fury.io/rb/html-proofer) [![Test Coverage](https://codeclimate.com/github/gjtorikian/html-proofer/badges/coverage.svg)](https://codeclimate.com/github/gjtorikian/html-proofer)
7
+ [![Build Status](https://travis-ci.org/gjtorikian/html-proofer.svg?branch=master)](https://travis-ci.org/gjtorikian/html-proofer) [![Gem Version](https://badge.fury.io/rb/html-proofer.svg)](http://badge.fury.io/rb/html-proofer)
8
8
 
9
9
  ## Installation
10
10
 
@@ -149,6 +149,7 @@ The `HTML::Proofer` constructor takes an optional hash of additional options:
149
149
  | `href_ignore` | An array of Strings or RegExps containing `href`s that are safe to ignore. Note that non-HTTP(S) URIs are always ignored. | `[]` |
150
150
  | `href_swap` | A hash containing key-value pairs of `RegExp => String`. It transforms links that match `RegExp` into `String` via `gsub`. | `{}` |
151
151
  | `only_4xx` | Only reports errors for links that fall within the 4xx status code range. | `false` |
152
+ | `url_ignore` | An array of Strings or RegExps containing URLs that are safe to ignore. It affects all HTML attributes. Note that non-HTTP(S) URIs are always ignored. | `[]` |
152
153
  | `check_favicon` | Enables the favicon checker. | `false` |
153
154
  | `check_html` | Enables HTML validation errors from Nokogiri | `false` |
154
155
  | `verbose` | If `true`, outputs extra information as the checking happens. Useful for debugging. | `false` |
@@ -237,3 +238,28 @@ class MailToOctocat < ::HTML::Proofer::CheckRunner
237
238
  end
238
239
  end
239
240
  ```
241
+
242
+ ## Troubleshooting
243
+
244
+ ### Certificates
245
+
246
+ To ignore certificates turn off the Typhoeus SSL verification:
247
+
248
+ ``` ruby
249
+ HTML::Proofer.new("out/", {
250
+ :typhoeus => {
251
+ :ssl_verifypeer => false,
252
+ :ssl_verifyhost => 0}
253
+ }).run
254
+ ```
255
+
256
+ ### User-Agent
257
+
258
+ To change the User-Agent used by Typhoeus:
259
+
260
+ ``` ruby
261
+ HTML::Proofer.new("out/", {
262
+ :typhoeus => {
263
+ :headers => { "User-Agent" => "Mozilla/5.0 (compatible; My New User-Agent)" }
264
+ }}).run
265
+ ```
data/lib/html/proofer.rb CHANGED
@@ -39,6 +39,7 @@ module HTML
39
39
  :href_swap => [],
40
40
  :href_ignore => [],
41
41
  :file_ignore => [],
42
+ :url_ignore => [],
42
43
  :check_external_hash => false,
43
44
  :alt_ignore => [],
44
45
  :empty_alt_ignore => false,
@@ -6,7 +6,7 @@ module HTML
6
6
  class CheckRunner
7
7
 
8
8
  attr_reader :issues, :src, :path, :options, :typhoeus_opts, :hydra_opts, :parallel_opts, \
9
- :external_urls, :href_ignores, :alt_ignores, :empty_alt_ignore
9
+ :external_urls, :href_ignores, :url_ignores, :alt_ignores, :empty_alt_ignore
10
10
 
11
11
  def initialize(src, path, html, options, typhoeus_opts, hydra_opts, parallel_opts)
12
12
  @src = src
@@ -18,6 +18,7 @@ module HTML
18
18
  @parallel_opts = parallel_opts
19
19
  @issues = []
20
20
  @href_ignores = @options[:href_ignore]
21
+ @url_ignores = @options[:url_ignore]
21
22
  @alt_ignores = @options[:alt_ignore]
22
23
  @empty_alt_ignore = @options[:empty_alt_ignore]
23
24
  @external_urls = {}
@@ -13,7 +13,7 @@ module HTML
13
13
  instance_variable_set("@#{attribute.tr('-:', '_')}".to_sym, value.value)
14
14
  end
15
15
 
16
- @content = obj.content
16
+ @text = obj.content
17
17
  @check = check
18
18
  @checked_paths = {}
19
19
  @type = self.class.name
@@ -66,13 +66,21 @@ module HTML
66
66
  def ignore?
67
67
  return true if @data_proofer_ignore
68
68
 
69
- case @type
70
- when 'FaviconCheckable'
69
+ # ignore base64 encoded images
70
+ if %w(ImageCheckable FaviconCheckable).include? @type
71
71
  return true if url.match(/^data:image/)
72
- when 'LinkCheckable'
72
+ end
73
+
74
+ # ignore user defined URLs
75
+ return true if ignores_pattern_check(@check.url_ignores)
76
+
77
+ # ignore user defined hrefs
78
+ if 'LinkCheckable' === @type
73
79
  return true if ignores_pattern_check(@check.href_ignores)
74
- when 'ImageCheckable'
75
- return true if url.match(/^data:image/)
80
+ end
81
+
82
+ # ignore user defined alts
83
+ if 'ImageCheckable' === @type
76
84
  return true if ignores_pattern_check(@check.alt_ignores)
77
85
  end
78
86
  end
@@ -11,7 +11,7 @@ class ScriptCheckable < ::HTML::Proofer::Checkable
11
11
  end
12
12
 
13
13
  def blank?
14
- @content.strip.empty?
14
+ @text.strip.empty?
15
15
  end
16
16
 
17
17
  end
@@ -1,6 +1,6 @@
1
1
  module HTML
2
2
  class Proofer
3
- VERSION = '2.2.0'
3
+ VERSION = '2.3.0'
4
4
  end
5
5
  end
6
6
 
@@ -2,10 +2,46 @@ require 'spec_helper'
2
2
 
3
3
  describe HTML::Proofer::Checkable do
4
4
  describe '#initialize' do
5
- it 'accepts xmlns attribute' do
5
+ it 'accepts the xmlns attribute' do
6
6
  nokogiri = Nokogiri::HTML '<a xmlns:cc="http://creativecommons.org/ns#">Creative Commons</a>'
7
7
  checkable = HTML::Proofer::Checkable.new nokogiri.css('a').first, nil
8
8
  expect(checkable.instance_variable_get(:@xmlns_cc)).to eq 'http://creativecommons.org/ns#'
9
9
  end
10
+ it 'assignes the text node' do
11
+ nokogiri = Nokogiri::HTML '<p>One'
12
+ checkable = HTML::Proofer::Checkable.new nokogiri.css('p').first, nil
13
+ expect(checkable.instance_variable_get(:@text)).to eq 'One'
14
+ end
15
+ it 'accepts the content attribute' do
16
+ nokogiri = Nokogiri::HTML '<meta name="twitter:card" content="summary">'
17
+ checkable = HTML::Proofer::Checkable.new nokogiri.css('meta').first, nil
18
+ expect(checkable.instance_variable_get(:@content)).to eq 'summary'
19
+ end
20
+ end
21
+ describe '#ignores_pattern_check' do
22
+ it 'works for regex patterns' do
23
+ nokogiri = Nokogiri::HTML '<script src=/assets/main.js></script>'
24
+ checkable = HTML::Proofer::Checkable.new nokogiri.css('script').first, nil
25
+ expect(checkable.ignores_pattern_check([/\/assets\/.*(js|css|png|svg)/])).to eq true
26
+ end
27
+ it 'works for string patterns' do
28
+ nokogiri = Nokogiri::HTML '<script src=/assets/main.js></script>'
29
+ checkable = HTML::Proofer::Checkable.new nokogiri.css('script').first, nil
30
+ expect(checkable.ignores_pattern_check(['/assets/main.js'])).to eq true
31
+ end
32
+ end
33
+ describe '#url' do
34
+ it 'works for src attributes' do
35
+ nokogiri = Nokogiri::HTML '<img src=image.png />'
36
+ checkable = HTML::Proofer::Checkable.new nokogiri.css('img').first, nil
37
+ expect(checkable.url).to eq 'image.png'
38
+ end
39
+ end
40
+ describe '#ignore' do
41
+ it 'works for twitter cards' do
42
+ nokogiri = Nokogiri::HTML '<meta name="twitter:url" data-proofer-ignore content="http://example.com/soon-to-be-published-url">'
43
+ checkable = HTML::Proofer::Checkable.new nokogiri.css('meta').first, nil
44
+ expect(checkable.ignore?).to eq true
45
+ end
10
46
  end
11
47
  end
@@ -0,0 +1,4 @@
1
+ <html>
2
+ <head>
3
+ <script src="/assets/main.js"></script>
4
+ <body>
@@ -38,4 +38,10 @@ describe 'Scripts test' do
38
38
  expect(proofer.failed_tests).to eq []
39
39
  end
40
40
 
41
+ it 'ignores links via url_ignore' do
42
+ ignorableLinks = "#{FIXTURES_DIR}/scripts/ignorableLinksViaOptions.html"
43
+ proofer = run_proofer(ignorableLinks, { :url_ignore => [/\/assets\/.*(js|css|png|svg)/] })
44
+ expect(proofer.failed_tests).to eq []
45
+ end
46
+
41
47
  end
@@ -68,9 +68,9 @@ describe HTML::Proofer do
68
68
  expect(output.strip).to eq('''
69
69
  - -1
70
70
  * spec/html/proofer/fixtures/sorting/status/broken_link.html: internally linking to nowhere.fooof, which does not exist (line 3)
71
- - 404
72
- * spec/html/proofer/fixtures/sorting/status/a_404.html: External link http://upload.wikimedia.org/wikipedia/en/thumb/not_here.png failed: 404 No error
73
- * spec/html/proofer/fixtures/sorting/status/broken_link.html: External link http://upload.wikimedia.org/wikipedia/en/thumb/fooooof.png failed: 404 No error
71
+ - 301
72
+ * spec/html/proofer/fixtures/sorting/status/a_404.html: External link http://upload.wikimedia.org/wikipedia/en/thumb/not_here.png failed: 301 No error
73
+ * spec/html/proofer/fixtures/sorting/status/broken_link.html: External link http://upload.wikimedia.org/wikipedia/en/thumb/fooooof.png failed: 301 No error
74
74
  '''.strip)
75
75
  end
76
76
  end
data/spec/spec_helper.rb CHANGED
@@ -1,6 +1,3 @@
1
- require 'codeclimate-test-reporter'
2
- CodeClimate::TestReporter.start
3
-
4
1
  require 'bundler/setup'
5
2
  require_relative "../lib/html/proofer"
6
3
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: html-proofer
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.0
4
+ version: 2.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Garen Torikian
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-04-21 00:00:00.000000000 Z
11
+ date: 2015-07-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mercenary
@@ -302,6 +302,7 @@ files:
302
302
  - spec/html/proofer/fixtures/resources/books/assets/version-control-with-git.jpg
303
303
  - spec/html/proofer/fixtures/resources/books/nestedRelativeImages.html
304
304
  - spec/html/proofer/fixtures/resources/gpl.png
305
+ - spec/html/proofer/fixtures/scripts/ignorableLinksViaOptions.html
305
306
  - spec/html/proofer/fixtures/scripts/script.js
306
307
  - spec/html/proofer/fixtures/scripts/script_broken_external.html
307
308
  - spec/html/proofer/fixtures/scripts/script_content.html
@@ -459,6 +460,7 @@ test_files:
459
460
  - spec/html/proofer/fixtures/resources/books/assets/version-control-with-git.jpg
460
461
  - spec/html/proofer/fixtures/resources/books/nestedRelativeImages.html
461
462
  - spec/html/proofer/fixtures/resources/gpl.png
463
+ - spec/html/proofer/fixtures/scripts/ignorableLinksViaOptions.html
462
464
  - spec/html/proofer/fixtures/scripts/script.js
463
465
  - spec/html/proofer/fixtures/scripts/script_broken_external.html
464
466
  - spec/html/proofer/fixtures/scripts/script_content.html