w3clove 0.0.1 → 0.0.2
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.
- data/README.rdoc +17 -1
- data/bin/w3clove +1 -1
- data/lib/w3clove/message.rb +15 -0
- data/lib/w3clove/page.rb +56 -0
- data/lib/w3clove/sitemap.rb +43 -0
- data/lib/w3clove/validator.rb +94 -0
- data/lib/w3clove/version.rb +4 -2
- data/lib/w3clove.rb +6 -25
- data/spec/message_spec.rb +33 -0
- data/spec/mocks/mocked_validator.rb +19 -0
- data/spec/page_spec.rb +97 -0
- data/spec/samples/sitemap.xml +18 -0
- data/spec/sitemap_spec.rb +38 -0
- data/spec/spec_helper.rb +36 -0
- data/w3clove.gemspec +6 -2
- metadata +50 -14
- data/heatup/01_single_validation.rb +0 -16
- data/heatup/02_multiple_validation.rb +0 -25
- data/heatup/03_multiple_validation_from_text_file.rb +0 -23
- data/heatup/04_multiple_validations_from_xml_file.rb +0 -24
- data/heatup/05_multiple_validations_from_remote_xml_sitemap.rb +0 -25
- data/heatup/sitemap.xml +0 -12
- data/heatup/urls.txt +0 -3
data/README.rdoc
CHANGED
@@ -16,4 +16,20 @@ I've already done something similar to this, I sent {a little contribution to do
|
|
16
16
|
|
17
17
|
* in addition to an XML file, accept as input the URL of a site and crawl the site to find all internal links
|
18
18
|
* validate the markup locally, without querying the W3C site, for more speed and to not saturate the W3C site
|
19
|
-
* store the results on a local database, so on subsequent checks, only the pages that had errors are re-checked (unless a --checkall force flag is passed). This way developers can check the whole site, get the errors, deploy the corrections, and recheck the site.
|
19
|
+
* store the results on a local database, so on subsequent checks, only the pages that had errors are re-checked (unless a --checkall force flag is passed). This way developers can check the whole site, get the errors, deploy the corrections, and recheck the site.
|
20
|
+
|
21
|
+
= Installation:
|
22
|
+
|
23
|
+
w3clove is a Ruby gem that can be installed on the usual way
|
24
|
+
|
25
|
+
gem install w3clove
|
26
|
+
|
27
|
+
= Usage:
|
28
|
+
|
29
|
+
Pass it the url of an XML sitemap to be checked, like:
|
30
|
+
|
31
|
+
w3clove http://www.ryanair.com/sitemap.xml
|
32
|
+
|
33
|
+
= Notes:
|
34
|
+
|
35
|
+
This gem requires Ruby 1.9, and has been tested on Ruby 1.9.2
|
data/bin/w3clove
CHANGED
@@ -0,0 +1,15 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
module W3Clove
|
4
|
+
##
|
5
|
+
# A message holds a message_id, a line, a text and a type
|
6
|
+
#
|
7
|
+
# message_id... corresponds to the W3C messages list from
|
8
|
+
# http://validator.w3.org/docs/errors.html
|
9
|
+
# line......... line number where the error was detected
|
10
|
+
# on the page that created it
|
11
|
+
# text......... generic but descriptive text about the error
|
12
|
+
# type......... can be :error or :warning
|
13
|
+
#
|
14
|
+
Message = Struct.new(:message_id, :line, :text, :type)
|
15
|
+
end
|
data/lib/w3clove/page.rb
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
require 'w3c_validators'
|
4
|
+
include W3CValidators
|
5
|
+
|
6
|
+
module W3Clove
|
7
|
+
##
|
8
|
+
# A page has an URL to be validated, and a collection of errors
|
9
|
+
# In case of an exception happens when validating, it is tracked
|
10
|
+
#
|
11
|
+
class Page
|
12
|
+
attr_accessor :url, :exception
|
13
|
+
|
14
|
+
def initialize(url)
|
15
|
+
@url = url
|
16
|
+
end
|
17
|
+
|
18
|
+
##
|
19
|
+
# Checks for errors and returns true if none found, false otherwise
|
20
|
+
# warnings are not considered as validation errors so a page with
|
21
|
+
# warnings but without errors will return true
|
22
|
+
# If the validation goes well, errors should be an array. Otherwise
|
23
|
+
# it will still be nil, which will not be considered validated
|
24
|
+
def valid?
|
25
|
+
!errors.nil? && errors.empty?
|
26
|
+
end
|
27
|
+
|
28
|
+
def errors
|
29
|
+
@errors ||= validations.errors.map {|e|
|
30
|
+
W3Clove::Message.new(e.message_id,
|
31
|
+
e.line,
|
32
|
+
e.message,
|
33
|
+
:error)}
|
34
|
+
rescue Exception => e
|
35
|
+
@exception = e.to_s
|
36
|
+
nil
|
37
|
+
end
|
38
|
+
|
39
|
+
def warnings
|
40
|
+
@warnings ||= validations.warnings.map {|w|
|
41
|
+
W3Clove::Message.new(w.message_id,
|
42
|
+
w.line,
|
43
|
+
w.message,
|
44
|
+
:warning)}
|
45
|
+
rescue Exception => e
|
46
|
+
@exception = e.to_s
|
47
|
+
nil
|
48
|
+
end
|
49
|
+
|
50
|
+
private
|
51
|
+
|
52
|
+
def validations
|
53
|
+
@validations ||= MarkupValidator.new.validate_uri(url)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
require 'open-uri'
|
4
|
+
require 'nokogiri'
|
5
|
+
|
6
|
+
module W3Clove
|
7
|
+
##
|
8
|
+
# A sitemap has an URL, and holds a collection of pages to be validated
|
9
|
+
#
|
10
|
+
class Sitemap
|
11
|
+
attr_accessor :url
|
12
|
+
|
13
|
+
def initialize(url)
|
14
|
+
@url = url
|
15
|
+
end
|
16
|
+
|
17
|
+
def pages
|
18
|
+
@pages ||= pages_in_sitemap.uniq {|p| p.url}
|
19
|
+
end
|
20
|
+
|
21
|
+
def errors
|
22
|
+
pages.map {|p| p.errors}.flatten
|
23
|
+
end
|
24
|
+
|
25
|
+
def warnings
|
26
|
+
pages.map {|p| p.warnings}.flatten
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
def pages_in_sitemap
|
32
|
+
locations.map {|loc| W3Clove::Page.new(loc.text)}
|
33
|
+
end
|
34
|
+
|
35
|
+
def locations
|
36
|
+
Nokogiri::XML(doc).css('loc')
|
37
|
+
end
|
38
|
+
|
39
|
+
def doc
|
40
|
+
@doc ||= open(url)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,94 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
module W3Clove
|
4
|
+
##
|
5
|
+
# Validator module is the one in charge of doing the validation loop
|
6
|
+
# for all pages on a sitemap and output the errors
|
7
|
+
#
|
8
|
+
module Validator
|
9
|
+
attr_writer :printer
|
10
|
+
|
11
|
+
extend self
|
12
|
+
|
13
|
+
##
|
14
|
+
# Parses a remote xml sitemap and checks markup validation for each url
|
15
|
+
# Shows progress on dot-style (...F...FFE..). A dot is a page with no errors,
|
16
|
+
# an F is a page with errors, and an E is an exception
|
17
|
+
# After the checking is done, a detailed summary is shown
|
18
|
+
def check(url)
|
19
|
+
sitemap = W3Clove::Sitemap.new(url)
|
20
|
+
say "Validating #{sitemap.pages.length} pages..."
|
21
|
+
|
22
|
+
sitemap.pages.each do |page|
|
23
|
+
say_inline page.valid? ? "." : (page.errors.nil? ? 'E' : 'F')
|
24
|
+
end
|
25
|
+
|
26
|
+
show_results(sitemap)
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
##
|
32
|
+
# Outputs the results of the validation
|
33
|
+
def show_results(sitemap)
|
34
|
+
show_sitemap_summary(sitemap)
|
35
|
+
show_popular_errors(sitemap)
|
36
|
+
show_popular_errors(sitemap)
|
37
|
+
say "\n\nDETAILS PER PAGE"
|
38
|
+
sitemap.pages.select {|page| !page.errors.empty?}.each do |p|
|
39
|
+
show_page_summary(p)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def show_sitemap_summary(sitemap)
|
44
|
+
<<HEREDOC
|
45
|
+
SITEMAP SUMMARY
|
46
|
+
TOTAL: #{sitemap.errors.length} errors, #{sitemap.warnings.length} warnings
|
47
|
+
HEREDOC
|
48
|
+
end
|
49
|
+
|
50
|
+
def show_popular_errors(sitemap)
|
51
|
+
say "\n\nMOST POPULAR ERRORS\n"
|
52
|
+
sitemap.errors.group_by {|e| e.message_id}.sort_by {|m,e| e.length}.reverse.each do |message_id, errors|
|
53
|
+
say "error #{message_id} happens #{errors.length} times"
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def show_popular_warnings(sitemap)
|
58
|
+
say "\n\nMOST POPULAR WARNINGS\n"
|
59
|
+
sitemap.warnings.group_by {|e| e.message_id}.sort_by {|m,e| e.length}.reverse.each do |message_id, warnings|
|
60
|
+
say "warning #{message_id} happens #{warnings.length} times"
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
def show_page_summary(page)
|
65
|
+
say "\n ** #{page.url} **"
|
66
|
+
" #{page.errors.length} errors, #{page.warnings.length} warnings"
|
67
|
+
page.errors.each do |error|
|
68
|
+
say "\n Error #{error.message_id} on line #{error.line}:"
|
69
|
+
say " #{error.text}"
|
70
|
+
end
|
71
|
+
|
72
|
+
page.warnings.each do |warning|
|
73
|
+
say "\n Warning #{warning.message_id} on line #{warning.line}:"
|
74
|
+
say " #{warning.text}"
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
def printer
|
79
|
+
@printer ||= STDOUT
|
80
|
+
end
|
81
|
+
|
82
|
+
##
|
83
|
+
# A shorter alias for printer.puts
|
84
|
+
def say(text)
|
85
|
+
printer.puts text
|
86
|
+
end
|
87
|
+
|
88
|
+
##
|
89
|
+
# A shorter alias for printer.print
|
90
|
+
def say_inline(text)
|
91
|
+
printer.print text
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
data/lib/w3clove/version.rb
CHANGED
data/lib/w3clove.rb
CHANGED
@@ -1,27 +1,8 @@
|
|
1
|
-
|
2
|
-
require 'open-uri'
|
3
|
-
require 'nokogiri'
|
4
|
-
require 'w3c_validators'
|
5
|
-
include W3CValidators
|
1
|
+
# -*- encoding: utf-8 -*-
|
6
2
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
validator = MarkupValidator.new
|
13
|
-
|
14
|
-
totals = {:errors => 0, :warnings => 0}
|
15
|
-
|
16
|
-
doc = Nokogiri::XML(open(sitemap_url))
|
17
|
-
doc.css('loc').collect {|item| item.text}.each do |url|
|
18
|
-
puts "\nValidating markup of #{url}"
|
19
|
-
results = validator.validate_uri(url)
|
20
|
-
puts "#{results.errors.count} errors, #{results.warnings.count} warnings"
|
21
|
-
totals[:errors] += results.errors.count
|
22
|
-
totals[:warnings] += results.warnings.count
|
23
|
-
end
|
24
|
-
|
25
|
-
puts "\nTOTAL:#{totals[:errors]} errors, #{totals[:warnings]} warnings"
|
26
|
-
end
|
3
|
+
module W3Clove
|
4
|
+
require_relative './w3clove/validator'
|
5
|
+
require_relative './w3clove/sitemap'
|
6
|
+
require_relative './w3clove/page'
|
7
|
+
require_relative './w3clove/message'
|
27
8
|
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
require_relative 'spec_helper'
|
4
|
+
|
5
|
+
describe W3Clove::Message do
|
6
|
+
before(:each) do
|
7
|
+
@error_message = W3Clove::Message.new('25',
|
8
|
+
100,
|
9
|
+
message_text('25'),
|
10
|
+
:error)
|
11
|
+
@warning_message = W3Clove::Message.new('25',
|
12
|
+
100,
|
13
|
+
message_text('25'),
|
14
|
+
:warning)
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should have a message_id" do
|
18
|
+
@error_message.message_id.should == '25'
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should have a line" do
|
22
|
+
@error_message.line.should == 100
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should have a text" do
|
26
|
+
@error_message.text.should == message_text('25')
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should have a type" do
|
30
|
+
@error_message.type == :error
|
31
|
+
@warning_message.type == :warning
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module W3Clove
|
2
|
+
class MockedValidator
|
3
|
+
attr_accessor :errors, :warnings
|
4
|
+
|
5
|
+
def initialize
|
6
|
+
@errors, @warnings = [], []
|
7
|
+
end
|
8
|
+
|
9
|
+
def add_error(message_id, line, message)
|
10
|
+
@errors << W3Clove::MockedMessage.new(message_id, line, message)
|
11
|
+
end
|
12
|
+
|
13
|
+
def add_warning(message_id, line, message)
|
14
|
+
@warnings << W3Clove::MockedMessage.new(message_id, line, message)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
MockedMessage = Struct.new(:message_id, :line, :message)
|
19
|
+
end
|
data/spec/page_spec.rb
ADDED
@@ -0,0 +1,97 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
require_relative 'spec_helper'
|
4
|
+
|
5
|
+
describe W3Clove::Page do
|
6
|
+
before(:each) do
|
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)
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should have an URL" do
|
12
|
+
@page.url.should == "http://www.ryanair.com/es/"
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should be valid when it has no errors" do
|
16
|
+
@page.errors.should_not be_empty
|
17
|
+
@page.should_not be_valid
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should be valid when it has no errors, even if it has warnings" do
|
21
|
+
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))
|
23
|
+
page.errors.should be_empty
|
24
|
+
page.warnings.should_not be_empty
|
25
|
+
page.should be_valid
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should not be valid if an exception happened when validating" do
|
29
|
+
page = W3Clove::Page.new('http://example.com/timeout')
|
30
|
+
MarkupValidator.any_instance.stubs(:validate_uri).with('http://example.com/timeout').raises(TimeoutError)
|
31
|
+
page.errors.should be_nil
|
32
|
+
page.should_not be_valid
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should get its validation errors from the W3C" do
|
36
|
+
@page.errors.length.should == 3
|
37
|
+
|
38
|
+
@page.errors.each do |e|
|
39
|
+
e.should be_an_instance_of W3Clove::Message
|
40
|
+
end
|
41
|
+
|
42
|
+
@page.errors[0].message_id.should == '25'
|
43
|
+
@page.errors[0].line.should == '92'
|
44
|
+
@page.errors[0].text.should == message_text('25')
|
45
|
+
@page.errors[0].type.should == :error
|
46
|
+
|
47
|
+
@page.errors[1].message_id.should == '325'
|
48
|
+
@page.errors[1].line.should == '92'
|
49
|
+
@page.errors[1].text.should == message_text('325')
|
50
|
+
@page.errors[1].type.should == :error
|
51
|
+
|
52
|
+
@page.errors[2].message_id.should == '325'
|
53
|
+
@page.errors[2].line.should == '224'
|
54
|
+
@page.errors[2].text.should == message_text('325')
|
55
|
+
@page.errors[2].type.should == :error
|
56
|
+
end
|
57
|
+
|
58
|
+
it "should get its validation warnings from the W3C" do
|
59
|
+
@page.warnings.length.should == 3
|
60
|
+
|
61
|
+
@page.warnings.each do |w|
|
62
|
+
w.should be_an_instance_of W3Clove::Message
|
63
|
+
end
|
64
|
+
|
65
|
+
@page.warnings[0].message_id.should == '338'
|
66
|
+
@page.warnings[0].line.should == '92'
|
67
|
+
@page.warnings[0].text.should == message_text('338')
|
68
|
+
@page.warnings[0].type.should == :warning
|
69
|
+
|
70
|
+
@page.warnings[1].message_id.should == '247'
|
71
|
+
@page.warnings[1].line.should == '112'
|
72
|
+
@page.warnings[1].text.should == message_text('247')
|
73
|
+
@page.warnings[1].type.should == :warning
|
74
|
+
|
75
|
+
@page.warnings[2].message_id.should == '247'
|
76
|
+
@page.warnings[2].line.should == '202'
|
77
|
+
@page.warnings[2].text.should == message_text('247')
|
78
|
+
@page.warnings[2].type.should == :warning
|
79
|
+
end
|
80
|
+
|
81
|
+
it "should recover from timeouts when checking for errors" do
|
82
|
+
page = W3Clove::Page.new('http://example.com/timeout')
|
83
|
+
MarkupValidator.any_instance.stubs(:validate_uri).with('http://example.com/timeout').raises(TimeoutError)
|
84
|
+
lambda { page.errors }.should_not raise_error
|
85
|
+
page.errors.should be_nil
|
86
|
+
page.exception.should == 'Timeout::Error'
|
87
|
+
end
|
88
|
+
|
89
|
+
it "should recover from timeouts when checking for warnings" do
|
90
|
+
page = W3Clove::Page.new('http://example.com/timeout')
|
91
|
+
MarkupValidator.any_instance.stubs(:validate_uri).with('http://example.com/timeout').raises(TimeoutError)
|
92
|
+
lambda { page.warnings }.should_not raise_error
|
93
|
+
page.warnings.should be_nil
|
94
|
+
page.exception.should == 'Timeout::Error'
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
@@ -0,0 +1,18 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
|
3
|
+
<url>
|
4
|
+
<loc>http://www.ryanair.com/es/</loc>
|
5
|
+
</url>
|
6
|
+
<url>
|
7
|
+
<loc>http://www.ryanair.com/es/careers/job</loc>
|
8
|
+
</url>
|
9
|
+
<url>
|
10
|
+
<loc>http://www.ryanair.com/es/about</loc>
|
11
|
+
</url>
|
12
|
+
<url>
|
13
|
+
<loc>http://www.ryanair.com/es/about</loc>
|
14
|
+
</url>
|
15
|
+
<url>
|
16
|
+
<loc>http://www.ryanair.com/es/about</loc>
|
17
|
+
</url>
|
18
|
+
</urlset>
|
@@ -0,0 +1,38 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
require_relative 'spec_helper'
|
4
|
+
|
5
|
+
describe W3Clove::Sitemap do
|
6
|
+
before(:each) do
|
7
|
+
@sitemap = W3Clove::Sitemap.new('http://ryanair.com/sitemap.xml')
|
8
|
+
@sitemap.stub!(:doc).and_return(open("#{$samples_dir}/sitemap.xml"))
|
9
|
+
MarkupValidator.any_instance.stubs(:validate_uri).returns(stubbed_validator_results)
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should have an URL" do
|
13
|
+
@sitemap.url.should == 'http://ryanair.com/sitemap.xml'
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should get its pages from the xml, removing repeated urls" do
|
17
|
+
@sitemap.pages.length.should == 3
|
18
|
+
@sitemap.pages[0].url.should == 'http://www.ryanair.com/es/'
|
19
|
+
@sitemap.pages[1].url.should == 'http://www.ryanair.com/es/careers/job'
|
20
|
+
@sitemap.pages[2].url.should == 'http://www.ryanair.com/es/about'
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should know the errors of all of its pages as a whole" do
|
24
|
+
@sitemap.errors.length.should == 9
|
25
|
+
@sitemap.errors.each do |e|
|
26
|
+
e.should be_an_instance_of W3Clove::Message
|
27
|
+
e.type.should == :error
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should know the warnings of all of its pages as a whole" do
|
32
|
+
@sitemap.warnings.length.should == 9
|
33
|
+
@sitemap.warnings.each do |w|
|
34
|
+
w.should be_an_instance_of W3Clove::Message
|
35
|
+
w.type.should == :warning
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
require_relative '../lib/w3clove'
|
4
|
+
require_relative './mocks/mocked_validator'
|
5
|
+
require 'mocha'
|
6
|
+
|
7
|
+
$samples_dir = File.dirname(__FILE__) + '/samples'
|
8
|
+
|
9
|
+
def message_text(message_id)
|
10
|
+
message_texts = {
|
11
|
+
'25' => 'general entity "B" not defined and no default entity',
|
12
|
+
'325' => 'reference to entity "B" for which no system identifier could be generated',
|
13
|
+
'65' => 'document type does not allow element "P" here; missing one of "APPLET", "OBJECT", "MAP", "IFRAME", "BUTTON" start-tag',
|
14
|
+
'338' => 'cannot generate system identifier for general entity "B"',
|
15
|
+
'247' => 'NET-enabling start-tag requires SHORTTAG YES'
|
16
|
+
}
|
17
|
+
message_texts[message_id]
|
18
|
+
end
|
19
|
+
|
20
|
+
def stubbed_validator_results(with_errors=true, with_warnings=true)
|
21
|
+
fake_validator = W3Clove::MockedValidator.new
|
22
|
+
|
23
|
+
if with_errors
|
24
|
+
fake_validator.add_error('25', '92', message_text('25'))
|
25
|
+
fake_validator.add_error('325', '92', message_text('325'))
|
26
|
+
fake_validator.add_error('325', '224', message_text('325'))
|
27
|
+
end
|
28
|
+
|
29
|
+
if with_warnings
|
30
|
+
fake_validator.add_warning('338', '92', message_text('338'))
|
31
|
+
fake_validator.add_warning('247', '112', message_text('247'))
|
32
|
+
fake_validator.add_warning('247', '202', message_text('247'))
|
33
|
+
end
|
34
|
+
|
35
|
+
fake_validator
|
36
|
+
end
|
data/w3clove.gemspec
CHANGED
@@ -1,10 +1,11 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
|
+
|
2
3
|
$:.push File.expand_path("../lib", __FILE__)
|
3
4
|
require "w3clove/version"
|
4
5
|
|
5
6
|
Gem::Specification.new do |s|
|
6
7
|
s.name = "w3clove"
|
7
|
-
s.version =
|
8
|
+
s.version = W3Clove::VERSION
|
8
9
|
s.platform = Gem::Platform::RUBY
|
9
10
|
s.authors = ["Jaime Iniesta"]
|
10
11
|
s.email = ["jaimeiniesta@gmail.com"]
|
@@ -15,9 +16,12 @@ and outputs a detailed report with all errors and warnings }
|
|
15
16
|
|
16
17
|
s.rubyforge_project = "w3clove"
|
17
18
|
|
18
|
-
s.add_dependency 'w3c_validators'
|
19
|
+
s.add_dependency 'w3c_validators', '1.0.2'
|
19
20
|
s.add_dependency 'nokogiri'
|
20
21
|
|
22
|
+
s.add_development_dependency 'rspec'
|
23
|
+
s.add_development_dependency 'mocha'
|
24
|
+
|
21
25
|
s.files = `git ls-files`.split("\n")
|
22
26
|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
23
27
|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
version: 0.0.
|
8
|
+
- 2
|
9
|
+
version: 0.0.2
|
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-
|
17
|
+
date: 2011-03-22 00:00:00 +01:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -23,11 +23,13 @@ dependencies:
|
|
23
23
|
requirement: &id001 !ruby/object:Gem::Requirement
|
24
24
|
none: false
|
25
25
|
requirements:
|
26
|
-
- - "
|
26
|
+
- - "="
|
27
27
|
- !ruby/object:Gem::Version
|
28
28
|
segments:
|
29
|
+
- 1
|
29
30
|
- 0
|
30
|
-
|
31
|
+
- 2
|
32
|
+
version: 1.0.2
|
31
33
|
type: :runtime
|
32
34
|
version_requirements: *id001
|
33
35
|
- !ruby/object:Gem::Dependency
|
@@ -43,6 +45,32 @@ dependencies:
|
|
43
45
|
version: "0"
|
44
46
|
type: :runtime
|
45
47
|
version_requirements: *id002
|
48
|
+
- !ruby/object:Gem::Dependency
|
49
|
+
name: rspec
|
50
|
+
prerelease: false
|
51
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
52
|
+
none: false
|
53
|
+
requirements:
|
54
|
+
- - ">="
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
segments:
|
57
|
+
- 0
|
58
|
+
version: "0"
|
59
|
+
type: :development
|
60
|
+
version_requirements: *id003
|
61
|
+
- !ruby/object:Gem::Dependency
|
62
|
+
name: mocha
|
63
|
+
prerelease: false
|
64
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ">="
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
segments:
|
70
|
+
- 0
|
71
|
+
version: "0"
|
72
|
+
type: :development
|
73
|
+
version_requirements: *id004
|
46
74
|
description: " this tool allows you to check the markup validation of a whole site passing an XML sitemap,\n\
|
47
75
|
and outputs a detailed report with all errors and warnings "
|
48
76
|
email:
|
@@ -59,15 +87,18 @@ files:
|
|
59
87
|
- README.rdoc
|
60
88
|
- Rakefile
|
61
89
|
- bin/w3clove
|
62
|
-
- heatup/01_single_validation.rb
|
63
|
-
- heatup/02_multiple_validation.rb
|
64
|
-
- heatup/03_multiple_validation_from_text_file.rb
|
65
|
-
- heatup/04_multiple_validations_from_xml_file.rb
|
66
|
-
- heatup/05_multiple_validations_from_remote_xml_sitemap.rb
|
67
|
-
- heatup/sitemap.xml
|
68
|
-
- heatup/urls.txt
|
69
90
|
- lib/w3clove.rb
|
91
|
+
- lib/w3clove/message.rb
|
92
|
+
- lib/w3clove/page.rb
|
93
|
+
- lib/w3clove/sitemap.rb
|
94
|
+
- lib/w3clove/validator.rb
|
70
95
|
- lib/w3clove/version.rb
|
96
|
+
- spec/message_spec.rb
|
97
|
+
- spec/mocks/mocked_validator.rb
|
98
|
+
- spec/page_spec.rb
|
99
|
+
- spec/samples/sitemap.xml
|
100
|
+
- spec/sitemap_spec.rb
|
101
|
+
- spec/spec_helper.rb
|
71
102
|
- w3clove.gemspec
|
72
103
|
has_rdoc: true
|
73
104
|
homepage: https://github.com/jaimeiniesta/w3clove/
|
@@ -101,5 +132,10 @@ rubygems_version: 1.3.7
|
|
101
132
|
signing_key:
|
102
133
|
specification_version: 3
|
103
134
|
summary: command-line tool to validate the markup of a whole site against the W3C validator
|
104
|
-
test_files:
|
105
|
-
|
135
|
+
test_files:
|
136
|
+
- spec/message_spec.rb
|
137
|
+
- spec/mocks/mocked_validator.rb
|
138
|
+
- spec/page_spec.rb
|
139
|
+
- spec/samples/sitemap.xml
|
140
|
+
- spec/sitemap_spec.rb
|
141
|
+
- spec/spec_helper.rb
|
@@ -1,16 +0,0 @@
|
|
1
|
-
# Example of validation of a single URL
|
2
|
-
|
3
|
-
require 'w3c_validators'
|
4
|
-
include W3CValidators
|
5
|
-
validator = MarkupValidator.new
|
6
|
-
|
7
|
-
url = 'http://university.rubymendicant.com/'
|
8
|
-
puts "Validating markup of #{url}"
|
9
|
-
|
10
|
-
results = validator.validate_uri(url)
|
11
|
-
|
12
|
-
if results.errors.length > 0
|
13
|
-
puts "There are #{results.errors.length} validation errors"
|
14
|
-
else
|
15
|
-
puts 'Valid!'
|
16
|
-
end
|
@@ -1,25 +0,0 @@
|
|
1
|
-
# Example of validation of a list of URLs
|
2
|
-
|
3
|
-
require 'w3c_validators'
|
4
|
-
include W3CValidators
|
5
|
-
validator = MarkupValidator.new
|
6
|
-
|
7
|
-
urls = %w{http://university.rubymendicant.com/
|
8
|
-
http://university.rubymendicant.com/changelog.html
|
9
|
-
http://university.rubymendicant.com/alumni.html}
|
10
|
-
totals = {:errors => 0, :warnings => 0}
|
11
|
-
|
12
|
-
urls.each do |url|
|
13
|
-
puts "\nValidating markup of #{url}"
|
14
|
-
results = validator.validate_uri(url)
|
15
|
-
puts "#{results.errors.count} errors, #{results.warnings.count} warnings"
|
16
|
-
totals[:errors] += results.errors.count
|
17
|
-
totals[:warnings] += results.warnings.count
|
18
|
-
end
|
19
|
-
|
20
|
-
puts "\nTOTAL:#{totals[:errors]} errors, #{totals[:warnings]} warnings"
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
@@ -1,23 +0,0 @@
|
|
1
|
-
# Example of validation of a list of URLs from a text file
|
2
|
-
|
3
|
-
require 'w3c_validators'
|
4
|
-
include W3CValidators
|
5
|
-
validator = MarkupValidator.new
|
6
|
-
|
7
|
-
totals = {:errors => 0, :warnings => 0}
|
8
|
-
File.open("urls.txt", "r") do |file|
|
9
|
-
file.each_line do |url|
|
10
|
-
puts "\nValidating markup of #{url}"
|
11
|
-
results = validator.validate_uri(url)
|
12
|
-
puts "#{results.errors.count} errors, #{results.warnings.count} warnings"
|
13
|
-
totals[:errors] += results.errors.count
|
14
|
-
totals[:warnings] += results.warnings.count
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
puts "\nTOTAL:#{totals[:errors]} errors, #{totals[:warnings]} warnings"
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
@@ -1,24 +0,0 @@
|
|
1
|
-
# Example of validation of a list of URLs from a local XML sitemap file
|
2
|
-
|
3
|
-
require 'nokogiri'
|
4
|
-
require 'w3c_validators'
|
5
|
-
include W3CValidators
|
6
|
-
validator = MarkupValidator.new
|
7
|
-
|
8
|
-
totals = {:errors => 0, :warnings => 0}
|
9
|
-
|
10
|
-
doc = Nokogiri::XML(File.open("sitemap.xml"))
|
11
|
-
doc.css('loc').collect {|item| item.text}.each do |url|
|
12
|
-
puts "\nValidating markup of #{url}"
|
13
|
-
results = validator.validate_uri(url)
|
14
|
-
puts "#{results.errors.count} errors, #{results.warnings.count} warnings"
|
15
|
-
totals[:errors] += results.errors.count
|
16
|
-
totals[:warnings] += results.warnings.count
|
17
|
-
end
|
18
|
-
|
19
|
-
puts "\nTOTAL:#{totals[:errors]} errors, #{totals[:warnings]} warnings"
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
@@ -1,25 +0,0 @@
|
|
1
|
-
# Example of validation of a list of URLs from a remote XML sitemap
|
2
|
-
|
3
|
-
require 'open-uri'
|
4
|
-
require 'nokogiri'
|
5
|
-
require 'w3c_validators'
|
6
|
-
include W3CValidators
|
7
|
-
validator = MarkupValidator.new
|
8
|
-
|
9
|
-
totals = {:errors => 0, :warnings => 0}
|
10
|
-
|
11
|
-
doc = Nokogiri::XML(open('https://github.com/jaimeiniesta/w3clove/raw/master/heatup/sitemap.xml'))
|
12
|
-
doc.css('loc').collect {|item| item.text}.each do |url|
|
13
|
-
puts "\nValidating markup of #{url}"
|
14
|
-
results = validator.validate_uri(url)
|
15
|
-
puts "#{results.errors.count} errors, #{results.warnings.count} warnings"
|
16
|
-
totals[:errors] += results.errors.count
|
17
|
-
totals[:warnings] += results.warnings.count
|
18
|
-
end
|
19
|
-
|
20
|
-
puts "\nTOTAL:#{totals[:errors]} errors, #{totals[:warnings]} warnings"
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
data/heatup/sitemap.xml
DELETED
@@ -1,12 +0,0 @@
|
|
1
|
-
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
-
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
|
3
|
-
<url>
|
4
|
-
<loc>http://university.rubymendicant.com/</loc>
|
5
|
-
</url>
|
6
|
-
<url>
|
7
|
-
<loc>http://university.rubymendicant.com/changelog.html</loc>
|
8
|
-
</url>
|
9
|
-
<url>
|
10
|
-
<loc>http://university.rubymendicant.com/alumni.html</loc>
|
11
|
-
</url>
|
12
|
-
</url>
|
data/heatup/urls.txt
DELETED