DylanFM-pleasevalidate 0.0.2 → 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 CHANGED
@@ -8,4 +8,9 @@
8
8
  * 1 major enhancement:
9
9
  * Multiple files validated
10
10
  * 1 minor enhancement:
11
- * Mime type checked to only allow html files to be validated
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/Manifest.txt CHANGED
@@ -8,13 +8,16 @@ bin/pleasevalidate
8
8
  cucumber.yml
9
9
  features/cli_validation.feature
10
10
  features/file_types.feature
11
+ features/request.feature
11
12
  features/steps/cli_validation_steps.rb
12
13
  features/steps/file_types_steps.rb
13
14
  features/steps/helper.rb
15
+ features/steps/request_steps.rb
14
16
  features/steps/validate_multiple_files_steps.rb
15
17
  features/steps/validate_steps.rb
16
18
  features/validate.feature
17
19
  features/validate_multiple_files.feature
18
20
  lib/please_validate.rb
19
21
  lib/please_validate/cli.rb
22
+ lib/please_validate/request.rb
20
23
  lib/please_validate/validator.rb
data/README.rdoc CHANGED
@@ -1,6 +1,7 @@
1
1
  = Please Validate
2
2
 
3
- http://github.com/DylanFM/please_validate/tree
3
+ * http://github.com/DylanFM/please_validate/
4
+ * http://rubyforge.org/projects/pleasevalidate/
4
5
 
5
6
  == DESCRIPTION:
6
7
 
@@ -39,6 +40,58 @@ A little markup validator.
39
40
  Line 20, Column 7: XML Parsing Error: Premature end of data in tag body line 12
40
41
  Line 20, Column 7: XML Parsing Error: Premature end of data in tag html line 4
41
42
 
43
+ === A few files: valid, invalid and a non-HTML file
44
+
45
+ $pleasevalidate examples/valid.html RakeFile examples/invalid.html
46
+ Valid: examples/valid.html
47
+
48
+ Validation failed: RakeFile must have a content type of text/html
49
+
50
+ Invalid: examples/invalid.html
51
+ 11 errors:
52
+ Line 8, Column 19: end tag for element "itle" which is not open
53
+ Line 10, Column 6: end tag for "title" omitted, but OMITTAG NO was specified
54
+ Line 8, Column 1: start tag was here
55
+ Line 16, Column 5: document type does not allow element "ul" here; missing one of "object", "ins", "del", "map", "button" start-tag
56
+ Line 20, Column 0: unclosed end-tag requires SHORTTAG YES
57
+ Line 20, Column 0: end tag for "li" omitted, but OMITTAG NO was specified
58
+ Line 17, Column 4: start tag was here
59
+ Line 20, Column 0: end tag for "ul" omitted, but OMITTAG NO was specified
60
+ Line 16, Column 2: start tag was here
61
+ Line 20, Column 0: end tag for "p" omitted, but OMITTAG NO was specified
62
+ Line 15, Column 2: start tag was here
63
+ Line 8, Column 20: XML Parsing Error: Opening and ending tag mismatch: title line 8 and itle
64
+ Line 20, Column 7: XML Parsing Error: expected '>'
65
+ Line 20, Column 7: XML Parsing Error: Premature end of data in tag p line 15
66
+ Line 20, Column 7: XML Parsing Error: Premature end of data in tag body line 12
67
+ Line 20, Column 7: XML Parsing Error: Premature end of data in tag html line 4
68
+
69
+ === A directory
70
+
71
+ $pleasevalidate examples
72
+ Valid: examples/valid.html
73
+
74
+ Invalid: examples/invalid.html
75
+ 11 errors:
76
+ Line 8, Column 19: end tag for element "itle" which is not open
77
+ Line 10, Column 6: end tag for "title" omitted, but OMITTAG NO was specified
78
+ Line 8, Column 1: start tag was here
79
+ Line 16, Column 5: document type does not allow element "ul" here; missing one of "object", "ins", "del", "map", "button" start-tag
80
+ Line 20, Column 0: unclosed end-tag requires SHORTTAG YES
81
+ Line 20, Column 0: end tag for "li" omitted, but OMITTAG NO was specified
82
+ Line 17, Column 4: start tag was here
83
+ Line 20, Column 0: end tag for "ul" omitted, but OMITTAG NO was specified
84
+ Line 16, Column 2: start tag was here
85
+ Line 20, Column 0: end tag for "p" omitted, but OMITTAG NO was specified
86
+ Line 15, Column 2: start tag was here
87
+ Line 8, Column 20: XML Parsing Error: Opening and ending tag mismatch: title line 8 and itle
88
+ Line 20, Column 7: XML Parsing Error: expected '>'
89
+ Line 20, Column 7: XML Parsing Error: Premature end of data in tag p line 15
90
+ Line 20, Column 7: XML Parsing Error: Premature end of data in tag body line 12
91
+ Line 20, Column 7: XML Parsing Error: Premature end of data in tag html line 4
92
+
93
+ Valid: examples/another/fancy.html
94
+
42
95
  == REQUIREMENTS:
43
96
 
44
97
  * nokogiri
@@ -47,10 +100,13 @@ A little markup validator.
47
100
 
48
101
  == INSTALL:
49
102
 
103
+ gem install pleasevalidate
104
+
105
+ === Or via Github:
50
106
  Run the following if you haven't already:
51
107
  gem sources -a http://gems.github.com
52
108
  Install the gem:
53
- sudo gem install DylanFM-pleasevalidate
109
+ gem install DylanFM-pleasevalidate
54
110
 
