html-proofer 1.1.5 → 1.1.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +26 -0
- data/.travis.yml +6 -0
- data/Gemfile +3 -0
- data/LICENSE.txt +22 -0
- data/README.md +177 -0
- data/Rakefile +8 -0
- data/html-proofer.gemspec +28 -0
- data/spec/html/proofer/favicon_spec.rb +46 -0
- data/spec/html/proofer/fixtures/favicon/favicon_absent.html +4 -0
- data/spec/html/proofer/fixtures/favicon/favicon_absent_apple.html +7 -0
- data/spec/html/proofer/fixtures/favicon/favicon_broken.html +7 -0
- data/spec/html/proofer/fixtures/favicon/favicon_broken_but_ignored.html +7 -0
- data/spec/html/proofer/fixtures/favicon/favicon_present.html +7 -0
- data/spec/html/proofer/fixtures/favicon/favicon_present_shortcut.html +7 -0
- data/spec/html/proofer/fixtures/images/existingImageExternal.html +9 -0
- data/spec/html/proofer/fixtures/images/gpl.png +0 -0
- data/spec/html/proofer/fixtures/images/ignorableAltViaOptions.html +13 -0
- data/spec/html/proofer/fixtures/images/ignorableImages.html +10 -0
- data/spec/html/proofer/fixtures/images/ignoreAltButNotLink.html +13 -0
- data/spec/html/proofer/fixtures/images/image_missing_protocol_invalid.html +9 -0
- data/spec/html/proofer/fixtures/images/image_missing_protocol_valid.html +9 -0
- data/spec/html/proofer/fixtures/images/missingImageAlt.html +9 -0
- data/spec/html/proofer/fixtures/images/missingImageAltText.html +9 -0
- data/spec/html/proofer/fixtures/images/missingImageExternal.html +9 -0
- data/spec/html/proofer/fixtures/images/missingImageInternal.html +9 -0
- data/spec/html/proofer/fixtures/images/missingImageSrc.html +9 -0
- data/spec/html/proofer/fixtures/images/relativeToSelf.html +2 -0
- data/spec/html/proofer/fixtures/images/rootRelativeImages.html +2 -0
- data/spec/html/proofer/fixtures/images/terribleImageName.html +9 -0
- data/spec/html/proofer/fixtures/images/workingDataURIImage.html +3 -0
- data/spec/html/proofer/fixtures/links/anchors_in_pre.html +12 -0
- data/spec/html/proofer/fixtures/links/blank_mailto_link.html +9 -0
- data/spec/html/proofer/fixtures/links/blank_tel_link.html +9 -0
- data/spec/html/proofer/fixtures/links/brokenHashExternal.html +11 -0
- data/spec/html/proofer/fixtures/links/brokenHashInternal.html +14 -0
- data/spec/html/proofer/fixtures/links/brokenInternalLink.html +0 -0
- data/spec/html/proofer/fixtures/links/brokenLinkExternal.html +11 -0
- data/spec/html/proofer/fixtures/links/brokenLinkInternal.html +10 -0
- data/spec/html/proofer/fixtures/links/brokenLinkWithNumber.html +8 -0
- data/spec/html/proofer/fixtures/links/checkSSLLinks.html +1 -0
- data/spec/html/proofer/fixtures/links/folder/anchorLink.html +0 -0
- data/spec/html/proofer/fixtures/links/folder/assets/barrel.png +0 -0
- data/spec/html/proofer/fixtures/links/folder/index.html +0 -0
- data/spec/html/proofer/fixtures/links/folder/relativeImage.html +2 -0
- data/spec/html/proofer/fixtures/links/gpl.png +0 -0
- data/spec/html/proofer/fixtures/links/head_link_href.html +7 -0
- data/spec/html/proofer/fixtures/links/head_link_href_absent.html +7 -0
- data/spec/html/proofer/fixtures/links/head_link_href_empty.html +7 -0
- data/spec/html/proofer/fixtures/links/ignorableLinks.html +13 -0
- data/spec/html/proofer/fixtures/links/ignorableLinksViaOptions.html +13 -0
- data/spec/html/proofer/fixtures/links/index.html +1 -0
- data/spec/html/proofer/fixtures/links/javascript_link.html +9 -0
- data/spec/html/proofer/fixtures/links/linkToFolder.html +9 -0
- data/spec/html/proofer/fixtures/links/linkTranslatedViaHrefSwap.html +9 -0
- data/spec/html/proofer/fixtures/links/linkWithHttps.html +9 -0
- data/spec/html/proofer/fixtures/links/linkWithRedirect.html +12 -0
- data/spec/html/proofer/fixtures/links/link_directory_without_slash.html +1 -0
- data/spec/html/proofer/fixtures/links/link_missing_protocol_invalid.html +9 -0
- data/spec/html/proofer/fixtures/links/link_missing_protocol_valid.html +9 -0
- data/spec/html/proofer/fixtures/links/links_in_pre.html +13 -0
- data/spec/html/proofer/fixtures/links/mailto_link.html +9 -0
- data/spec/html/proofer/fixtures/links/missingLinkHref.html +9 -0
- data/spec/html/proofer/fixtures/links/multipleProblems.html +11 -0
- data/spec/html/proofer/fixtures/links/notarealhash.html +0 -0
- data/spec/html/proofer/fixtures/links/relativeLinks.html +4 -0
- data/spec/html/proofer/fixtures/links/rootLink.html +10 -0
- data/spec/html/proofer/fixtures/links/tel_link.html +9 -0
- data/spec/html/proofer/fixtures/resources/Screen Shot 2012-08-09 at 7.51.18 AM.png +0 -0
- data/spec/html/proofer/fixtures/resources/books/assets/getting-good-with-git.jpg +0 -0
- data/spec/html/proofer/fixtures/resources/books/assets/pro-git.jpg +0 -0
- data/spec/html/proofer/fixtures/resources/books/assets/version-control-with-git.jpg +0 -0
- data/spec/html/proofer/fixtures/resources/books/nestedRelativeImages.html +5 -0
- data/spec/html/proofer/fixtures/resources/gpl.png +0 -0
- data/spec/html/proofer/fixtures/scripts/script.js +1 -0
- data/spec/html/proofer/fixtures/scripts/script_broken_external.html +9 -0
- data/spec/html/proofer/fixtures/scripts/script_content.html +9 -0
- data/spec/html/proofer/fixtures/scripts/script_content_absent.html +9 -0
- data/spec/html/proofer/fixtures/scripts/script_in_pre.html +5 -0
- data/spec/html/proofer/fixtures/scripts/script_missing_internal.html +9 -0
- data/spec/html/proofer/fixtures/scripts/script_valid_internal.html +9 -0
- data/spec/html/proofer/images_spec.rb +98 -0
- data/spec/html/proofer/links_spec.rb +192 -0
- data/spec/html/proofer/scripts_spec.rb +41 -0
- data/spec/html/proofer_spec.rb +12 -0
- data/spec/spec_helper.rb +30 -0
- metadata +166 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: af929be3f389ca9ac9d1fc449552207eaf5d983a
|
4
|
+
data.tar.gz: 4197105516d8e7e6cf4768ca57d5e45996aef9ee
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 82d3cffe4c8295939d0140a5e0ad297fed56dfbf0031700eb28eeb2bebb9e187f5cfc7587042a23b9534276f7530f63aeddfb7635993426bbbc1476a3ab4c06f
|
7
|
+
data.tar.gz: d8a50d7cb65def4b4f7ca9be03d0ae1ceac83b495cb34f9d7501650a8cac2a1c072a2a25a8b186f1b5459a52559fb39afe8581f16ff388e4cbce4c21e8a91e06
|
data/.gitignore
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
.bundle
|
4
|
+
.config
|
5
|
+
coverage
|
6
|
+
InstalledFiles
|
7
|
+
lib/bundler/man
|
8
|
+
pkg
|
9
|
+
rdoc
|
10
|
+
spec/reports
|
11
|
+
test/tmp
|
12
|
+
test/version_tmp
|
13
|
+
tmp
|
14
|
+
|
15
|
+
Gemfile.lock
|
16
|
+
out/
|
17
|
+
sample.rb
|
18
|
+
run_sample.rb
|
19
|
+
src/
|
20
|
+
docs/
|
21
|
+
|
22
|
+
# YARD artifacts
|
23
|
+
.yardoc
|
24
|
+
_yardoc
|
25
|
+
doc/
|
26
|
+
.DS_Store
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Garen Torikian
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,177 @@
|
|
1
|
+
# HTML::Proofer
|
2
|
+
|
3
|
+
If you generate HTML files, _then this tool might be for you_.
|
4
|
+
|
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
|
+
|
7
|
+
[![Build Status](https://travis-ci.org/gjtorikian/html-proofer.png?branch=master)](https://travis-ci.org/gjtorikian/html-proofer) [![Gem Version](https://badge.fury.io/rb/html-proofer.png)](http://badge.fury.io/rb/html-proofer)
|
8
|
+
|
9
|
+
## Installation
|
10
|
+
|
11
|
+
Add this line to your application's Gemfile:
|
12
|
+
|
13
|
+
gem 'html-proofer'
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install html-proofer
|
22
|
+
|
23
|
+
**NOTE:** When installation speed matters, set `NOKOGIRI_USE_SYSTEM_LIBRARIES` to `true` in your environment. This is useful for increasing the speed of your Continuous Integration builds.
|
24
|
+
|
25
|
+
## Usage
|
26
|
+
|
27
|
+
### Using in a script
|
28
|
+
|
29
|
+
Require the gem; generate some HTML; create a new instance of the `HTML::Proofer` on
|
30
|
+
your output folder; then `run` it. Here's a simple example:
|
31
|
+
|
32
|
+
```ruby
|
33
|
+
require 'html/proofer'
|
34
|
+
require 'html/pipeline'
|
35
|
+
require 'find'
|
36
|
+
|
37
|
+
# make an out dir
|
38
|
+
Dir.mkdir("out") unless File.exists?("out")
|
39
|
+
|
40
|
+
pipeline = HTML::Pipeline.new [
|
41
|
+
HTML::Pipeline::MarkdownFilter,
|
42
|
+
HTML::Pipeline::TableOfContentsFilter
|
43
|
+
], :gfm => true
|
44
|
+
|
45
|
+
# iterate over files, and generate HTML from Markdown
|
46
|
+
Find.find("./docs") do |path|
|
47
|
+
if File.extname(path) == ".md"
|
48
|
+
contents = File.read(path)
|
49
|
+
result = pipeline.call(contents)
|
50
|
+
|
51
|
+
File.open("out/#{path.split("/").pop.sub('.md', '.html')}", 'w') { |file| file.write(result[:output].to_s) }
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
# test your out dir!
|
56
|
+
HTML::Proofer.new("./out").run
|
57
|
+
```
|
58
|
+
|
59
|
+
### Using on the command-line
|
60
|
+
|
61
|
+
You'll get a new program called `htmlproof` with this gem. Jawesome!
|
62
|
+
|
63
|
+
Use it like you'd expect to:
|
64
|
+
|
65
|
+
``` bash
|
66
|
+
htmlproof run ./out --swap wow:cow,mow:doh --ext .html.erb --ignore www.github.com
|
67
|
+
```
|
68
|
+
|
69
|
+
Note: since `swap` is a bit special, you'll pass in a pair of `RegEx:String` values.
|
70
|
+
`htmlproof` will figure out what you mean.
|
71
|
+
|
72
|
+
### Using with Jekyll
|
73
|
+
|
74
|
+
Want to use HTML Proofer with your Jekyll site? Awesome. Simply add `gem 'html-proofer'`
|
75
|
+
to your `Gemfile` as described above, and add the following to your `Rakefile`,
|
76
|
+
using `rake test` to execute:
|
77
|
+
|
78
|
+
```ruby
|
79
|
+
require 'html/proofer'
|
80
|
+
|
81
|
+
task :test do
|
82
|
+
sh "bundle exec jekyll build"
|
83
|
+
HTML::Proofer.new("./_site").run
|
84
|
+
end
|
85
|
+
```
|
86
|
+
|
87
|
+
Don't have or want a `Rakefile`? You _could_ also do something like the following:
|
88
|
+
|
89
|
+
```bash
|
90
|
+
htmlproof ./_site
|
91
|
+
```
|
92
|
+
|
93
|
+
## What's Tested?
|
94
|
+
|
95
|
+
### Images
|
96
|
+
|
97
|
+
`img` elements:
|
98
|
+
|
99
|
+
* Whether all your images have alt tags
|
100
|
+
* Whether your internal image references are not broken
|
101
|
+
* Whether external images are showing
|
102
|
+
|
103
|
+
### Links
|
104
|
+
|
105
|
+
`a`, `link` elements:
|
106
|
+
|
107
|
+
* Whether your internal links are not broken; this includes hash references (`#linkToMe`)
|
108
|
+
* Whether external links are working
|
109
|
+
|
110
|
+
### Scripts
|
111
|
+
|
112
|
+
`script` elements:
|
113
|
+
|
114
|
+
* Whether your internal script references are not broken
|
115
|
+
* Whether external scripts are loading
|
116
|
+
|
117
|
+
## Configuration
|
118
|
+
|
119
|
+
The `HTML::Proofer` constructor takes an optional hash of additional options:
|
120
|
+
|
121
|
+
| Option | Description | Default |
|
122
|
+
| :----- | :---------- | :------ |
|
123
|
+
| `disable_external` | If `true`, does not run the external link checker, which can take a lot of time. | `false` |
|
124
|
+
| `ext` | The extension of your HTML files including the dot. | `.html`
|
125
|
+
| `favicon` | Enables the favicon checker. | `false` |
|
126
|
+
| `followlocation` | Follows external redirections. Amends missing trailing slashes to internal directories. | `true` |
|
127
|
+
| `as_link_array` | Assumes that you've passed in just an array of links to check. | `false` |
|
128
|
+
| `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. | `[]` |
|
129
|
+
| `alt_ignore` | An array of Strings or RegExps containing `img`s whose missing `alt` tags are safe to ignore. | `[]` |
|
130
|
+
| `href_swap` | A hash containing key-value pairs of `RegExp => String`. It transforms links that match `RegExp` into `String` via `gsub`. | `{}` |
|
131
|
+
| `verbose` | If `true`, outputs extra information as the checking happens. Useful for debugging. | `false` |
|
132
|
+
|
133
|
+
You can also pass in any of Typhoeus' options for the external link check. For example:
|
134
|
+
|
135
|
+
``` ruby
|
136
|
+
HTML::Proofer.new("out/", {:ext => ".htm", :verbose = > true, :ssl_verifyhost => 2 })
|
137
|
+
```
|
138
|
+
|
139
|
+
This sets `HTML::Proofer`'s extensions to use _.htm_, and gives Typhoeus a configuration 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.
|
140
|
+
|
141
|
+
## Ignoring content
|
142
|
+
|
143
|
+
Add the `data-proofer-ignore` attribute to any tag to ignore it from the checks.
|
144
|
+
|
145
|
+
## Custom tests
|
146
|
+
|
147
|
+
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.
|
148
|
+
|
149
|
+
Here's an example custom test that protects against `mailto` links:
|
150
|
+
|
151
|
+
``` ruby
|
152
|
+
class OctocatLink < ::HTML::Proofer::Checkable
|
153
|
+
|
154
|
+
def mailto?
|
155
|
+
return false if @data_ignore_proofer || @href.nil? || @href.empty?
|
156
|
+
return @href.match /^mailto\:/
|
157
|
+
end
|
158
|
+
|
159
|
+
def octocat?
|
160
|
+
return @href.match /\:octocat@github.com\Z/
|
161
|
+
end
|
162
|
+
|
163
|
+
end
|
164
|
+
|
165
|
+
class MailToOctocat < ::HTML::Proofer::Checks::Check
|
166
|
+
|
167
|
+
def run
|
168
|
+
@html.css('a').each do |l|
|
169
|
+
link = OctocatLink.new l, "octocat_link", self
|
170
|
+
|
171
|
+
if link.mailto? && link.octocat?
|
172
|
+
return self.add_issue("Don't email the Octocat directly!")
|
173
|
+
end
|
174
|
+
end
|
175
|
+
end
|
176
|
+
end
|
177
|
+
```
|
data/Rakefile
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.name = "html-proofer"
|
6
|
+
gem.version = "1.1.6"
|
7
|
+
gem.authors = ["Garen Torikian"]
|
8
|
+
gem.email = ["gjtorikian@gmail.com"]
|
9
|
+
gem.description = %q{Test your rendered HTML files to make sure they're accurate.}
|
10
|
+
gem.summary = %q{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 documentation output.}
|
11
|
+
gem.homepage = "https://github.com/gjtorikian/html-proofer"
|
12
|
+
gem.license = "MIT"
|
13
|
+
gem.executables = ["htmlproof"]
|
14
|
+
gem.files = `git ls-files`.split($/)
|
15
|
+
gem.test_files = gem.files.grep(%r{^(spec)/})
|
16
|
+
gem.require_paths = ["lib"]
|
17
|
+
|
18
|
+
gem.add_dependency "mercenary", "~> 0.3.2"
|
19
|
+
gem.add_dependency "nokogiri", "~> 1.5"
|
20
|
+
gem.add_dependency "colored", "~> 1.2"
|
21
|
+
gem.add_dependency "typhoeus", "~> 0.6.7"
|
22
|
+
gem.add_dependency "yell", "~> 2.0"
|
23
|
+
|
24
|
+
gem.add_development_dependency "html-pipeline", "~> 1.8"
|
25
|
+
gem.add_development_dependency "escape_utils", "~> 1.0" # Ruby 2.1 fix
|
26
|
+
gem.add_development_dependency "rspec", "~> 2.13.0"
|
27
|
+
gem.add_development_dependency "rake"
|
28
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe "Favicons test" do
|
4
|
+
it "ignores for absent favicon by default" do
|
5
|
+
absent = "#{FIXTURES_DIR}/favicon/favicon_absent.html"
|
6
|
+
output = capture_stderr { HTML::Proofer.new(absent).run }
|
7
|
+
output.should == ""
|
8
|
+
end
|
9
|
+
|
10
|
+
it "fails for absent favicon" do
|
11
|
+
absent = "#{FIXTURES_DIR}/favicon/favicon_absent.html"
|
12
|
+
output = capture_stderr { HTML::Proofer.new(absent, {:favicon => true}).run }
|
13
|
+
output.should match /no favicon specified/
|
14
|
+
end
|
15
|
+
|
16
|
+
it "fails for absent favicon but present apple touch icon" do
|
17
|
+
absent = "#{FIXTURES_DIR}/favicon/favicon_absent_apple.html"
|
18
|
+
output = capture_stderr { HTML::Proofer.new(absent, {:favicon => true}).run }
|
19
|
+
output.should match /no favicon specified/
|
20
|
+
end
|
21
|
+
|
22
|
+
it "fails for broken favicon" do
|
23
|
+
broken = "#{FIXTURES_DIR}/favicon/favicon_broken.html"
|
24
|
+
output = capture_stderr { HTML::Proofer.new(broken, {:favicon => true}).run }
|
25
|
+
output.should match /internally linking to asdadaskdalsdk.png/
|
26
|
+
end
|
27
|
+
|
28
|
+
it "passes for present favicon" do
|
29
|
+
present = "#{FIXTURES_DIR}/favicon/favicon_present.html"
|
30
|
+
output = capture_stderr { HTML::Proofer.new(present, {:favicon => true}).run }
|
31
|
+
output.should == ""
|
32
|
+
end
|
33
|
+
|
34
|
+
it "passes for present favicon with shortcut notation" do
|
35
|
+
present = "#{FIXTURES_DIR}/favicon/favicon_present_shortcut.html"
|
36
|
+
output = capture_stderr { HTML::Proofer.new(present, {:favicon => true}).run }
|
37
|
+
output.should == ""
|
38
|
+
end
|
39
|
+
|
40
|
+
it "passes for broken favicon with data-proofer-ignore" do
|
41
|
+
broken_but_ignored = "#{FIXTURES_DIR}/favicon/favicon_broken_but_ignored.html"
|
42
|
+
output = capture_stderr { HTML::Proofer.new(broken_but_ignored, {:favicon => true}).run }
|
43
|
+
output.should == ""
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
Binary file
|