pleasevalidate 0.0.3
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/History.txt +16 -0
- data/LICENSE +22 -0
- data/Manifest.txt +23 -0
- data/PostInstall.txt +2 -0
- data/README.rdoc +104 -0
- data/RakeFile +32 -0
- data/bin/pleasevalidate +8 -0
- data/cucumber.yml +1 -0
- data/features/cli_validation.feature +9 -0
- data/features/file_types.feature +16 -0
- data/features/request.feature +9 -0
- data/features/steps/cli_validation_steps.rb +14 -0
- data/features/steps/file_types_steps.rb +24 -0
- data/features/steps/helper.rb +3 -0
- data/features/steps/request_steps.rb +14 -0
- data/features/steps/validate_multiple_files_steps.rb +29 -0
- data/features/steps/validate_steps.rb +37 -0
- data/features/validate.feature +17 -0
- data/features/validate_multiple_files.feature +15 -0
- data/lib/please_validate.rb +13 -0
- data/lib/please_validate/cli.rb +74 -0
- data/lib/please_validate/request.rb +39 -0
- data/lib/please_validate/validator.rb +70 -0
- metadata +129 -0
data/History.txt
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
== 0.0.1 2009-03-09
|
2
|
+
|
3
|
+
* 1 major enhancement:
|
4
|
+
* Initial release
|
5
|
+
|
6
|
+
== 0.0.2 2009-14-09
|
7
|
+
|
8
|
+
* 1 major enhancement:
|
9
|
+
* Multiple files validated
|
10
|
+
* 1 minor enhancement:
|
11
|
+
* Mime type checked to only allow html files to be validated
|
12
|
+
|
13
|
+
== 0.0.3 2009-16-09
|
14
|
+
|
15
|
+
* 1 major enhancement:
|
16
|
+
* Directories can be passed as arguments and recursively scanned for HTML files for validation
|
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
(The MIT License)
|
2
|
+
|
3
|
+
Copyright (c) 2009 Dylan Fogarty-MacDonald
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Manifest.txt
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
History.txt
|
2
|
+
LICENSE
|
3
|
+
Manifest.txt
|
4
|
+
PostInstall.txt
|
5
|
+
README.rdoc
|
6
|
+
RakeFile
|
7
|
+
bin/pleasevalidate
|
8
|
+
cucumber.yml
|
9
|
+
features/cli_validation.feature
|
10
|
+
features/file_types.feature
|
11
|
+
features/request.feature
|
12
|
+
features/steps/cli_validation_steps.rb
|
13
|
+
features/steps/file_types_steps.rb
|
14
|
+
features/steps/helper.rb
|
15
|
+
features/steps/request_steps.rb
|
16
|
+
features/steps/validate_multiple_files_steps.rb
|
17
|
+
features/steps/validate_steps.rb
|
18
|
+
features/validate.feature
|
19
|
+
features/validate_multiple_files.feature
|
20
|
+
lib/please_validate.rb
|
21
|
+
lib/please_validate/cli.rb
|
22
|
+
lib/please_validate/request.rb
|
23
|
+
lib/please_validate/validator.rb
|
data/PostInstall.txt
ADDED
data/README.rdoc
ADDED
@@ -0,0 +1,104 @@
|
|
1
|
+
= Please Validate
|
2
|
+
|
3
|
+
http://github.com/DylanFM/please_validate/tree
|
4
|
+
|
5
|
+
== DESCRIPTION:
|
6
|
+
|
7
|
+
A little markup validator.
|
8
|
+
|
9
|
+
== FEATURES/PROBLEMS:
|
10
|
+
|
11
|
+
* Validate (X)HTML files.
|
12
|
+
|
13
|
+
== SYNOPSIS:
|
14
|
+
|
15
|
+
=== Valid file
|
16
|
+
|
17
|
+
$ pleasevalidate examples/valid.html
|
18
|
+
Valid: examples/valid.html
|
19
|
+
|
20
|
+
=== Invalid file
|
21
|
+
|
22
|
+
$ pleasevalidate examples/invalid.html
|
23
|
+
Invalid: examples/invalid.html
|
24
|
+
11 errors:
|
25
|
+
Line 8, Column 19: end tag for element "itle" which is not open
|
26
|
+
Line 10, Column 6: end tag for "title" omitted, but OMITTAG NO was specified
|
27
|
+
Line 8, Column 1: start tag was here
|
28
|
+
Line 16, Column 5: document type does not allow element "ul" here; missing one of "object", "ins", "del", "map", "button" start-tag
|
29
|
+
Line 20, Column 0: unclosed end-tag requires SHORTTAG YES
|
30
|
+
Line 20, Column 0: end tag for "li" omitted, but OMITTAG NO was specified
|
31
|
+
Line 17, Column 4: start tag was here
|
32
|
+
Line 20, Column 0: end tag for "ul" omitted, but OMITTAG NO was specified
|
33
|
+
Line 16, Column 2: start tag was here
|
34
|
+
Line 20, Column 0: end tag for "p" omitted, but OMITTAG NO was specified
|
35
|
+
Line 15, Column 2: start tag was here
|
36
|
+
Line 8, Column 20: XML Parsing Error: Opening and ending tag mismatch: title line 8 and itle
|
37
|
+
Line 20, Column 7: XML Parsing Error: expected '>'
|
38
|
+
Line 20, Column 7: XML Parsing Error: Premature end of data in tag p line 15
|
39
|
+
Line 20, Column 7: XML Parsing Error: Premature end of data in tag body line 12
|
40
|
+
Line 20, Column 7: XML Parsing Error: Premature end of data in tag html line 4
|
41
|
+
|
42
|
+
=== A few files: valid, invalid and a non-HTML file
|
43
|
+
|
44
|
+
$pleasevalidate examples/valid.html RakeFile examples/invalid.html
|
45
|
+
Valid: examples/valid.html
|
46
|
+
|
47
|
+
Validation failed: RakeFile must have a content type of text/html
|
48
|
+
|
49
|
+
Invalid: examples/invalid.html
|
50
|
+
11 errors:
|
51
|
+
Line 8, Column 19: end tag for element "itle" which is not open
|
52
|
+
Line 10, Column 6: end tag for "title" omitted, but OMITTAG NO was specified
|
53
|
+
Line 8, Column 1: start tag was here
|
54
|
+
Line 16, Column 5: document type does not allow element "ul" here; missing one of "object", "ins", "del", "map", "button" start-tag
|
55
|
+
Line 20, Column 0: unclosed end-tag requires SHORTTAG YES
|
56
|
+
Line 20, Column 0: end tag for "li" omitted, but OMITTAG NO was specified
|
57
|
+
Line 17, Column 4: start tag was here
|
58
|
+
Line 20, Column 0: end tag for "ul" omitted, but OMITTAG NO was specified
|
59
|
+
Line 16, Column 2: start tag was here
|
60
|
+
Line 20, Column 0: end tag for "p" omitted, but OMITTAG NO was specified
|
61
|
+
Line 15, Column 2: start tag was here
|
62
|
+
Line 8, Column 20: XML Parsing Error: Opening and ending tag mismatch: title line 8 and itle
|
63
|
+
Line 20, Column 7: XML Parsing Error: expected '>'
|
64
|
+
Line 20, Column 7: XML Parsing Error: Premature end of data in tag p line 15
|
65
|
+
Line 20, Column 7: XML Parsing Error: Premature end of data in tag body line 12
|
66
|
+
Line 20, Column 7: XML Parsing Error: Premature end of data in tag html line 4
|
67
|
+
|
68
|
+
== REQUIREMENTS:
|
69
|
+
|
70
|
+
* nokogiri
|
71
|
+
* colored
|
72
|
+
* mime/types
|
73
|
+
|
74
|
+
== INSTALL:
|
75
|
+
|
76
|
+
Run the following if you haven't already:
|
77
|
+
gem sources -a http://gems.github.com
|
78
|
+
Install the gem:
|
79
|
+
sudo gem install DylanFM-pleasevalidate
|
80
|
+
|
81
|
+
== LICENSE:
|
82
|
+
|
83
|
+
(The MIT License)
|
84
|
+
|
85
|
+
Copyright (c) 2009 Dylan Fogarty-MacDonald
|
86
|
+
|
87
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
88
|
+
a copy of this software and associated documentation files (the
|
89
|
+
'Software'), to deal in the Software without restriction, including
|
90
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
91
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
92
|
+
permit persons to whom the Software is furnished to do so, subject to
|
93
|
+
the following conditions:
|
94
|
+
|
95
|
+
The above copyright notice and this permission notice shall be
|
96
|
+
included in all copies or substantial portions of the Software.
|
97
|
+
|
98
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
99
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
100
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
101
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
102
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
103
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
104
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/RakeFile
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
%w[rubygems rake rake/clean fileutils newgem rubigen].each { |f| require f }
|
2
|
+
require File.dirname(__FILE__) + '/lib/please_validate'
|
3
|
+
|
4
|
+
# Generate all the Rake tasks
|
5
|
+
# Run 'rake -T' to see list of generated tasks (from gem root directory)
|
6
|
+
$hoe = Hoe.new('pleasevalidate', PleaseValidate::VERSION) do |p|
|
7
|
+
p.developer('Dylan Fogarty-MacDonald', 'dylan.fm@gmail.com')
|
8
|
+
p.changes = p.paragraphs_of("History.txt", 0..1).join("\n\n")
|
9
|
+
p.post_install_message = 'PostInstall.txt'
|
10
|
+
p.rubyforge_name = p.name
|
11
|
+
p.extra_deps = [
|
12
|
+
['nokogiri'],
|
13
|
+
['colored'],
|
14
|
+
['mime-types']
|
15
|
+
]
|
16
|
+
p.extra_dev_deps = [
|
17
|
+
['newgem', ">= #{::Newgem::VERSION}"]
|
18
|
+
]
|
19
|
+
|
20
|
+
p.clean_globs |= %w[**/.DS_Store tmp *.log]
|
21
|
+
path = (p.rubyforge_name == p.name) ? p.rubyforge_name : "\#{p.rubyforge_name}/\#{p.name}"
|
22
|
+
p.remote_rdoc_dir = File.join(path.gsub(/^#{p.rubyforge_name}\/?/,''), 'rdoc')
|
23
|
+
p.rsync_args = '-av --delete --ignore-errors'
|
24
|
+
end
|
25
|
+
|
26
|
+
require 'newgem/tasks' # load /tasks/*.rake
|
27
|
+
Dir['tasks/**/*.rake'].each { |t| load t }
|
28
|
+
|
29
|
+
require 'cucumber/rake/task'
|
30
|
+
|
31
|
+
Cucumber::Rake::Task.new
|
32
|
+
|
data/bin/pleasevalidate
ADDED
data/cucumber.yml
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
default: features
|
@@ -0,0 +1,9 @@
|
|
1
|
+
Feature: Validate a file
|
2
|
+
In order to product valid markup
|
3
|
+
As a web developer
|
4
|
+
I want to validate a file
|
5
|
+
|
6
|
+
Scenario: Validate a file
|
7
|
+
Given there is a valid html file examples/valid.html
|
8
|
+
When the file is validated and the output is captured
|
9
|
+
Then the result should be displayed saying it's valid
|
@@ -0,0 +1,16 @@
|
|
1
|
+
Feature: only HTML files are valid
|
2
|
+
In order to validate HTML files
|
3
|
+
As a developer
|
4
|
+
I want to make sure only HTML files are validated
|
5
|
+
|
6
|
+
Scenario: HTML file requessted
|
7
|
+
Given there is an HTML file
|
8
|
+
When the HTML file is validated
|
9
|
+
Then there should be no errors
|
10
|
+
|
11
|
+
Scenario: Bad file requested
|
12
|
+
Given there is a non-HTML file
|
13
|
+
When the non-HTML file is requested
|
14
|
+
Then there should be an error
|
15
|
+
|
16
|
+
|
@@ -0,0 +1,9 @@
|
|
1
|
+
Feature: Validation requests are wrapped in a request object
|
2
|
+
In order to validate all my contents
|
3
|
+
As a request
|
4
|
+
I want my request to be understood
|
5
|
+
|
6
|
+
Scenario: Request contains a directory
|
7
|
+
Given there is a directory containing 3 files
|
8
|
+
When the directory is included in a request
|
9
|
+
Then the request should have those 3 files
|
@@ -0,0 +1,14 @@
|
|
1
|
+
Given /^there is a valid html file ([~\w\/.]+)$/ do |file|
|
2
|
+
@file = file
|
3
|
+
File.exist?(@file).should be_true
|
4
|
+
end
|
5
|
+
|
6
|
+
When /^the file is validated and the output is captured$/ do
|
7
|
+
PleaseValidate::CLI.execute(@stdout_io = StringIO.new, [@file])
|
8
|
+
@stdout_io.rewind
|
9
|
+
@stdout = @stdout_io.read
|
10
|
+
end
|
11
|
+
|
12
|
+
Then /^the result should be displayed saying it's valid$/ do
|
13
|
+
@stdout.should =~ /Valid: #{@file}/
|
14
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
Given /^there is an HTML file$/ do
|
2
|
+
Given "there is a valid XHTML file"
|
3
|
+
end
|
4
|
+
|
5
|
+
When /^the HTML file is validated$/ do
|
6
|
+
When "the file is validated"
|
7
|
+
end
|
8
|
+
|
9
|
+
Then /^there should be no errors$/ do
|
10
|
+
@result.should be_an_instance_of(Hash)
|
11
|
+
end
|
12
|
+
|
13
|
+
Given /^there is a non\-HTML file$/ do
|
14
|
+
@file = 'cucumber.yml'
|
15
|
+
File.exist?(@file).should be_true
|
16
|
+
end
|
17
|
+
|
18
|
+
When /^the non\-HTML file is requested$/ do
|
19
|
+
#Nothing to go here?
|
20
|
+
end
|
21
|
+
|
22
|
+
Then /^there should be an error$/ do
|
23
|
+
lambda { PleaseValidate::Validator.file(@file) }.should raise_error
|
24
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
Given /^there is a directory containing 3 files$/ do
|
2
|
+
@dir = 'examples'
|
3
|
+
File.directory?(@dir).should be_true
|
4
|
+
end
|
5
|
+
|
6
|
+
When /^the directory is included in a request$/ do
|
7
|
+
@request = PleaseValidate::Request.new(@dir)
|
8
|
+
end
|
9
|
+
|
10
|
+
Then /^the request should have those 3 files$/ do
|
11
|
+
['valid','invalid','another/fancy'].each do |file|
|
12
|
+
@request.files.should include "#{@dir}/#{file}.html"
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
Given /^there are 2 files for validation$/ do
|
2
|
+
@files = ['examples/valid.html','examples/invalid.html']
|
3
|
+
@files.each do |file|
|
4
|
+
File.exist?(file).should be_true
|
5
|
+
end
|
6
|
+
end
|
7
|
+
|
8
|
+
When /^they are both requested for validation$/ do
|
9
|
+
@results = PleaseValidate::Validator.files(@files)
|
10
|
+
end
|
11
|
+
|
12
|
+
Then /^the result should address both files$/ do
|
13
|
+
@results.should be_a_kind_of Array
|
14
|
+
@results.should have(2).things
|
15
|
+
@files.each do |file|
|
16
|
+
@results.any? { |r| r[:file] == file }.should be_true
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
When /^they are both requested for validation via cli$/ do
|
21
|
+
PleaseValidate::CLI.execute(@stdout_io = StringIO.new, @files)
|
22
|
+
@stdout_io.rewind
|
23
|
+
@stdout = @stdout_io.read
|
24
|
+
end
|
25
|
+
|
26
|
+
Then /^the result should mention both files$/ do
|
27
|
+
@stdout.should =~ /Valid: #{@file}/
|
28
|
+
@stdout.should =~ /Invalid: #{@file}/
|
29
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
Given /^there is a valid XHTML file$/ do
|
2
|
+
@file = 'examples/valid.html'
|
3
|
+
File.exist?(@file).should be_true
|
4
|
+
end
|
5
|
+
|
6
|
+
When /^the file is validated$/ do
|
7
|
+
@result = PleaseValidate::Validator.file(@file)
|
8
|
+
end
|
9
|
+
|
10
|
+
Then /^the response should not show errors$/ do
|
11
|
+
@result[:error_count].should == 0
|
12
|
+
@result[:errors].length.should == 0
|
13
|
+
end
|
14
|
+
|
15
|
+
Then /^the file should be valid$/ do
|
16
|
+
@result[:status].should == :valid
|
17
|
+
end
|
18
|
+
|
19
|
+
Given /^there is an invalid XHTML file$/ do
|
20
|
+
@file = 'examples/invalid.html'
|
21
|
+
File.exist?(@file).should be_true
|
22
|
+
end
|
23
|
+
|
24
|
+
Then /^the file should be invalid$/ do
|
25
|
+
@result[:status].should == :invalid
|
26
|
+
end
|
27
|
+
|
28
|
+
Then /^the response should show errors$/ do
|
29
|
+
@result[:error_count].should > 0
|
30
|
+
@result[:errors].length.should > 0
|
31
|
+
@result[:errors].each do |error|
|
32
|
+
error[:message].should_not be_empty
|
33
|
+
error[:line].should be_an_instance_of(Fixnum)
|
34
|
+
error[:col].should be_an_instance_of(Fixnum)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
@@ -0,0 +1,17 @@
|
|
1
|
+
Feature: Validate markup
|
2
|
+
In order to be standards compliant
|
3
|
+
As a web developer
|
4
|
+
I want to validate my markup
|
5
|
+
|
6
|
+
Scenario: Validate valid markup
|
7
|
+
Given there is a valid XHTML file
|
8
|
+
When the file is validated
|
9
|
+
Then the response should not show errors
|
10
|
+
And the file should be valid
|
11
|
+
|
12
|
+
Scenario: Validate invalid markup
|
13
|
+
Given there is an invalid XHTML file
|
14
|
+
When the file is validated
|
15
|
+
Then the file should be invalid
|
16
|
+
And the response should show errors
|
17
|
+
|
@@ -0,0 +1,15 @@
|
|
1
|
+
Feature: Validates multiple files
|
2
|
+
In order to develop efficiently
|
3
|
+
As a developer
|
4
|
+
I want to validate multiple files at once
|
5
|
+
|
6
|
+
Scenario: validate 2 files
|
7
|
+
Given there are 2 files for validation
|
8
|
+
When they are both requested for validation
|
9
|
+
Then the result should address both files
|
10
|
+
|
11
|
+
Scenario: validate 2 files through cli
|
12
|
+
Given there are 2 files for validation
|
13
|
+
When they are both requested for validation via cli
|
14
|
+
Then the result should mention both files
|
15
|
+
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'net/http'
|
3
|
+
require 'cgi'
|
4
|
+
require 'nokogiri'
|
5
|
+
require 'mime/types'
|
6
|
+
require 'find'
|
7
|
+
|
8
|
+
Dir.glob(File.join(File.dirname(__FILE__), "please_validate", "*.rb")).each { |f| require f }
|
9
|
+
|
10
|
+
module PleaseValidate
|
11
|
+
VERSION = '0.0.3'
|
12
|
+
ACCEPTED_MIMES = ['text/html']
|
13
|
+
end
|
@@ -0,0 +1,74 @@
|
|
1
|
+
require 'optparse'
|
2
|
+
require 'colored'
|
3
|
+
|
4
|
+
module PleaseValidate
|
5
|
+
class CLI
|
6
|
+
class << self
|
7
|
+
# Execute the CLI
|
8
|
+
def execute(stdout, arguments=[])
|
9
|
+
options = {}
|
10
|
+
mandatory_options = %w( )
|
11
|
+
|
12
|
+
parser = OptionParser.new do |opts|
|
13
|
+
opts.banner = <<-BANNER.gsub(/^ /,'')
|
14
|
+
Please Validate does some lovely markup validation of your (X)HTML files.
|
15
|
+
|
16
|
+
Usage: #{File.basename($0)} /path/to/file [options]
|
17
|
+
|
18
|
+
Options are:
|
19
|
+
BANNER
|
20
|
+
opts.separator ""
|
21
|
+
# opts.on("-p", "--path=PATH", String,
|
22
|
+
# "This is a sample message.",
|
23
|
+
# "For multiple lines, add more strings.",
|
24
|
+
# "Default: ~") { |arg| options[:path] = arg }
|
25
|
+
opts.on("-h", "--help",
|
26
|
+
"Show this help message.") { stdout.puts opts; exit }
|
27
|
+
opts.parse!(arguments)
|
28
|
+
|
29
|
+
if mandatory_options && mandatory_options.find { |option| options[option.to_sym].nil? }
|
30
|
+
stdout.puts opts; exit
|
31
|
+
end
|
32
|
+
end
|
33
|
+
validation = new(arguments)
|
34
|
+
stdout.puts validation.msg
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
# Takes the arguments, passes it to validate for validation and displays the result
|
39
|
+
def initialize(arguments)
|
40
|
+
@result = validate arguments
|
41
|
+
@msg = display
|
42
|
+
end
|
43
|
+
|
44
|
+
# Creates a new request object and returns its result
|
45
|
+
def validate(items)
|
46
|
+
request = PleaseValidate::Request.new(items)
|
47
|
+
request.result
|
48
|
+
end
|
49
|
+
|
50
|
+
# Displays the request's results
|
51
|
+
def display
|
52
|
+
@result.inject('') do |msg,result|
|
53
|
+
if result.is_a? Hash
|
54
|
+
msg += "#{result[:status].to_s.capitalize}: #{result[:file]}".send(result[:status] == :valid ? :on_green : :on_red)
|
55
|
+
if result[:status] == :invalid
|
56
|
+
msg += "\n#{result[:error_count]} error#{result[:error_count] == 1 ? nil:'s'}:"
|
57
|
+
result[:errors].each do |error|
|
58
|
+
msg += "\nLine #{error[:line]}, Column #{error[:col]}".red + ": #{error[:message]}"
|
59
|
+
end
|
60
|
+
end
|
61
|
+
elsif result.is_a? String
|
62
|
+
msg += result
|
63
|
+
end
|
64
|
+
msg += "\n\n"
|
65
|
+
msg
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
#Displays the message for the command line result
|
70
|
+
def msg
|
71
|
+
@msg
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
module PleaseValidate
|
2
|
+
|
3
|
+
class Request
|
4
|
+
|
5
|
+
# Takes an array of requested items and passes them to the validator
|
6
|
+
def initialize(arguments)
|
7
|
+
@files = build_file_list_from_request arguments
|
8
|
+
@result = PleaseValidate::Validator.files(files)
|
9
|
+
end
|
10
|
+
|
11
|
+
# Returns the validation result
|
12
|
+
def result
|
13
|
+
@result
|
14
|
+
end
|
15
|
+
|
16
|
+
# Returns all files included in the validation request
|
17
|
+
def files
|
18
|
+
@files
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
# Takes the request's arguments and checks if the requested items are directories
|
23
|
+
# The result of this method is an array of all arguments (files) that are within this request
|
24
|
+
# Any directories will be scanned recursively
|
25
|
+
def build_file_list_from_request(arguments)
|
26
|
+
files = []
|
27
|
+
arguments.each do |item|
|
28
|
+
if File.directory? item
|
29
|
+
Find.find(item) { |f| files << f if File.file? f }
|
30
|
+
else
|
31
|
+
files << item
|
32
|
+
end
|
33
|
+
end
|
34
|
+
files
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
module PleaseValidate
|
2
|
+
|
3
|
+
class Validator
|
4
|
+
|
5
|
+
class << self
|
6
|
+
# Read requested file's contents and send to the w3c validator api then call the parse_response method to sort the response out.
|
7
|
+
def file(file)
|
8
|
+
begin
|
9
|
+
raise "please specify a file to validate" unless file
|
10
|
+
raise "#{file} doesn't exist" unless File.exist? file
|
11
|
+
raise "#{file} must have a content type of text/html" unless file_valid? file
|
12
|
+
response = File.open(file, 'r') do |f|
|
13
|
+
Net::HTTP.start('validator.w3.org').post(
|
14
|
+
'/check',
|
15
|
+
"fragment=#{CGI.escape(f.read)}&output=xml",
|
16
|
+
{'Content-Type' => 'application/x-www-form-urlencoded'}
|
17
|
+
)
|
18
|
+
end
|
19
|
+
parse_response file, response
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
# Takes an array of files and validates them all
|
24
|
+
def files(files)
|
25
|
+
files.uniq.collect do |file|
|
26
|
+
begin
|
27
|
+
self.file(file)
|
28
|
+
rescue Exception => e
|
29
|
+
"Validation failed: #{e}"
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
# Takes an XML response from the file method's call to the w3c and parses it into a nice little hash
|
35
|
+
def parse_response(filename, response)
|
36
|
+
# Use Nokogiri to parse the xml
|
37
|
+
response_data = Nokogiri::XML.parse(response.body)
|
38
|
+
# Begin building the return hash
|
39
|
+
result = {
|
40
|
+
:file => filename,
|
41
|
+
:status => response['x-w3c-validator-status'].downcase.to_sym,
|
42
|
+
:error_count => response['x-w3c-validator-errors'].to_i,
|
43
|
+
:errors => Array.new
|
44
|
+
}
|
45
|
+
# Get meta elements like encoding and doctype
|
46
|
+
response_data.css('result > meta *').each do |meta|
|
47
|
+
next unless %w{encoding doctype}.include? meta.name
|
48
|
+
result[meta.name.to_sym] = meta.content
|
49
|
+
end
|
50
|
+
# Get errors
|
51
|
+
response_data.css('result messages msg').each do |error|
|
52
|
+
result[:errors] << {
|
53
|
+
:message => error.content,
|
54
|
+
:line => error['line'].to_i,
|
55
|
+
:col => error['col'].to_i
|
56
|
+
}
|
57
|
+
end
|
58
|
+
result
|
59
|
+
end
|
60
|
+
|
61
|
+
# Takes a file path and checks to see if it's mime type is OK. Currently using the first mime type returned by the mime-types gem.
|
62
|
+
def file_valid?(file)
|
63
|
+
mime = MIME::Types.type_for(file).first
|
64
|
+
!mime.nil? && ACCEPTED_MIMES.include?(mime.content_type)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
end
|
69
|
+
|
70
|
+
end
|
metadata
ADDED
@@ -0,0 +1,129 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: pleasevalidate
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.3
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Dylan Fogarty-MacDonald
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-03-17 00:00:00 +11:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: nokogiri
|
17
|
+
type: :runtime
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: "0"
|
24
|
+
version:
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: colored
|
27
|
+
type: :runtime
|
28
|
+
version_requirement:
|
29
|
+
version_requirements: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: "0"
|
34
|
+
version:
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: mime-types
|
37
|
+
type: :runtime
|
38
|
+
version_requirement:
|
39
|
+
version_requirements: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: "0"
|
44
|
+
version:
|
45
|
+
- !ruby/object:Gem::Dependency
|
46
|
+
name: newgem
|
47
|
+
type: :development
|
48
|
+
version_requirement:
|
49
|
+
version_requirements: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: 1.2.3
|
54
|
+
version:
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: hoe
|
57
|
+
type: :development
|
58
|
+
version_requirement:
|
59
|
+
version_requirements: !ruby/object:Gem::Requirement
|
60
|
+
requirements:
|
61
|
+
- - ">="
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: 1.8.0
|
64
|
+
version:
|
65
|
+
description: A little markup validator.
|
66
|
+
email:
|
67
|
+
- dylan.fm@gmail.com
|
68
|
+
executables:
|
69
|
+
- pleasevalidate
|
70
|
+
extensions: []
|
71
|
+
|
72
|
+
extra_rdoc_files:
|
73
|
+
- History.txt
|
74
|
+
- Manifest.txt
|
75
|
+
- PostInstall.txt
|
76
|
+
- README.rdoc
|
77
|
+
files:
|
78
|
+
- History.txt
|
79
|
+
- LICENSE
|
80
|
+
- Manifest.txt
|
81
|
+
- PostInstall.txt
|
82
|
+
- README.rdoc
|
83
|
+
- RakeFile
|
84
|
+
- bin/pleasevalidate
|
85
|
+
- cucumber.yml
|
86
|
+
- features/cli_validation.feature
|
87
|
+
- features/file_types.feature
|
88
|
+
- features/request.feature
|
89
|
+
- features/steps/cli_validation_steps.rb
|
90
|
+
- features/steps/file_types_steps.rb
|
91
|
+
- features/steps/helper.rb
|
92
|
+
- features/steps/request_steps.rb
|
93
|
+
- features/steps/validate_multiple_files_steps.rb
|
94
|
+
- features/steps/validate_steps.rb
|
95
|
+
- features/validate.feature
|
96
|
+
- features/validate_multiple_files.feature
|
97
|
+
- lib/please_validate.rb
|
98
|
+
- lib/please_validate/cli.rb
|
99
|
+
- lib/please_validate/request.rb
|
100
|
+
- lib/please_validate/validator.rb
|
101
|
+
has_rdoc: true
|
102
|
+
homepage: http://github.com/DylanFM/please_validate/tree
|
103
|
+
post_install_message: PostInstall.txt
|
104
|
+
rdoc_options:
|
105
|
+
- --main
|
106
|
+
- README.rdoc
|
107
|
+
require_paths:
|
108
|
+
- lib
|
109
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
110
|
+
requirements:
|
111
|
+
- - ">="
|
112
|
+
- !ruby/object:Gem::Version
|
113
|
+
version: "0"
|
114
|
+
version:
|
115
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
116
|
+
requirements:
|
117
|
+
- - ">="
|
118
|
+
- !ruby/object:Gem::Version
|
119
|
+
version: "0"
|
120
|
+
version:
|
121
|
+
requirements: []
|
122
|
+
|
123
|
+
rubyforge_project: pleasevalidate
|
124
|
+
rubygems_version: 1.3.1
|
125
|
+
signing_key:
|
126
|
+
specification_version: 2
|
127
|
+
summary: A little markup validator.
|
128
|
+
test_files: []
|
129
|
+
|