html-proofer 0.9.0 → 1.0.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: 65952ba4e5dea5147b84fb88dfae41a49d432340
4
- data.tar.gz: a127df0cb3040eba53860c640255678baf4df3d3
3
+ metadata.gz: 0e7b88c5fd839aa05b97b85399326a9db187a340
4
+ data.tar.gz: e0a0c34a2602aca002797185b7ee488b1a94314d
5
5
  SHA512:
6
- metadata.gz: 878ed21acbf0ed474580c29bd438dd32e645750480f88e16f675bd579ae3c8fc7b8c216c357caecbfd34944c3cbef3c9b5932fef57ba2f6ce09abbbcc03f23cf
7
- data.tar.gz: 740b6aaaa8df3bed83b6194ff27ba85810dbd035e30cb45410fabb2050bcb94ba485e67531cec6c790ad7194523da23c2291796e6797ca192b66dfc805c2123d
6
+ metadata.gz: 904bc7984ee9ddba79e06833a9e235e26c5d388c7581493f79f210053248d4d7916dfe849c8eac7e5fc75815f5be2dbf9d88b3f043eb1181e95f11241cae698b
7
+ data.tar.gz: 509fe2ee57606ea93e1c175bafc8bf8ff39891a93c0bfa8c7ea3242f731f184e4a884bb1deea9d2433074f3b816d25542873deed24e7df4a3f421e64d2f106ba
data/README.md CHANGED
@@ -124,6 +124,7 @@ The `HTML::Proofer` constructor takes an optional hash of additional options:
124
124
  | `ext` | The extension of your HTML files including the dot. | `.html` |
125
125
  | `favicon` | Enables the favicon checker. | `false` |
126
126
  | `href_ignore` | An array of Strings or RegExps containing `href`s that are safe to ignore. Certain URIs, like `mailto` and `tel`, are always ignored. | `[]` |
127
+ | `alt_ignore` | An array of Strings or RegExps containing `img`s whose missing `alt` tags are safe to ignore. | `[]` |
127
128
  | `href_swap` | A hash containing key-value pairs of `RegExp => String`. It transforms links that match `RegExp` into `String` via `gsub`. | `{}` |
128
129
  | `verbose` | If `true`, outputs extra information as the checking happens. Useful for debugging. | `false` |
129
130
 
data/bin/htmlproof CHANGED
@@ -17,7 +17,8 @@ Mercenary.program(:htmlproof) do |p|
17
17
  p.option 'ext', '--ext EXT', 'The extension of your HTML files (default: `.html`)'
18
18
  p.option 'favicon', '--favicon', 'Enables the favicon checker (default: `false`).'
19
19
  p.option 'swap', '--swap regex:string,[regex:string,...]', Array, 'Array containing key-value pairs of `RegExp:String`. It transforms links that match `RegExp` into `String`'
20
- p.option 'ignore', '--ignore link1,[link2,...]', Array, 'Array of Strings containing `href`s that are safe to ignore (default: `mailto`)'
20
+ p.option 'href_ignore', '--href_ignore link1,[link2,...]', Array, 'Array of Strings containing `href`s that are safe to ignore. Certain URIs, like `mailto` and `tel`, are always ignored.'
21
+ p.option 'alt_ignore', '--alt_ignore image1,[image2,...]', Array, 'Array of Strings containing `img`s whose missing `alt` tags are safe to ignore'
21
22
  p.option 'disable_external', '--disable_external', 'Disables the external link checker (default: `false`)'
22
23
  p.option 'verbose', '--verbose', 'Enables more verbose logging.'
23
24
 
