headhunter 0.1.6 → 0.1.7

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: 17899a252da19aa720eaafc32ae6d34fee5d37e6
4
- data.tar.gz: 07fd0c44d1085be0f05b59213ce8d4fcb275daf1
3
+ metadata.gz: 4eab4440d00eba351de19361f2dac45a68db188d
4
+ data.tar.gz: d8689bd2c15d0358f865653976a7f193a6bc7727
5
5
  SHA512:
6
- metadata.gz: 32d2db1f50a555c779dc284d89d53038a0f33269213e6a38fa87f1a006fa48bd1a7752172c8cbceb1bf2eee044173c6b62a2d7aae981c78dc51a3f3c4a2c6cb6
7
- data.tar.gz: e86281c07b6d6889b7c1a5e7a901775203eaf646900f6c8fcdb3a7f1290d8ea56ad616281ae77817cd022d28921d45c51d4320975c484143c50fa8f47bcc0532
6
+ metadata.gz: 17736bf55ce84edf7be0c74a33a8c5b8f25202d293506c7baa3bddf4a50992c436b0925f0ddd11203605ca1bcacc0724c3530bd9a8ae735127ed5966b3d69f65
7
+ data.tar.gz: e9710d38bbc41753ca27d0bd4f928f68c37c1a10750c3b3b4ba7bd15a34eacf40e279af68ef9bfbc8da2d421de603be3c4ed7ed6f342e5df652ebe6dab23be9a
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- headhunter (0.1.5)
4
+ headhunter (0.1.6)
5
5
  colorize
6
6
  css_parser (>= 1.2.6)
7
7
  html_validation
@@ -3,7 +3,7 @@ require 'nokogiri/xml'
3
3
 
4
4
  module Headhunter
5
5
  class CssValidator
6
- VALIDATOR_PATH = Gem.loaded_specs['headhunter'].full_gem_path + '/lib/css-validator/'
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
- Dir.chdir(VALIDATOR_PATH) { `java -jar css-validator.jar --output=soap12 file:#{uri}` }
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
- @document = Nokogiri::XML(convert_soap_to_xml(response)) if response
77
+ @dom = Nokogiri::XML(convert_soap_to_xml(response)) if response
77
78
  end
78
79
 
79
80
  def [](key)
80
- @headers[key]
81
+ @dom[key] # TODO: still needed?
81
82
  end
82
83
 
83
84
  def valid?
84
- @document.css('validity').text == 'true'
85
+ @dom.css('validity').text == 'true'
85
86
  end
86
87
 
87
88
  def errors
88
- @document.css('errors error').map do |error|
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
- @document.css('cssvalidationresponse > uri').text
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(url, html)
12
- # Docs for Tidy: http://tidy.sourceforge.net/docs/quickref.html
13
- @responses << PageValidations::HTMLValidation.new.validation(html, url)
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.resource}:".red
34
-
35
- ([response.exceptions].flatten).each do |exception|
36
- lines << " - #{exception.strip}".red
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
@@ -1,3 +1,3 @@
1
1
  module Headhunter
2
- VERSION = '0.1.6'
2
+ VERSION = '0.1.7'
3
3
  end
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.6
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-12 00:00:00.000000000 Z
11
+ date: 2014-02-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri