html-proofer 3.5.0 → 3.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: c8e32513d55bbc3b6fe0b8b238199fa0270c13a4
4
- data.tar.gz: 6b1f6264dae93f15f2e09e4542e2f7b5d6ffff3c
3
+ metadata.gz: ee04feecbb1a662c1c5023003314a6647292fd13
4
+ data.tar.gz: f01200df1a2f69ea90a2bb8cb49feac80bb4593b
5
5
  SHA512:
6
- metadata.gz: b9f3c3a6028eb2eae4b3fb0f999702c80c06b3a89a6a715ee7f1d5b09d12b50ca47bd739c8696d1b6ff531f647afa3b85d1ee29c04fb0c81fa5e60896787661f
7
- data.tar.gz: b5eaa5f478efd12a53161a91218da9661a979dfe91cd1ba2873b365ec94ec0c9b2f9d8202befacb062c92da6820cd83a914e54fa9c83046a12648ba11b862337
6
+ metadata.gz: aae793b1fd1d3672cba9a86557efad2b728dd4e09326076c24aeda5203fb03a6aa2600198ae50549d26712ffaf378d405e8f39121e9f0396d34d540f2f5a2c62
7
+ data.tar.gz: 0ecb402b29e2721ca83acc1b6582d4642954d2378ad0bb992fdfaa93e6d6a326c7199fad2c5056186bfc18b78bf94565f5375fb6f05e8dda69efd90c3108f804
data/bin/htmlproofer CHANGED
@@ -27,7 +27,7 @@ Mercenary.program(:htmlproofer) do |p|
27
27
  p.option 'directory_index_file', '--directory-index-file', String, 'Sets the file to look for when a link refers to a directory. (default: `index.html`)'
28
28
  p.option 'disable_external', '--disable-external', 'If `true`, does not run the external link checker, which can take a lot of time (default: `false`)'
29
29
  p.option 'empty_alt_ignore', '--empty-alt-ignore', 'If `true`, ignores images with empty alt tags'
30
- p.option 'error_sort', '--error-sort SORT', 'Defines the sort order for error output. Can be `:path`, `:desc`, or `:status` (default: `path`).'
30
+ p.option 'error_sort', '--error-sort SORT', 'Defines the sort order for error output. Can be `:path`, `:desc`, or `:status` (default: `:path`).'
31
31
  p.option 'enforce_https', '--enforce-https', 'Fails a link if it\'s not marked as `https` (default: `false`).'
32
32
  p.option 'extension', '--extension EXT', String, 'The extension of your HTML files including the dot. (default: `.html`)'
33
33
  p.option 'external_only', '--external_only', 'Only checks problems with external references'
@@ -36,12 +36,13 @@ Mercenary.program(:htmlproofer) do |p|
36
36
  p.option 'report_invalid_tags', '--report-invalid-tags', 'Ignore `check_html` errors associated with unknown markup (default: `false`)'
37
37
  p.option 'report_missing_names', '--report-missing-names', 'Ignore `check_html` errors associated with missing entities (default: `false`)'
38
38
  p.option 'report_script_embeds', '--report-script-embeds', 'Ignore `check_html` errors associated with `script`s (default: `false`)'
39
- p.option 'log_level', '--log-level <level>', String, 'Sets the logging level, as determined by Yell'
39
+ p.option 'log_level', '--log-level <level>', String, 'Sets the logging level, as determined by Yell. One of `:debug`, `:info`, `:warn`, `:error`, or `:fatal`. (default: `:info`)'
40
40
  p.option 'only_4xx', '--only-4xx', 'Only reports errors for links that fall within the 4xx status code range'
41
41
  p.option 'timeframe', '--timeframe <time>', String, 'A string representing the caching timeframe.'
42
42
  p.option 'url_ignore', '--url-ignore link1,[link2,...]', Array, 'A comma-separated list 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'
43
43
  p.option 'url_swap', '--url-swap re:string,[re:string,...]', Array, 'A comma-separated list containing key-value pairs of `RegExp => String`. It transforms URLs that match `RegExp` into `String` via `gsub`. The escape sequences `\\:` should be used to produce literal `:`s.'
44
44
  p.option 'internal_domains', '--internal-domains domain1,[domain2,...]', Array, 'A comma-separated list of Strings containing domains that will be treated as internal urls.'
45
+ p.option 'storage_dir', '--storage-dir PATH', String, 'Directory where to store the cache log (default: "tmp/.htmlproofer")'
45
46
 
46
47
  p.action do |args, opts|
47
48
  args = ['.'] if args.empty?
@@ -80,6 +81,7 @@ Mercenary.program(:htmlproofer) do |p|
80
81
 
81
82
  options[:cache] = {}
82
83
  options[:cache][:timeframe] = opts['timeframe'] unless opts['timeframe'].nil?
84
+ options[:cache][:storage_dir] = opts['storage_dir'] unless opts['storage_dir'].nil?
83
85
 
84
86
  options[:http_status_ignore] = Array(options[:http_status_ignore]).map(&:to_i)
85
87
 
@@ -9,9 +9,10 @@ module HTMLProofer
9
9
  class Cache
10
10
  include HTMLProofer::Utils
11
11
 
12
- CACHE_LOG = File.join(STORAGE_DIR, 'cache.log')
12
+ DEFAULT_STORAGE_DIR = File.join('tmp', '.htmlproofer')
13
+ DEFAULT_CACHE_FILE_NAME = "cache.log"
13
14
 