55
111
  == LICENSE:
56
112
 
@@ -1,7 +1,7 @@
1
- Feature: Validate a file
2
- In order to product valid markup
1
+ Feature: Validate an XHTML file
2
+ In order to produce valid markup
3
3
  As a web developer
4
- I want to validate a file
4
+ I want to validate an XHTML file
5
5
 
6
6
  Scenario: Validate a file
7
7
  Given there is a valid html file examples/valid.html
@@ -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 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
@@ -3,10 +3,11 @@ require 'net/http'
3
3
  require 'cgi'
4
4
  require 'nokogiri'
5
5
  require 'mime/types'
6
+ require 'find'
6
7
 
7
8
  Dir.glob(File.join(File.dirname(__FILE__), "please_validate", "*.rb")).each { |f| require f }
8
9
 
9
10
  module PleaseValidate
10
- VERSION = '0.0.2'
11
+ VERSION = '0.0.3'
11
12
  ACCEPTED_MIMES = ['text/html']
12
13
  end
@@ -6,7 +6,7 @@ module PleaseValidate
6
6
  class << self
7
7
  # Execute the CLI
8
8
  def execute(stdout, arguments=[])
9
- options = {}
9
+ options = { :quiet => false }
10
10
  mandatory_options = %w( )
11
11
 
12
12
  parser = OptionParser.new do |opts|
@@ -22,6 +22,8 @@ module PleaseValidate
22
22
  # "This is a sample message.",
23
23
  # "For multiple lines, add more strings.",
24
24
  # "Default: ~") { |arg| options[:path] = arg }
25
+ opts.on("-q", "--quiet",
26
+ "Hide invalid file notices.") { options[:quiet] = true }
25
27
  opts.on("-h", "--help",
26
28
  "Show this help message.") { stdout.puts opts; exit }
27
29
  opts.parse!(arguments)
@@ -30,45 +32,57 @@ module PleaseValidate
30
32
  stdout.puts opts; exit
31
33
  end
32
34
  end
33
- validation = new(arguments)
35
+ validation = new(arguments, options)
34
36
  stdout.puts validation.msg
35
37
  end
36
38
  end
37
39
 
38
- # Takes the requested file, passes it to validate for validation and displays the result with the display method
39
- def initialize(arguments)
40
- @files = arguments
41
- @results = validate
40
+ # Takes the arguments, passes it to validate for validation and displays the result
41
+ def initialize(arguments, options)
42
+ @result, @options = validate(arguments), options
42
43
  @msg = display
43
44
  end
44
45
 
45
- # Calls the validator class's file method for the requested file
46
- def validate
47
- PleaseValidate::Validator.files(@files)
46
+ # Creates a new request object and returns its result
47
+ def validate(items)
48
+ request = PleaseValidate::Request.new(items)
49
+ request.result
48
50
  end
49
51
 
50
- # Displays the file validation's results
52
+ # Displays the request's results
51
53
  def display
52
- @results.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
54
+ @result.inject('') do |msg,result|
55
+ if result.is_a? String
56
+ next msg if options[:quiet] && result =~ /^Validation failed:/
62
57
  msg += result
58
+ elsif result.is_a? Hash
59
+ msg += message_for result
63
60
  end
64
- msg += "\n\n"
65
- msg
61
+ "#{msg}\n\n"
66
62
  end
67
63
  end
68
64
 
69
- #Displays the message for the command line result
65
+ # Displays the message for the command line result
70
66
  def msg
71
67
  @msg
72
68
  end
69
+
70
+ protected
71
+ # Returns a hash of options passed to command line invocation
72
+ def options
73
+ @options
74
+ end
75
+
76
+ # Takes one result from the validation and makes a message suitable for output
77
+ def message_for(result)
78
+ msg = "#{result[:status].to_s.capitalize}: #{result[:file]}".send(result[:status] == :valid ? :on_green : :on_red)
79
+ if result[:status] == :invalid
80
+ msg += "\n#{result[:error_count]} error#{result[:error_count] == 1 ? nil:'s'}:"
81
+ result[:errors].each do |error|
82
+ msg += "\nLine #{error[:line]}, Column #{error[:col]}".red + ": #{error[:message]}"
83
+ end
84
+ end
85
+ msg
86
+ end
73
87
  end
74
88
  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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: DylanFM-pleasevalidate
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dylan Fogarty-MacDonald
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-03-14 00:00:00 -07:00
12
+ date: 2009-03-31 00:00:00 -07:00
13
13
  default_executable: pleasevalidate
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -85,18 +85,21 @@ files:
85
85
  - cucumber.yml
86
86
  - features/cli_validation.feature
87
87
  - features/file_types.feature
88
+ - features/request.feature
88
89
  - features/steps/cli_validation_steps.rb
89
90
  - features/steps/file_types_steps.rb
90
91
  - features/steps/helper.rb
92
+ - features/steps/request_steps.rb
91
93
  - features/steps/validate_multiple_files_steps.rb
92
94
  - features/steps/validate_steps.rb
93
95
  - features/validate.feature
94
96
  - features/validate_multiple_files.feature
95
97
  - lib/please_validate.rb
96
98
  - lib/please_validate/cli.rb
99
+ - lib/please_validate/request.rb
97
100
  - lib/please_validate/validator.rb
98
101
  has_rdoc: true
99
- homepage: http://github.com/DylanFM/please_validate/tree
102
+ homepage: http://github.com/DylanFM/please_validate/
100
103
  post_install_message: PostInstall.txt
101
104
  rdoc_options:
102
105
  - --main