w3clove 0.3.2 → 0.3.3

Sign up to get free protection for your applications and to get access to all the features.
data/bin/w3clove CHANGED
@@ -7,7 +7,7 @@ begin
7
7
  if ARGV.length == 2
8
8
  W3Clove::Validator.check(ARGV[0], ARGV[1])
9
9
  else
10
- puts "USAGE: w3clove url_of_xml_sitemap output_file.html"
10
+ puts "USAGE: w3clove url_of_xml_sitemap output_file.html"
11
11
  end
12
12
  rescue
13
13
  puts "There was an error processing your request"
data/lib/w3clove/page.rb CHANGED
@@ -31,7 +31,9 @@ module W3Clove
31
31
  # If it has no validation errors, it will be an empty array.
32
32
  # It an exception occurs, it will be nil.
33
33
  def errors
34
- @errors ||= validations.errors.map do |e|
34
+ @errors ||= validations.errors
35
+ .select {|e| e.message_id && !e.message_id.empty?}
36
+ .map do |e|
35
37
  W3Clove::Message.new(e.message_id, e.line, e.message, :error)
36
38
  end
37
39
  rescue Exception => e
@@ -44,7 +46,9 @@ module W3Clove
44
46
  # If it has no validation warnings, it will be an empty array.
45
47
  # It an exception occurs, it will be nil.
46
48
  def warnings
47
- @warnings ||= validations.warnings.map do |w|
49
+ @warnings ||= validations.warnings
50
+ .select {|w| w.message_id && !w.message_id.empty?}
51
+ .map do |w|
48
52
  W3Clove::Message.new(w.message_id, w.line, w.message, :warning)
49
53
  end
50
54
  rescue Exception => e
@@ -23,6 +23,8 @@
23
23
  border: 1px solid black;
24
24
  background-color: white;
25
25
  }
26
+ a { text-decoration: none; color: black;}
27
+ a:hover { text-decoration: underline; }
26
28
  </style>
27
29
  </head>
28
30
  <body>
@@ -31,16 +33,28 @@
31
33
  </div>
32
34
 
33
35
  <div id="main">
34
- <h1>Report for <%= @url %></h1>
36
+ <h1>Report for <a href='<%= @url %>'><%= @url %></a></h1>
35
37
 
36
38
  <h2>SITEMAP SUMMARY</h2>
37
39
  <p>TOTAL: <%= errors.length %> errors, <%= warnings.length %> warnings.</p>
38
-
39
40
  <% if errors.length > 0 %>
40
41
  <h2>POPULAR ERRORS</h2>
41
42
  <ul>
42
43
  <% errors.group_by {|e| e.message_id}.sort_by {|m,e| e.length}.reverse.each do |message_id, errors| %>
43
- <li>error <a href="http://validator.w3.org/docs/errors.html#ve-<%= message_id %>"><%= message_id %></a> happens <%= errors.length %> times</li>
44
+ <% if message_id == 'html5' %>
45
+ <li><%= errors.length %> HTML5 errors found</li>
46
+ <ul>
47
+ <% errors.select{|e| e.message_id == 'html5'}
48
+ .group_by {|e| e.text}
49
+ .sort_by {|m,e| e.length}
50
+ .reverse.each do |text, errors| %>
51
+ <li><%= errors.length %> times: <strong><%= text %></strong></li>
52
+ <% end %>
53
+ </ul>
54
+ <% elsif message_id %>
55
+ <li>error <a href="http://validator.w3.org/docs/errors.html#ve-<%= message_id %>"><%= message_id %></a>
56
+ happens <%= errors.length %> times</li>
57
+ <% end %>
44
58
  <% end %>
45
59
  </ul>
46
60
  <% end %>
@@ -49,7 +63,20 @@
49
63
  <h2>POPULAR WARNINGS</h2>
50
64
  <ul>
51
65
  <% warnings.group_by {|w| w.message_id}.sort_by {|m,w| w.length}.reverse.each do |message_id, warnings| %>
