headhunter 0.1.6 → 0.1.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/headhunter/css_validator.rb +8 -7
- data/lib/headhunter/html_validator.rb +55 -7
- data/lib/headhunter/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4eab4440d00eba351de19361f2dac45a68db188d
|
4
|
+
data.tar.gz: d8689bd2c15d0358f865653976a7f193a6bc7727
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 17736bf55ce84edf7be0c74a33a8c5b8f25202d293506c7baa3bddf4a50992c436b0925f0ddd11203605ca1bcacc0724c3530bd9a8ae735127ed5966b3d69f65
|
7
|
+
data.tar.gz: e9710d38bbc41753ca27d0bd4f928f68c37c1a10750c3b3b4ba7bd15a34eacf40e279af68ef9bfbc8da2d421de603be3c4ed7ed6f342e5df652ebe6dab23be9a
|
data/Gemfile.lock
CHANGED
@@ -3,7 +3,7 @@ require 'nokogiri/xml'
|
|
3
3
|
|
4
4
|
module Headhunter
|
5
5
|
class CssValidator
|
6
|
-
|
6
|
+
VALIDATOR_DIR = Gem.loaded_specs['headhunter'].full_gem_path + '/lib/css-validator/'
|
7
7
|
|
8
8
|
attr_reader :stylesheets, :responses
|
9
9
|
|
@@ -21,7 +21,8 @@ module Headhunter
|
|
21
21
|
# See http://stackoverflow.com/questions/1137884/is-there-an-open-source-css-validator-that-can-be-run-locally
|
22
22
|
# More config options see http://jigsaw.w3.org/css-validator/manual.html
|
23
23
|
results = if File.exists?(uri)
|
24
|
-
|
24
|
+
# TODO: Better use Open3.popen3!
|
25
|
+
Dir.chdir(VALIDATOR_DIR) { `java -jar css-validator.jar --output=soap12 file:#{uri}` }
|
25
26
|
else
|
26
27
|
raise "Couldn't locate uri #{uri}"
|
27
28
|
end
|
@@ -73,19 +74,19 @@ module Headhunter
|
|
73
74
|
|
74
75
|
class Response
|
75
76
|
def initialize(response = nil)
|
76
|
-
@
|
77
|
+
@dom = Nokogiri::XML(convert_soap_to_xml(response)) if response
|
77
78
|
end
|
78
79
|
|
79
80
|
def [](key)
|
80
|
-
@
|
81
|
+
@dom[key] # TODO: still needed?
|
81
82
|
end
|
82
83
|
|
83
84
|
def valid?
|
84
|
-
@
|
85
|
+
@dom.css('validity').text == 'true'
|
85
86
|
end
|
86
87
|
|
87
88
|
def errors
|
88
|
-
@
|
89
|
+
@dom.css('errors error').map do |error|
|
89
90
|
Error.new( error.css('line').text.strip.to_i,
|
90
91
|
error.css('message').text.strip[0..-3],
|
91
92
|
errortype: error.css('errortype').text.strip,
|
@@ -97,7 +98,7 @@ module Headhunter
|
|
97
98
|
end
|
98
99
|
|
99
100
|
def uri
|
100
|
-
@
|
101
|
+
@dom.css('cssvalidationresponse > uri').text
|
101
102
|
end
|
102
103
|
|
103
104
|
private
|
@@ -2,15 +2,26 @@ require 'html_validation'
|
|
2
2
|
|
3
3
|
module Headhunter
|
4
4
|
class HtmlValidator
|
5
|
+
VALIDATOR_DIR = Gem.loaded_specs['headhunter'].full_gem_path + '/lib/tidy/'
|
6
|
+
|
5
7
|
attr_reader :responses
|
6
8
|
|
7
9
|
def initialize
|
8
10
|
@responses = []
|
9
11
|
end
|
10
12
|
|
11
|
-
def validate(
|
12
|
-
|
13
|
-
|
13
|
+
def validate(uri, html)
|
14
|
+
Dir.chdir(VALIDATOR_DIR) do
|
15
|
+
# Docs for Tidy: http://tidy.sourceforge.net/docs/quickref.html
|
16
|
+
stdin, stdout, stderr = Open3.popen3('tidy -quiet')
|
17
|
+
stdin.puts html
|
18
|
+
stdin.close
|
19
|
+
stdout.close
|
20
|
+
|
21
|
+
@responses << Response.new(stderr.read, uri)
|
22
|
+
stderr.close
|
23
|
+
end
|
24
|
+
|
14
25
|
@responses.last
|
15
26
|
end
|
16
27
|
|
@@ -30,10 +41,10 @@ module Headhunter
|
|
30
41
|
lines << "#{x_pages_be(invalid_responses.size)} invalid.".red if invalid_responses.size > 0
|
31
42
|
|
32
43
|
invalid_responses.each do |response|
|
33
|
-
lines << " #{response.
|
34
|
-
|
35
|
-
|
36
|
-
lines << " - #{
|
44
|
+
lines << " #{response.uri}:".red
|
45
|
+
|
46
|
+
response.errors.each do |error|
|
47
|
+
lines << " - #{error.to_s}".red
|
37
48
|
end
|
38
49
|
end
|
39
50
|
|
@@ -47,5 +58,42 @@ module Headhunter
|
|
47
58
|
"#{size} pages are"
|
48
59
|
end
|
49
60
|
end
|
61
|
+
|
62
|
+
class Response
|
63
|
+
attr_reader :uri
|
64
|
+
|
65
|
+
def initialize(response = nil, uri = nil)
|
66
|
+
@response = response
|
67
|
+
@uri = uri
|
68
|
+
end
|
69
|
+
|
70
|
+
def valid?
|
71
|
+
@response.empty?
|
72
|
+
end
|
73
|
+
|
74
|
+
def errors
|
75
|
+
@response.split("\n").map do |error|
|
76
|
+
matches = error.match(/line (\d*) column (\d*) - (.*)/)
|
77
|
+
Error.new( matches[1],
|
78
|
+
matches[3],
|
79
|
+
column: matches[2]
|
80
|
+
)
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
class Error
|
85
|
+
attr_reader :line, :message, :details
|
86
|
+
|
87
|
+
def initialize(line, message, details = {})
|
88
|
+
@line = line
|
89
|
+
@message = message
|
90
|
+
@details = details
|
91
|
+
end
|
92
|
+
|
93
|
+
def to_s
|
94
|
+
"Line #{@line}, column #{@details[:column]}: #{@message}."
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
50
98
|
end
|
51
99
|
end
|
data/lib/headhunter/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: headhunter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Joshua Muheim
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-02-
|
11
|
+
date: 2014-02-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nokogiri
|