@@ -34,7 +35,8 @@ Mercenary.program(:htmlproof) do |p|
34
35
  options[:href_swap][%r{#{pair[0]}}] = pair[1]
35
36
  end
36
37
  end
37
- options[:href_ignore] = opts["ignore"] unless opts["ignore"].nil?
38
+ options[:href_ignore] = opts["ignore"] unless opts["href_ignore"].nil?
39
+ options[:alt_ignore] = opts["ignore"] unless opts["alt_ignore"].nil?
38
40
  options[:disable_external] = opts["disable_external"] unless opts["disable_external"].nil?
39
41
  options[:favicon] = opts["favicon"] unless opts["favicon"].nil?
40
42
  options[:verbose] = opts["verbose"] unless opts["verbose"].nil?
data/html-proofer.gemspec CHANGED
@@ -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 = "0.9.0"
6
+ gem.version = "1.0.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.}
data/lib/html/proofer.rb CHANGED
@@ -18,6 +18,7 @@ module HTML
18
18
  :favicon => false,
19
19
  :href_swap => [],
20
20
  :href_ignore => [],
21
+ :alt_ignore => [],
21
22
  :disable_external => false,
22
23
  :verbose => false
23
24
  }
@@ -10,7 +10,7 @@ class HTML::Proofer::Checks
10
10
 
11
11
  class Check
12
12
 
13
- attr_reader :issues, :src, :path, :options, :external_urls, :additional_href_ignores
13
+ attr_reader :issues, :src, :path, :options, :external_urls, :additional_href_ignores, :additional_alt_ignores
14
14
 
15
15
  def initialize(src, path, html, opts={})
16
16
  @src = src
@@ -19,6 +19,7 @@ class HTML::Proofer::Checks
19
19
  @options = opts
20
20
  @issues = []
21
21
  @additional_href_ignores = @options[:href_ignore]
22
+ @additional_alt_ignores = @options[:alt_ignore]
22
23
  @external_urls = {}
23
24
  end
24
25
 
@@ -62,14 +62,15 @@ module HTML
62
62
  end
63
63
 
64
64
  def ignore?
65
- return true if @data_ignore_proofer || @check.additional_href_ignores.include?(url)
66
- return true if @type == "image" and url.match(/^data:image/)
67
- unless @check.additional_href_ignores.empty?
68
- @check.additional_href_ignores.each do |href_ignore|
69
- if href_ignore.is_a? String
70
- return true if href_ignore == url
71
- elsif href_ignore.is_a? Regexp
72
- return true if href_ignore =~ url
65
+ return true if @data_ignore_proofer || @check.additional_href_ignores.include?(url) || @check.additional_alt_ignores.include?(url)
66
+ return true if (@type == "image" || @type == "favicon") && url.match(/^data:image/)
67
+
68
+ [@check.additional_href_ignores, @check.additional_alt_ignores].each do |additional_ignore|
69
+ additional_ignore.each do |ignore|
70
+ if ignore.is_a? String
71
+ return true if ignore == url
72
+ elsif ignore.is_a? Regexp
73
+ return true if ignore =~ url
73
74
  end
74
75
  end
75
76
  end
@@ -0,0 +1,13 @@
1
+ <html>
2
+
3
+ <body>
4
+
5
+
6
+ <img src="gpl.png"/>Relative to self
7
+
8
+
9
+ <p>Blah blah blah. <img src="//upload.wikimedia.org/wikipedia/en/thumb/2/22/Heckert_GNU_white.svg/256px-Heckert_GNU_white.svg.png" /> </p>
10
+
11
+ </body>
12
+
13
+ </html>
@@ -82,4 +82,10 @@ describe "Images test" do
82
82
  output = capture_stderr { HTML::Proofer.new(relativeLinks).run }
83
83
  output.should == ""
84
84
  end
85
+
86
+ it 'properly ignores missing alt tags when asked' do
87
+ ignorableLinks = "#{FIXTURES_DIR}/images/ignorableAltViaOptions.html"
88
+ output = capture_stderr { HTML::Proofer.new(ignorableLinks, {:alt_ignore => [/wikimedia/, "gpl.png"]}).run }
89
+ output.should == ""
90
+ end
85
91
  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: 0.9.0
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Garen Torikian
@@ -169,6 +169,7 @@ files:
169
169
  - spec/html/proofer/fixtures/favicon/favicon_present_shortcut.html
170
170
  - spec/html/proofer/fixtures/images/existingImageExternal.html
171
171
  - spec/html/proofer/fixtures/images/gpl.png
172
+ - spec/html/proofer/fixtures/images/ignorableAltViaOptions.html
172
173
  - spec/html/proofer/fixtures/images/ignorableImages.html
173
174
  - spec/html/proofer/fixtures/images/image_missing_protocol_invalid.html
174
175
  - spec/html/proofer/fixtures/images/image_missing_protocol_valid.html
@@ -268,6 +269,7 @@ test_files:
268
269
  - spec/html/proofer/fixtures/favicon/favicon_present_shortcut.html
269
270
  - spec/html/proofer/fixtures/images/existingImageExternal.html
270
271
  - spec/html/proofer/fixtures/images/gpl.png
272
+ - spec/html/proofer/fixtures/images/ignorableAltViaOptions.html
271
273
  - spec/html/proofer/fixtures/images/ignorableImages.html
272
274
  - spec/html/proofer/fixtures/images/image_missing_protocol_invalid.html
273
275
  - spec/html/proofer/fixtures/images/image_missing_protocol_valid.html