14
- attr_reader :exists, :cache_log
15
+ attr_reader :exists, :cache_log, :storage_dir, :cache_file
15
16
 
16
17
  def initialize(logger, options)
17
18
  @logger = logger
@@ -21,15 +22,11 @@ module HTMLProofer
21
22
  define_singleton_method('use_cache?') { false }
22
23
  else
23
24
  define_singleton_method('use_cache?') { true }
25
+ setup_cache!(options)
24
26
  @parsed_timeframe = parsed_timeframe(options[:timeframe])
25
27
  end
26
28
 
27
29
  @cache_time = Time.now
28
-
29
- if File.exist?(CACHE_LOG)
30
- contents = File.read(CACHE_LOG)
31
- @cache_log = contents.empty? ? {} : JSON.parse(contents)
32
- end
33
30
  end
34
31
 
35
32
  def within_timeframe?(time)
@@ -111,7 +108,7 @@ module HTMLProofer
111
108
  end
112
109
 
113
110
  def write
114
- File.write(CACHE_LOG, @cache_log.to_json)
111
+ File.write(cache_file, @cache_log.to_json)
115
112
  end
116
113
 
117
114
  def load?
@@ -149,5 +146,30 @@ module HTMLProofer
149
146
  def clean_url(url)
150
147
  slashless_url(unescape_url(url))
151
148
  end
149
+
150
+ def setup_cache!(options)
151
+ if options[:storage_dir]
152
+ @storage_dir = options[:storage_dir]
153
+ else
154
+ @storage_dir = DEFAULT_STORAGE_DIR
155
+ end
156
+
157
+ if !Dir.exist?(storage_dir)
158
+ FileUtils.mkdir_p(storage_dir)
159
+ end
160
+
161
+ if options[:cache_file]
162
+ cache_file_name = options[:cache_file]
163
+ else
164
+ cache_file_name = DEFAULT_CACHE_FILE_NAME
165
+ end
166
+
167
+ @cache_file = File.join(storage_dir, cache_file_name)
168
+
169
+ if File.exist?(cache_file)
170
+ contents = File.read(cache_file)
171
+ @cache_log = contents.empty? ? {} : JSON.parse(contents)
172
+ end
173
+ end
152
174
  end
153
175
  end
@@ -107,10 +107,12 @@ class LinkCheck < ::HTMLProofer::Check
107
107
 
108
108
  def hash_check(html, href_hash)
109
109
  decoded_href_hash = URI.decode(href_hash)
110
- html.xpath("//*[case_insensitive_equals(@id, '#{href_hash}')]", \
111
- "//*[case_insensitive_equals(@name, '#{href_hash}')]", \
112
- "//*[case_insensitive_equals(@id, '#{decoded_href_hash}')]", \
113
- "//*[case_insensitive_equals(@name, '#{decoded_href_hash}')]", \
110
+ href_hash = "'#{href_hash.split("'").join("', \"'\", '")}', ''"
111
+ decoded_href_hash = "'#{decoded_href_hash.split("'").join("', \"'\", '")}', ''"
112
+ html.xpath("//*[case_insensitive_equals(@id, concat(#{href_hash}))]", \
113
+ "//*[case_insensitive_equals(@name, concat(#{href_hash}))]", \
114
+ "//*[case_insensitive_equals(@id, concat(#{decoded_href_hash}))]", \
115
+ "//*[case_insensitive_equals(@name, concat(#{decoded_href_hash}))]", \
114
116
  XpathFunctions.new).length > 0
115
117
  end
116
118
 
@@ -33,7 +33,9 @@ module HTMLProofer
33
33
  :followlocation => true,
34
34
  :headers => {
35
35
  'User-Agent' => "Mozilla/5.0 (compatible; HTML Proofer/#{HTMLProofer::VERSION}; +https://github.com/gjtorikian/html-proofer)"
36
- }
36
+ },
37
+ :connecttimeout => 10,
38
+ :timeout => 30
37
39
  }
38
40
 
39
41
  HYDRA_DEFAULTS = {
@@ -19,10 +19,6 @@ module HTMLProofer
19
19
  @type = @options.delete(:type)
20
20
  @logger = HTMLProofer::Log.new(@options[:log_level])
21
21
 
22
- if !@options[:cache].empty? && !File.exist?(STORAGE_DIR)
23
- FileUtils.mkdir_p(STORAGE_DIR)
24
- end
25
-
26
22
  # Add swap patterns for internal domains
27
23
  unless @options[:internal_domains].empty?
28
24
  @options[:internal_domains].each do |dom|
@@ -2,8 +2,6 @@ require 'nokogiri'
2
2
 
3
3
  module HTMLProofer
4
4
  module Utils
5
- STORAGE_DIR = File.join('tmp', '.htmlproofer')
6
-
7
5
  def pluralize(count, single, plural)
8
6
  "#{count} " << (count == 1 ? single : plural)
9
7
  end
@@ -1,3 +1,3 @@
1
1
  module HTMLProofer
2
- VERSION = '3.5.0'.freeze
2
+ VERSION = '3.6.0'.freeze
3
3
  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: 3.5.0
4
+ version: 3.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: 2017-03-04 00:00:00.000000000 Z
11
+ date: 2017-03-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mercenary