52
- <li>warning <a href="http://validator.w3.org/docs/errors.html#ve-<%= message_id %>"><%= message_id %></a> found <%= warnings.length %> times</li>
66
+ <% if message_id == 'html5' %>
67
+ <li><%= warnings.length %> HTML5 warnings found</li>
68
+ <ul>
69
+ <% warnings.select{|w| w.message_id == 'html5'}
70
+ .group_by {|w| w.text}
71
+ .sort_by {|m,w| w.length}
72
+ .reverse.each do |text, warnings| %>
73
+ <li><%= warnings.length %> times: <strong><%= text %></strong></li>
74
+ <% end %>
75
+ </ul>
76
+ <% elsif message_id %>
77
+ <li>warning <a href="http://validator.w3.org/docs/errors.html#ve-<%= message_id %>"><%= message_id %></a>
78
+ found <%= warnings.length %> times</li>
79
+ <% end %>
53
80
  <% end %>
54
81
  </ul>
55
82
  <% end %>
@@ -59,24 +86,36 @@
59
86
  <h2>DETAILS PER PAGE</h2>
60
87
  <% processed_pages.each do |page| %>
61
88
  <div class='page'>
62
- <h3><%= page.url %></h3>
89
+ <h3><a href='<%= page.url %>'><%= page.url %></a></h3>
63
90
  <p class='page_summary'>
64
91
  <%= "#{page.errors.length} errors, #{page.warnings.length} warnings" %>
65
92
  </p>
66
93
 
67
94
  <ul class="page_errors">
68
- <% page.errors.each do |error| %>
95
+ <% page.errors.sort_by {|e| e.line.to_i}.each do |error| %>
69
96
  <li>
70
- Error <a href="http://validator.w3.org/docs/errors.html#ve-<%= error.message_id %>"><%= error.message_id %></a> on line <%= error.line %>:
97
+ <% if error.message_id == 'html5' %>
98
+ HTML5 error on line <%= error.line %>:
99
+ <% else %>
100
+ Error <a href="http://validator.w3.org/docs/errors.html#ve-<%= error.message_id %>"><%= error.message_id %></a>
101
+ on line <%= error.line %>:
102
+ <% end %>
103
+
71
104
  <%= error.text %>
72
105
  </li>
73
106
  <% end %>
74
107
  </ul>
75
108
 
76
109
  <ul class="page_warnings">
77
- <% page.warnings.each do |warning| %>
110
+ <% page.warnings.sort_by {|w| w.line.to_i}.each do |warning| %>
78
111
  <li>
79
- Warning <a href="http://validator.w3.org/docs/errors.html#ve-<%= warning.message_id %>"><%= warning.message_id %></a> on line <%= warning.line %>:
112
+ <% if warning.message_id == 'html5' %>
113
+ HTML5 warning on line <%= warning.line %>:
114
+ <% else %>
115
+ Warning <a href="http://validator.w3.org/docs/errors.html#ve-<%= warning.message_id %>"><%= warning.message_id %></a>
116
+ on line <%= warning.line %>:
117
+ <% end %>
118
+
80
119
  <%= warning.text %>
81
120
  </li>
82
121
  <% end %>
@@ -87,7 +126,8 @@
87
126
  </div>
88
127
 
89
128
  <div id="footer">
90
- <strong>w3clove</strong>@2011 <a href='http://jaimeiniesta.com'>Jaime Iniesta</a>. Get w3clove from <a href="http://github.com/jaimeiniesta/w3clove">github</a>.
129
+ <strong>w3clove</strong>@2011 <a href='http://jaimeiniesta.com'>Jaime Iniesta</a>.
130
+ Get w3clove from <a href="http://github.com/jaimeiniesta/w3clove">github</a>.
91
131
  </div>
92
132
  </body>
93
133
  </html>
@@ -1,5 +1,5 @@
1
1
  # -*- encoding: utf-8 -*-
2
2
 
3
3
  module W3Clove
4
- VERSION = "0.3.2"
4
+ VERSION = "0.3.3"
5
5
  end
data/spec/page_spec.rb CHANGED
@@ -5,7 +5,10 @@ require_relative 'spec_helper'
5
5
  describe W3Clove::Page do
6
6
  before(:each) do
7
7
  @page = W3Clove::Page.new('http://www.ryanair.com/es/')
8
- MarkupValidator.any_instance.stubs(:validate_uri).with('http://www.ryanair.com/es/').returns(stubbed_validator_results)
8
+ MarkupValidator.any_instance
9
+ .stubs(:validate_uri)
10
+ .with('http://www.ryanair.com/es/')
11
+ .returns(stubbed_validator_results)
9
12
  end
10
13
 
11
14
  it "should have an URL" do
@@ -19,7 +22,10 @@ describe W3Clove::Page do
19
22
 
