html-proofer 1.5.4 → 1.6.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: 2378653066f706946320a842961fa24145a30c6c
4
- data.tar.gz: d5f9af8f26f706d8749c7703aced6f00282b2fd1
3
+ metadata.gz: 8328f696789f830910e2bee17b2b015e8ffc0b0d
4
+ data.tar.gz: f051884d9787841d70dfdaf2ebedc5bb7818a6e2
5
5
  SHA512:
6
- metadata.gz: 33ddc59a5868f717d5f1a57ae259d0adac9401786952bbc5df502ce8dd89ed29cf52969df2df8dbc57325d1800eaa755fd629fa4e093e4c5464672c60b6ea2f0
7
- data.tar.gz: fe325d831dfd59fc5d48ab7eace5514c0ba6877151a84341183cb7b8a3949a7b4ff3a8500a03e4f201669c9e8c19fca0c77d742b0232e3e2617f178d17acf7ff
6
+ metadata.gz: cf0bfd4a6060c0eebe58be4caad40cbada074241ed378ced25236f52e594b1ff1f1d528c4bb757fac11fe4bb3a68dce072950ccbe5eb965652179660fda19285
7
+ data.tar.gz: 53fe8b4b33e7d6507da659f18e54279c85bf741d9bb84439430147584ac1928ff085b31cd61576313098e1e383b216bdff0f844fb9e4fb0f3156c11176a2195a
data/README.md CHANGED
@@ -140,6 +140,7 @@ The `HTML::Proofer` constructor takes an optional hash of additional options:
140
140
  | `directory_index_file` | Sets the file to look for when a link refers to a directory. | `index.html` |
141
141
  | `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. | `[]` |
142
142
  | `alt_ignore` | An array of Strings or RegExps containing `img`s whose missing `alt` tags are safe to ignore. | `[]` |
143
+ | `file_ignore` | An array of Strings or RegExps containing file paths that are safe to ignore. | `[]` |
143
144
  | `href_swap` | A hash containing key-value pairs of `RegExp => String`. It transforms links that match `RegExp` into `String` via `gsub`. | `{}` |
144
145
  | `verbose` | If `true`, outputs extra information as the checking happens. Useful for debugging. | `false` |
145
146
  | `only_4xx` | Only reports errors for links that fall within the 4xx status code range. | `false` |
data/bin/htmlproof CHANGED
@@ -18,8 +18,9 @@ Mercenary.program(:htmlproof) do |p|
18
18
  p.option 'favicon', '--favicon', 'Enables the favicon checker (default: `false`).'
19
19
  p.option 'as-links', '--as-links', 'Assumes that `PATH` is a comma-separated array of links to check.'
20
20
  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`'
21
- p.option 'href_ignore', '--href_ignore link1,[link2,...]', Array, 'Array of Strings containing `href`s that are safe to ignore. Note that non-HTTP(S) URIs are always ignored.'
22
- p.option 'alt_ignore', '--alt_ignore image1,[image2,...]', Array, 'Array of Strings containing `img`s whose missing `alt` tags are safe to ignore'
21
+ p.option 'href_ignore', '--href_ignore link1,[link2,...]', Array, 'Array of Strings or RegExps containing `href`s that are safe to ignore. Note that non-HTTP(S) URIs are always ignored.'
22
+ p.option 'alt_ignore', '--alt_ignore image1,[image2,...]', Array, 'Array of Strings or RegExps containing `img`s whose missing `alt` tags are safe to ignore'
23
+ p.option 'file_ignore', '--file_ignore file1,[file2,...]', Array, 'Array of Strings or RegExps containing file paths that are safe to ignore'
23
24
  p.option 'disable_external', '--disable_external', 'Disables the external link checker (default: `false`)'
24
25
  p.option 'only_4xx', '--only_4xx', 'Only reports errors for links that fall within the 4x status code range.'
25
26
  p.option 'verbose', '--verbose', 'Enables more verbose logging.'
