html-proofer 0.6.7 → 0.6.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +41 -5
- data/bin/htmlproof +4 -2
- data/html-proofer.gemspec +4 -2
- data/lib/html/proofer.rb +25 -7
- data/spec/spec_helper.rb +1 -1
- metadata +32 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4158a32821a881ebd52b68d22058614bf593cdb3
|
4
|
+
data.tar.gz: 9fd06100599bb970ac6e1f62e8f5ffcf3c761e31
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 345e1cd5381f31064f52429b91252ffc85b013daefcb4c83ea717ca4cf607e02b75c8b652ac9a53add7269a10870bc9e7a4e80afd30e4516de8506e6c723ebf0
|
7
|
+
data.tar.gz: c51bd43c8cfd5ddd20834932e68686f41d00bebd85151f82c8a8588ed51a2105fcd2353dd0cec5fefe643213f56876efc3787ccde1a06d5a99b7a9d68fd29f05
|
data/README.md
CHANGED
@@ -22,7 +22,7 @@ Or install it yourself as:
|
|
22
22
|
|
23
23
|
## Usage
|
24
24
|
|
25
|
-
###
|
25
|
+
### Using in a script
|
26
26
|
|
27
27
|
Require the gem; generate some HTML; create a new instance of the `HTML::Proofer` on
|
28
28
|
your output folder; then `run` it. Here's a simple example:
|
@@ -54,7 +54,7 @@ end
|
|
54
54
|
HTML::Proofer.new("./out").run
|
55
55
|
```
|
56
56
|
|
57
|
-
###
|
57
|
+
### Using on the command-line
|
58
58
|
|
59
59
|
You'll get a new program called `htmlproof` with this gem. Jawesome!
|
60
60
|
|
@@ -67,7 +67,7 @@ htmlproof run ./out --swap wow:cow,mow:doh --ext .html.erb --ignore www.github.c
|
|
67
67
|
Note: since `swap` is a bit special, you'll pass in a pair of `RegEx:String` values.
|
68
68
|
`htmlproof` will figure out what you mean.
|
69
69
|
|
70
|
-
|
70
|
+
### Using with Jekyll
|
71
71
|
|
72
72
|
Want to use HTML Proofer with your Jekyll site? Awesome. Simply add `gem 'html-proofer'`
|
73
73
|
to your `Gemfile` as described above, and add the following to your `Rakefile`,
|
@@ -104,6 +104,7 @@ The `HTML::Proofer` constructor takes an optional hash of additional options:
|
|
104
104
|
* `:href_swap`: a hash containing key-value pairs of `RegExp => String`. It transforms links that match `RegExp` into `String` via `gsub`.
|
105
105
|
* `:href_ignore`: an array of Strings or RegExps containing `href`s that are safe to ignore (`mailto` is always ignored)
|
106
106
|
* `:disable_external`: if `true`, does not run the external link checker, which can take a lot of time (default: `false`)
|
107
|
+
* `:verbose`: if `true`, outputs extra information as the checking happens. Useful for debugging. (default: `false`)
|
107
108
|
|
108
109
|
You can also pass in any of Typhoeus' options for the external link check. For example:
|
109
110
|
|
@@ -113,6 +114,41 @@ HTML::Proofer.new("out/", {:ext => ".htm", :verbose = > true, :ssl_verifyhost =>
|
|
113
114
|
|
114
115
|
This sets `HTML::Proofer`'s' extensions to use _.htm_, and gives Typhoeus a configurtion for it to be verbose, and use specific SSL settings. Check [the Typhoeus documentation](https://github.com/typhoeus/typhoeus#other-curl-options) for more information on what options it can receive.
|
115
116
|
|
116
|
-
## Ignoring
|
117
|
+
## Ignoring content
|
118
|
+
|
119
|
+
Add the `data-proofer-ignore` attribute to any `<a>` or `<img>` tag to ignore it from the checks.
|
120
|
+
|
121
|
+
## Custom tests
|
122
|
+
|
123
|
+
Want to write your own test? Sure! Just create two classes--one that inherits from `HTML::Proofer::Checkable`, and another that inherits from `HTML::Proofer::Checks::Check`. `Checkable` defines various helper methods for your test, while `Checks::Check` actually runs across your content. `Checks::Check` should call `self.add_issue` on failures, to add them to the list.
|
124
|
+
|
125
|
+
Here's an example custom test that protects against `mailto` links:
|
126
|
+
|
127
|
+
``` ruby
|
128
|
+
class OctocatLink < ::HTML::Proofer::Checkable
|
129
|
+
|
130
|
+
def mailto?
|
131
|
+
return false if @data_ignore_proofer || @href.nil? || @href.empty?
|
132
|
+
return @href.match /^mailto\:/
|
133
|
+
end
|
134
|
+
|
135
|
+
def octocat?
|
136
|
+
return @href.match /\:octocat@github.com\Z/
|
137
|
+
end
|
138
|
+
|
139
|
+
end
|
140
|
+
|
141
|
+
class MailToOctocat < ::HTML::Proofer::Checks::Check
|
142
|
+
|
143
|
+
def run
|
144
|
+
@html.css('a').each do |l|
|
145
|
+
link = OctocatLink.new l, "octocat_link", self
|
146
|
+
|
147
|
+
if link.mailto? && link.octocat?
|
148
|
+
return self.add_issue("Don't email the Octocat directly!")
|
149
|
+
end
|
150
|
+
end
|
151
|
+
end
|
152
|
+
end
|
153
|
+
```
|
117
154
|
|
118
|
-
To any `<a>` or `<img>` tag, you may add the `data-proofer-ignore` attribute to ignore the link.
|
data/bin/htmlproof
CHANGED
@@ -15,9 +15,10 @@ Mercenary.program(:htmlproof) do |p|
|
|
15
15
|
p.description "Runs the HTML-Proofer suite on the files in PATH"
|
16
16
|
|
17
17
|
p.option 'ext', '--ext EXT', 'The extension of your HTML files (default: `.html`)'
|
18
|
-
p.option 'swap', '--swap regex:string,[regex:string,...]', 'Array containing key-value pairs of `RegExp:String`. It transforms links that match `RegExp` into `String`'
|
19
|
-
p.option 'ignore', '--ignore link1,[link2,...]', 'Array of Strings containing `href`s that are safe to ignore (default: `mailto`)'
|
18
|
+
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`'
|
19
|
+
p.option 'ignore', '--ignore link1,[link2,...]', Array, 'Array of Strings containing `href`s that are safe to ignore (default: `mailto`)'
|
20
20
|
p.option 'disable_external', '--disable_external', 'Disables the external link checker (default: `false`)'
|
21
|
+
p.option 'verbose', '--verbose', 'Enables more verbose logging.'
|
21
22
|
|
22
23
|
p.action do |args, opts|
|
23
24
|
args = ["."] if args.empty?
|
@@ -34,6 +35,7 @@ Mercenary.program(:htmlproof) do |p|
|
|
34
35
|
end
|
35
36
|
options[:href_ignore] = opts["ignore"] unless opts["ignore"].nil?
|
36
37
|
options[:disable_external] = opts["disable_external"] unless opts["disable_external"].nil?
|
38
|
+
options[:verbose] = opts["verbose"] unless opts["verbose"].nil?
|
37
39
|
|
38
40
|
HTML::Proofer.new(path, options).run
|
39
41
|
end
|
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.6.
|
6
|
+
gem.version = "0.6.8"
|
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.}
|
@@ -19,8 +19,10 @@ Gem::Specification.new do |gem|
|
|
19
19
|
gem.add_dependency "nokogiri", "~> 1.6.0"
|
20
20
|
gem.add_dependency "colored", "~> 1.2"
|
21
21
|
gem.add_dependency "typhoeus", "~> 0.6.7"
|
22
|
+
gem.add_dependency "yell", "~> 2.0"
|
22
23
|
|
23
|
-
gem.add_development_dependency "html-pipeline", "~>
|
24
|
+
gem.add_development_dependency "html-pipeline", "~> 1.8"
|
25
|
+
gem.add_development_dependency "escape_utils", "~> 1.0" # Ruby 2.1 fix
|
24
26
|
gem.add_development_dependency "rspec", "~> 2.13.0"
|
25
27
|
gem.add_development_dependency "rake"
|
26
28
|
end
|
data/lib/html/proofer.rb
CHANGED
@@ -1,30 +1,39 @@
|
|
1
1
|
require 'nokogiri'
|
2
|
+
require 'yell'
|
2
3
|
|
3
4
|
require File.dirname(__FILE__) + '/proofer/checkable'
|
4
5
|
require File.dirname(__FILE__) + '/proofer/checks'
|
5
6
|
|
6
7
|
module HTML
|
7
8
|
class Proofer
|
9
|
+
include Yell::Loggable
|
10
|
+
|
8
11
|
def initialize(src, opts={})
|
9
12
|
@srcDir = src
|
10
13
|
|
11
|
-
@proofer_opts = {:ext => ".html", :href_swap => [], :href_ignore => [], :disable_external => false }
|
14
|
+
@proofer_opts = {:ext => ".html", :href_swap => [], :href_ignore => [], :disable_external => false, :verbose => false }
|
12
15
|
@options = @proofer_opts.merge({:followlocation => true}).merge(opts)
|
13
16
|
|
14
17
|
@failed_tests = []
|
18
|
+
|
19
|
+
Yell.new({ :format => false, :name => "HTML::Proofer", :level => "gte.#{log_level}" }) do |l|
|
20
|
+
l.adapter :stdout, level: [:debug, :info, :warn]
|
21
|
+
l.adapter :stderr, level: [:error, :fatal]
|
22
|
+
end
|
15
23
|
end
|
16
24
|
|
17
25
|
def run
|
18
26
|
total_files = 0
|
19
27
|
external_urls = {}
|
20
28
|
|
21
|
-
|
29
|
+
logger.info "Running #{get_checks} checks on #{@srcDir} on *#{@options[:ext]}... \n\n".white
|
22
30
|
|
23
31
|
files.each do |path|
|
24
32
|
total_files += 1
|
25
33
|
html = HTML::Proofer.create_nokogiri(path)
|
26
34
|
|
27
35
|
get_checks.each do |klass|
|
36
|
+
logger.debug "Checking #{klass.to_s.downcase} on #{path} ...".blue
|
28
37
|
check = klass.new(@srcDir, path, html, @options)
|
29
38
|
check.run
|
30
39
|
external_urls.merge!(check.external_urls)
|
@@ -40,31 +49,34 @@ module HTML
|
|
40
49
|
external_urls = Hash[external_urls.sort]
|
41
50
|
|
42
51
|
unless @options[:disable_external]
|
43
|
-
|
52
|
+
logger.info "Checking #{external_urls.length} external links...".yellow
|
44
53
|
|
45
54
|
# Typhoeus won't let you pass any non-Typhoeus option
|
46
55
|
@proofer_opts.each_key do |opt|
|
47
56
|
@options.delete opt
|
48
57
|
end
|
49
58
|
|
59
|
+
Ethon.logger = logger # log from Typhoeus/Ethon
|
60
|
+
|
50
61
|
external_urls.each_pair do |href, filenames|
|
51
62
|
request = Typhoeus::Request.new(href, @options.merge({:method => :head}))
|
52
63
|
request.on_complete { |response| response_handler(response, filenames) }
|
53
64
|
hydra.queue request
|
54
65
|
end
|
66
|
+
logger.debug "Running requests for all #{hydra.queued_requests.size} external URLs...".yellow
|
55
67
|
hydra.run
|
56
68
|
end
|
57
69
|
|
58
|
-
|
70
|
+
logger.info "Ran on #{total_files} files!\n\n".green
|
59
71
|
|
60
72
|
if @failed_tests.empty?
|
61
|
-
|
73
|
+
logger.info "HTML-Proofer finished successfully.".green
|
62
74
|
else
|
63
75
|
@failed_tests.each do |issue|
|
64
|
-
|
76
|
+
logger.error (issue + "\n\n").red
|
65
77
|
end
|
66
78
|
|
67
|
-
raise "HTML-Proofer found #{@failed_tests.length} failures!"
|
79
|
+
raise "HTML-Proofer found #{@failed_tests.length} failures!".red
|
68
80
|
end
|
69
81
|
end
|
70
82
|
|
@@ -73,6 +85,8 @@ module HTML
|
|
73
85
|
method = response.request.options[:method]
|
74
86
|
response_code = response.code
|
75
87
|
|
88
|
+
logger.debug "Received a #{response_code} for #{href} in #{filenames.join(' ')}"
|
89
|
+
|
76
90
|
if response_code.between?(200, 299)
|
77
91
|
# continue with no op
|
78
92
|
elsif response.timed_out?
|
@@ -114,5 +128,9 @@ module HTML
|
|
114
128
|
def get_checks
|
115
129
|
HTML::Proofer::Checks::Check.subclasses
|
116
130
|
end
|
131
|
+
|
132
|
+
def log_level
|
133
|
+
@options[:verbose] ? :debug : :info
|
134
|
+
end
|
117
135
|
end
|
118
136
|
end
|
data/spec/spec_helper.rb
CHANGED
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: 0.6.
|
4
|
+
version: 0.6.8
|
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
|
+
date: 2014-05-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: mercenary
|
@@ -66,20 +66,48 @@ dependencies:
|
|
66
66
|
- - ~>
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: 0.6.7
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: yell
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ~>
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '2.0'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ~>
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '2.0'
|
69
83
|
- !ruby/object:Gem::Dependency
|
70
84
|
name: html-pipeline
|
71
85
|
requirement: !ruby/object:Gem::Requirement
|
72
86
|
requirements:
|
73
87
|
- - ~>
|
74
88
|
- !ruby/object:Gem::Version
|
75
|
-
version:
|
89
|
+
version: '1.8'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ~>
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '1.8'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: escape_utils
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ~>
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '1.0'
|
76
104
|
type: :development
|
77
105
|
prerelease: false
|
78
106
|
version_requirements: !ruby/object:Gem::Requirement
|
79
107
|
requirements:
|
80
108
|
- - ~>
|
81
109
|
- !ruby/object:Gem::Version
|
82
|
-
version:
|
110
|
+
version: '1.0'
|
83
111
|
- !ruby/object:Gem::Dependency
|
84
112
|
name: rspec
|
85
113
|
requirement: !ruby/object:Gem::Requirement
|