20
23
  it "should be valid when it has no errors, even if it has warnings" do
21
24
  page = W3Clove::Page.new('http://example.com/no_errors_but_warnings')
22
- MarkupValidator.any_instance.stubs(:validate_uri).with('http://example.com/no_errors_but_warnings').returns(stubbed_validator_results(false))
25
+ MarkupValidator.any_instance
26
+ .stubs(:validate_uri)
27
+ .with('http://example.com/no_errors_but_warnings')
28
+ .returns(stubbed_validator_results(false))
23
29
  page.errors.should be_empty
24
30
  page.warnings.should_not be_empty
25
31
  page.should be_valid
@@ -27,7 +33,10 @@ describe W3Clove::Page do
27
33
 
28
34
  it "should not be valid if an exception happened when validating" do
29
35
  page = W3Clove::Page.new('http://example.com/timeout')
30
- MarkupValidator.any_instance.stubs(:validate_uri).with('http://example.com/timeout').raises(TimeoutError)
36
+ MarkupValidator.any_instance
37
+ .stubs(:validate_uri)
38
+ .with('http://example.com/timeout')
39
+ .raises(TimeoutError)
31
40
  page.errors.should be_nil
32
41
  page.should_not be_valid
33
42
  end
@@ -80,7 +89,10 @@ describe W3Clove::Page do
80
89
 
81
90
  it "should recover from timeouts when checking for errors" do
82
91
  page = W3Clove::Page.new('http://example.com/timeout')
83
- MarkupValidator.any_instance.stubs(:validate_uri).with('http://example.com/timeout').raises(TimeoutError)
92
+ MarkupValidator.any_instance
93
+ .stubs(:validate_uri)
94
+ .with('http://example.com/timeout')
95
+ .raises(TimeoutError)
84
96
  lambda { page.errors }.should_not raise_error
85
97
  page.errors.should be_nil
86
98
  page.exception.should == 'Timeout::Error'
@@ -88,10 +100,41 @@ describe W3Clove::Page do
88
100
 
89
101
  it "should recover from timeouts when checking for warnings" do
90
102
  page = W3Clove::Page.new('http://example.com/timeout')
91
- MarkupValidator.any_instance.stubs(:validate_uri).with('http://example.com/timeout').raises(TimeoutError)
103
+ MarkupValidator.any_instance
104
+ .stubs(:validate_uri)
105
+ .with('http://example.com/timeout')
106
+ .raises(TimeoutError)
92
107
  lambda { page.warnings }.should_not raise_error
93
108
  page.warnings.should be_nil
94
109
  page.exception.should == 'Timeout::Error'
95
110
  end
111
+
112
+ it "should not record empty errors returned by the validator" do
113
+ mocked_validator = W3Clove::MockedValidator.new
114
+ mocked_validator.add_error('25', '92', message_text('25'))
115
+ mocked_validator.add_error('', '', '')
116
+ mocked_validator.add_error(nil, nil, nil)
117
+ MarkupValidator.any_instance
118
+ .stubs(:validate_uri)
119
+ .with('http://example.com/emptyerrors')
120
+ .returns(mocked_validator)
121
+ page = W3Clove::Page.new('http://example.com/emptyerrors')
122
+ page.errors.length.should == 1
123
+ page.errors.first.message_id.should == '25'
124
+ end
125
+
126
+ it "should not record empty warnings returned by the validator" do
127
+ mocked_validator = W3Clove::MockedValidator.new
128
+ mocked_validator.add_warning('25', '92', message_text('25'))
129
+ mocked_validator.add_warning('', '', '')
130
+ mocked_validator.add_warning(nil, nil, nil)
131
+ MarkupValidator.any_instance
132
+ .stubs(:validate_uri)
133
+ .with('http://example.com/emptyerrors')
134
+ .returns(mocked_validator)
135
+ page = W3Clove::Page.new('http://example.com/emptyerrors')
136
+ page.warnings.length.should == 1
137
+ page.warnings.first.message_id.should == '25'
138
+ end
96
139
  end
97
140
 
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 3
8
- - 2
9
- version: 0.3.2
8
+ - 3
9
+ version: 0.3.3
10
10
  platform: ruby
11
11
  authors:
12
12
  - Jaime Iniesta
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2011-03-24 00:00:00 +01:00
17
+ date: 2011-03-25 00:00:00 +01:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency