html-proofer 0.0.9 → 0.0.10
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +9 -1
- data/README.md +2 -3
- data/html-proofer.gemspec +1 -0
- data/lib/html/proofer.rb +1 -0
- data/lib/html/proofer/check.rb +16 -40
- data/lib/html/proofer/checks/images.rb +1 -1
- data/lib/html/proofer/checks/links.rb +1 -1
- data/lib/html/proofer/version.rb +1 -1
- data/spec/html/proofer/images_spec.rb +5 -3
- data/spec/html/proofer/links_spec.rb +6 -4
- metadata +18 -2
data/Gemfile.lock
CHANGED
@@ -1,9 +1,10 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
html-proofer (0.0.
|
4
|
+
html-proofer (0.0.10)
|
5
5
|
colored (~> 1.2)
|
6
6
|
nokogiri (~> 1.5.6)
|
7
|
+
typhoeus (~> 0.6.3)
|
7
8
|
|
8
9
|
GEM
|
9
10
|
remote: http://rubygems.org/
|
@@ -14,6 +15,10 @@ GEM
|
|
14
15
|
colored (1.2)
|
15
16
|
diff-lcs (1.2.1)
|
16
17
|
escape_utils (0.3.2)
|
18
|
+
ethon (0.5.12)
|
19
|
+
ffi (>= 1.3.0)
|
20
|
+
mime-types (~> 1.18)
|
21
|
+
ffi (1.9.0)
|
17
22
|
gemoji (1.4.0)
|
18
23
|
github-markdown (0.5.3)
|
19
24
|
html-pipeline (0.0.8)
|
@@ -25,6 +30,7 @@ GEM
|
|
25
30
|
rinku (~> 1.7)
|
26
31
|
sanitize (~> 2.0)
|
27
32
|
i18n (0.6.4)
|
33
|
+
mime-types (1.23)
|
28
34
|
multi_json (1.6.1)
|
29
35
|
nokogiri (1.5.6)
|
30
36
|
rinku (1.7.2)
|
@@ -38,6 +44,8 @@ GEM
|
|
38
44
|
rspec-mocks (2.13.0)
|
39
45
|
sanitize (2.0.3)
|
40
46
|
nokogiri (>= 1.4.4, < 1.6)
|
47
|
+
typhoeus (0.6.3)
|
48
|
+
ethon (~> 0.5.11)
|
41
49
|
|
42
50
|
PLATFORMS
|
43
51
|
ruby
|
data/README.md
CHANGED
@@ -20,7 +20,7 @@ Or install it yourself as:
|
|
20
20
|
|
21
21
|
## Usage
|
22
22
|
|
23
|
-
Require the gem; generate some HTML; create a new instance of the `HTML::Proofer` on
|
23
|
+
Require the gem; generate some HTML; create a new instance of the `HTML::Proofer` on
|
24
24
|
your out folder; then `run` it:
|
25
25
|
|
26
26
|
```ruby
|
@@ -56,7 +56,6 @@ The `HTML::Proofer` constructor takes an optional hash of additional options:
|
|
56
56
|
* `:ext`: the extension (including the `.`) of your HTML files (default: `.html`)
|
57
57
|
* `:href_swap`: a hash containing key-value pairs of `RegExp => String`. It transforms links that match `RegExp` into `String` via `gsub`.
|
58
58
|
* `:href_ignore`: an array of Strings containing `href`s that are safe to ignore (default: `mailto`)
|
59
|
-
* `:longTests`: a Boolean indicating if long-running tests should run (for example, tests checking external links)
|
60
59
|
|
61
60
|
## What's Tested?
|
62
61
|
|
@@ -64,4 +63,4 @@ The `HTML::Proofer` constructor takes an optional hash of additional options:
|
|
64
63
|
* Whether your internal image references are not broken
|
65
64
|
* Whether external images are showing
|
66
65
|
* Whether your internal links are not broken; this includes hash references (`#linkToMe`)
|
67
|
-
* Whether external links are working
|
66
|
+
* Whether external links are working
|
data/html-proofer.gemspec
CHANGED
@@ -16,6 +16,7 @@ Gem::Specification.new do |gem|
|
|
16
16
|
|
17
17
|
gem.add_dependency "nokogiri", "~> 1.5.6"
|
18
18
|
gem.add_dependency "colored", "~> 1.2"
|
19
|
+
gem.add_dependency "typhoeus", "~> 0.6.3"
|
19
20
|
|
20
21
|
gem.add_development_dependency "html-pipeline", "~> 0.0.7"
|
21
22
|
gem.add_development_dependency "rspec", "~> 2.13.0"
|
data/lib/html/proofer.rb
CHANGED
data/lib/html/proofer/check.rb
CHANGED
@@ -4,12 +4,13 @@ require 'net/https'
|
|
4
4
|
require 'timeout'
|
5
5
|
require 'uri'
|
6
6
|
require 'colored'
|
7
|
+
require 'typhoeus'
|
7
8
|
|
8
9
|
class HTML::Proofer::Checks
|
9
10
|
|
10
11
|
class Check
|
11
12
|
|
12
|
-
attr_reader :issues
|
13
|
+
attr_reader :issues, :hydra
|
13
14
|
|
14
15
|
def initialize(path, html, opts={})
|
15
16
|
@path = path
|
@@ -17,6 +18,7 @@ class HTML::Proofer::Checks
|
|
17
18
|
@options = opts
|
18
19
|
@issues = []
|
19
20
|
|
21
|
+
@hydra = Typhoeus::Hydra.hydra
|
20
22
|
@additional_href_ignores = @options[:href_ignore] || []
|
21
23
|
end
|
22
24
|
|
@@ -50,48 +52,22 @@ class HTML::Proofer::Checks
|
|
50
52
|
false
|
51
53
|
end
|
52
54
|
|
53
|
-
def validate_url(href)
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
# Get status
|
65
|
-
res = nil
|
66
|
-
5.times do |i|
|
67
|
-
begin
|
68
|
-
Timeout::timeout(10) do
|
69
|
-
res = request_url(url)
|
70
|
-
end
|
71
|
-
rescue => e
|
72
|
-
return nil
|
73
|
-
end
|
74
|
-
|
75
|
-
next if res.code =~ /^5..$/
|
76
|
-
|
77
|
-
if res.code =~ /^3..$/
|
78
|
-
# Find proper location
|
79
|
-
location = res['Location']
|
80
|
-
if location !~ /^https?:\/\//
|
81
|
-
base_url = url.dup
|
82
|
-
base_url.path = (location =~ /^\// ? '' : '/')
|
83
|
-
base_url.query = nil
|
84
|
-
base_url.fragment = nil
|
85
|
-
location = base_url.to_s + location
|
86
|
-
end
|
87
|
-
url = URI.parse(location)
|
88
|
-
elsif res.code == '200'
|
89
|
-
return true
|
55
|
+
def validate_url(href, issue_text)
|
56
|
+
request = Typhoeus::Request.new(href)
|
57
|
+
request.on_complete do |response|
|
58
|
+
if response.success?
|
59
|
+
# no op
|
60
|
+
elsif response.timed_out?
|
61
|
+
self.add_issue(issue_text + " got a time out")
|
62
|
+
elsif response.code == 0
|
63
|
+
# Could not get an http response, something's wrong.
|
64
|
+
self.add_issue(issue_text + " #{response}")
|
90
65
|
else
|
91
|
-
|
66
|
+
# Received a non-successful http response.
|
67
|
+
self.add_issue(issue_text + " HTTP request failed: " + response.code.to_s)
|
92
68
|
end
|
93
69
|
end
|
94
|
-
|
70
|
+
hydra.queue(request)
|
95
71
|
end
|
96
72
|
|
97
73
|
def request_url(url)
|
@@ -11,7 +11,7 @@ class Images < ::HTML::Proofer::Checks::Check
|
|
11
11
|
if !external_href?(src)
|
12
12
|
self.add_issue("#{@path}".blue + ": internal image #{src} does not exist") unless src[0] != "/" and File.exist?(File.join(File.dirname(@path), src))
|
13
13
|
else
|
14
|
-
|
14
|
+
validate_url(src, "#{@path}".blue + ": external image #{src} does not exist")
|
15
15
|
end
|
16
16
|
else
|
17
17
|
self.add_issue("#{@path}".blue + ": image has no src attribute")
|
@@ -47,7 +47,7 @@ class Links < ::HTML::Proofer::Checks::Check
|
|
47
47
|
self.add_issue("#{@path}".blue + ": internally linking to #{href}, which does not exist") unless File.exist?(File.join(File.dirname(@path), href))
|
48
48
|
end
|
49
49
|
else
|
50
|
-
|
50
|
+
validate_url(href, "#{@path}".blue + ": externally linking to #{href}, which does not exist")
|
51
51
|
end
|
52
52
|
else
|
53
53
|
self.add_issue("#{@path}".blue + ": link has no href attribute") unless a['name'] || a['id']
|
data/lib/html/proofer/version.rb
CHANGED
@@ -3,7 +3,7 @@ require "spec_helper"
|
|
3
3
|
describe "Image tests" do
|
4
4
|
it "passes for existing external images" do
|
5
5
|
externalImageFilepath = "#{FIXTURES_DIR}/existingImageExternal.html"
|
6
|
-
@imageCheck = Images.new(externalImageFilepath, HTML::Proofer.create_nokogiri(externalImageFilepath)
|
6
|
+
@imageCheck = Images.new(externalImageFilepath, HTML::Proofer.create_nokogiri(externalImageFilepath))
|
7
7
|
@imageCheck.run
|
8
8
|
@imageCheck.issues[0].should eq(nil)
|
9
9
|
end
|
@@ -31,8 +31,10 @@ describe "Image tests" do
|
|
31
31
|
|
32
32
|
it "fails for missing external images" do
|
33
33
|
externalImageFilepath = "#{FIXTURES_DIR}/missingImageExternal.html"
|
34
|
-
@imageCheck = Images.new(externalImageFilepath, HTML::Proofer.create_nokogiri(externalImageFilepath)
|
34
|
+
@imageCheck = Images.new(externalImageFilepath, HTML::Proofer.create_nokogiri(externalImageFilepath))
|
35
35
|
@imageCheck.run
|
36
|
+
@imageCheck.hydra.run
|
37
|
+
@imageCheck.issues[0].sub!(/ #<Typhoeus::Response:[\w]+>/, "")
|
36
38
|
@imageCheck.issues[0].should eq("spec/html/proofer/fixtures/missingImageExternal.html".blue + ": external image http://www.whatthehell does not exist")
|
37
39
|
end
|
38
40
|
|
@@ -56,4 +58,4 @@ describe "Image tests" do
|
|
56
58
|
@imageCheck.run
|
57
59
|
@imageCheck.issues[0].should eq("spec/html/proofer/fixtures/terribleImageName.html".blue + ": image has a terrible filename (./Screen Shot 2012-08-09 at 7.51.18 AM.png)")
|
58
60
|
end
|
59
|
-
end
|
61
|
+
end
|
@@ -18,8 +18,10 @@ describe "Links tests" do
|
|
18
18
|
|
19
19
|
it "fails for broken external links" do
|
20
20
|
brokenLinkExternalFilepath = "#{FIXTURES_DIR}/brokenLinkExternal.html"
|
21
|
-
@linkCheck = Links.new(brokenLinkExternalFilepath, HTML::Proofer.create_nokogiri(brokenLinkExternalFilepath)
|
21
|
+
@linkCheck = Links.new(brokenLinkExternalFilepath, HTML::Proofer.create_nokogiri(brokenLinkExternalFilepath))
|
22
22
|
@linkCheck.run
|
23
|
+
@linkCheck.hydra.run
|
24
|
+
@linkCheck.issues[0].sub!(/ #<Typhoeus::Response:[\w]+>/, "")
|
23
25
|
@linkCheck.issues[0].should eq("spec/html/proofer/fixtures/brokenLinkExternal.html".blue + ": externally linking to http://www.asdo3IRJ395295jsingrkrg4.com, which does not exist")
|
24
26
|
end
|
25
27
|
|
@@ -39,14 +41,14 @@ describe "Links tests" do
|
|
39
41
|
|
40
42
|
it "should follow redirects" do
|
41
43
|
linkWithRedirectFilepath = "#{FIXTURES_DIR}/linkWithRedirect.html"
|
42
|
-
@linkCheck = Links.new(linkWithRedirectFilepath, HTML::Proofer.create_nokogiri(linkWithRedirectFilepath)
|
44
|
+
@linkCheck = Links.new(linkWithRedirectFilepath, HTML::Proofer.create_nokogiri(linkWithRedirectFilepath))
|
43
45
|
@linkCheck.run
|
44
46
|
@linkCheck.issues[0].should eq(nil)
|
45
47
|
end
|
46
48
|
|
47
49
|
it "should understand https" do
|
48
50
|
linkWithHttpsFilepath = "#{FIXTURES_DIR}/linkWithHttps.html"
|
49
|
-
@linkCheck = Links.new(linkWithHttpsFilepath, HTML::Proofer.create_nokogiri(linkWithHttpsFilepath)
|
51
|
+
@linkCheck = Links.new(linkWithHttpsFilepath, HTML::Proofer.create_nokogiri(linkWithHttpsFilepath))
|
50
52
|
@linkCheck.run
|
51
53
|
@linkCheck.issues[0].should eq(nil)
|
52
54
|
end
|
@@ -57,4 +59,4 @@ describe "Links tests" do
|
|
57
59
|
@linkCheck.run
|
58
60
|
@linkCheck.issues[0].should eq(nil)
|
59
61
|
end
|
60
|
-
end
|
62
|
+
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.0.
|
4
|
+
version: 0.0.10
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-06-29 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: nokogiri
|
@@ -43,6 +43,22 @@ dependencies:
|
|
43
43
|
- - ~>
|
44
44
|
- !ruby/object:Gem::Version
|
45
45
|
version: '1.2'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: typhoeus
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ~>
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: 0.6.3
|
54
|
+
type: :runtime
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 0.6.3
|
46
62
|
- !ruby/object:Gem::Dependency
|
47
63
|
name: html-pipeline
|
48
64
|
requirement: !ruby/object:Gem::Requirement
|