@@ -43,6 +44,7 @@ Mercenary.program(:htmlproof) do |p|
43
44
 
44
45
  options[:href_ignore] = opts["href_ignore"] unless opts["href_ignore"].nil?
45
46
  options[:alt_ignore] = opts["alt_ignore"] unless opts["alt_ignore"].nil?
47
+ options[:file_ignore] = opts["file_ignore"] unless opts["file_ignore"].nil?
46
48
  options[:disable_external] = opts["disable_external"] unless opts["disable_external"].nil?
47
49
  options[:only_4xx] = opts["only_4xx"] unless opts["only_4xx"].nil?
48
50
  options[:favicon] = opts["favicon"] unless opts["favicon"].nil?
data/lib/html/proofer.rb CHANGED
@@ -37,6 +37,7 @@ module HTML
37
37
  :favicon => false,
38
38
  :href_swap => [],
39
39
  :href_ignore => [],
40
+ :file_ignore => [],
40
41
  :check_external_hash => false,
41
42
  :alt_ignore => [],
42
43
  :disable_external => false,
@@ -220,14 +221,27 @@ module HTML
220
221
  def files
221
222
  if File.directory? @src
222
223
  pattern = File.join @src, "**", "*#{@options[:ext]}"
223
- Dir.glob(pattern).select { |fn| File.file? fn }
224
+ files = Dir.glob(pattern).select { |fn| File.file? fn }
225
+ files.reject { |f| ignore_file?(f) }
224
226
  elsif File.extname(@src) == @options[:ext]
225
- [@src]
227
+ [@src].reject { |f| ignore_file?(f) }
226
228
  else
227
229
  []
228
230
  end
229
231
  end
230
232
 
233
+ def ignore_file?(file)
234
+ @options[:file_ignore].each do |pattern|
235
+ if pattern.is_a? String
236
+ return pattern == file
237
+ elsif pattern.is_a? Regexp
238
+ return pattern =~ file
239
+ end
240
+ end
241
+
242
+ false
243
+ end
244
+
231
245
  def self.create_nokogiri(path)
232
246
  content = File.open(path).read
233
247
  Nokogiri::HTML(content)
@@ -1,5 +1,5 @@
1
1
  module HTML
2
2
  class Proofer
3
- VERSION = "1.5.4"
3
+ VERSION = "1.6.0"
4
4
  end
5
5
  end
@@ -75,5 +75,28 @@ describe HTML::Proofer do
75
75
  """.strip)
76
76
  end
77
77
  end
78
+
79
+ describe "file ignores" do
80
+ it "knows how to ignore a file by string" do
81
+ options = { :file_ignore => ["#{FIXTURES_DIR}/links/brokenHashInternal.html"] }
82
+ brokenHashInternalFilepath = "#{FIXTURES_DIR}/links/brokenHashInternal.html"
83
+ proofer = make_proofer(brokenHashInternalFilepath, options)
84
+ expect(proofer.failed_tests).to eq []
85
+ end
86
+
87
+ it "knows how to ignore a file by regexp" do
88
+ options = { :file_ignore => [/brokenHash/] }
89
+ brokenHashInternalFilepath = "#{FIXTURES_DIR}/links/brokenHashInternal.html"
90
+ proofer = make_proofer(brokenHashInternalFilepath, options)
91
+ expect(proofer.failed_tests).to eq []
92
+ end
93
+
94
+ it "knows how to ignore a directory by regexp" do
95
+ options = { :file_ignore => [/\S\.html/] }
96
+ linksDir = "#{FIXTURES_DIR}/links"
97
+ proofer = make_proofer(linksDir, options)
98
+ expect(proofer.failed_tests).to eq []
99
+ end
100
+ end
78
101
  end
79
102
  end
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: 1.5.4
4
+ version: 1.6.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: 2014-11-14 00:00:00.000000000 Z
11
+ date: 2014-12-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mercenary