html_validation 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 16841ce4c4a97f2e7e43df68c179c705d7c409a1
4
+ data.tar.gz: 4e2d18c9de31d6ae7a7661b718cb1846b61204b4
5
+ SHA512:
6
+ metadata.gz: 64c6c31360e9137adf41e1144ff96719acdbe7d02be336c43003b66b8878b965a3e2a44c211cf363868e7536cff83d67fdf4a248ac8d2bd882dece40be1bd954
7
+ data.tar.gz: aaabae9bb5e3fe2a328ddc96a694b2b9de26c3a068acd01ac847e9d3c84bb7598dd52123d1866baf5ab16e8387f4167d0dd7b50ed48526d2333f03354211cc5a
data/Gemfile CHANGED
@@ -11,7 +11,6 @@ end
11
11
 
12
12
  gem 'rdoc'
13
13
  gem 'thor'
14
- gem 'open3'
15
14
 
16
15
  # Unix Rubies (OSX, Linux)
17
16
  platform :ruby do
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- html_validation (0.0.1)
4
+ html_validation (1.0.0)
5
5
 
6
6
  GEM
7
7
  remote: http://rubygems.org/
data/README.rdoc CHANGED
@@ -53,14 +53,19 @@ On linux/OS X machines, confirm the right installation path using: which tidy
53
53
 
54
54
  HTMLValidation.show_warnings = false
55
55
 
56
+ If you want to ignore specific errors, you can do the following :
57
+
58
+ HTMLValidation.ignored_attribute_errors = ['tabindex']
59
+ HTMLValidation.ignored_tag_errors = ['inline']
60
+ HTMLValidation.ignored_errors = ['missing li']
61
+
56
62
 
57
63
 
58
64
  == Non-RSpec Usage:
59
65
 
60
66
  require 'html_validation'
61
67
 
62
-
63
- h = HTMLValidation.new
68
+ h = PageValidations::HTMLValidation.new
64
69
  v = h.validation("<html>foo</html>", 'http://somesite.com/index.html')
65
70
 
66
71
  # Note: The second argument (resource) just serves as an identifier used to
@@ -14,4 +14,5 @@ Gem::Specification.new do |gem|
14
14
  gem.require_paths = ["lib"]
15
15
  gem.executables = ['html_validation']
16
16
  gem.version = PageValidations::HTML_VALIDATOR_VERSION
17
+ gem.license = 'MIT'
17
18
  end
@@ -3,7 +3,7 @@ require File.join(File.dirname(__FILE__), '..', 'html_validation')
3
3
 
4
4
 
5
5
  class HTMLValidationResult
6
- attr_accessor :resource, :html, :exceptions
6
+ attr_accessor :resource, :html, :exceptions, :options
7
7
 
8
8
  include PageValidations
9
9
 
@@ -19,7 +19,7 @@ class HTMLValidationResult
19
19
  @exceptions = ''
20
20
  @datapath = datapath
21
21
  @tidy_flags = (HTMLValidation.default_tidy_flags + tidy_flags).uniq
22
- @ignore_proprietary = options[:ignore_proprietary]
22
+ @options = options
23
23
  valid?
24
24
  end
25
25
 
@@ -99,11 +99,20 @@ class HTMLValidationResult
99
99
  # accepted exception strings will remain valid.
100
100
  def filter(str)
101
101
  str.gsub!(/^line.*trimming empty.*\n/, '') # the messages about empty are overzealous, and not invalid
102
- str.gsub!(/^line.*proprietary.*\n/, '') if @ignore_proprietary # if you use IE only attributes like wrap, or spellcheck or things not in standard
102
+ str.gsub!(/^line.*proprietary.*\n/, '') if options[:ignore_proprietary] # if you use IE only attributes like wrap, or spellcheck or things not in standard
103
+ str.gsub!(/^line.*(?:Error|Warning):.*<\/?(?:#{options[:ignored_tag_errors].join('|')})>.*\n/, '') if options[:ignored_tag_errors] && options[:ignored_tag_errors].any?
104
+ str.gsub!(/^line.*(?:Error|Warning):.* attribute \"(?:#{options[:ignored_attribute_errors].join('|')})\".*\n/, '') if options[:ignored_attribute_errors] && options[:ignored_attribute_errors].any?
105
+ if options[:ignored_errors] && options[:ignored_errors].any? && str.gsub(/^line.*(?:Error|Warning):/, '') =~ ignored_errors_regex
106
+ str.gsub!(Regexp.new(/^line.*(?:Error|Warning):/.source + '.*' + ignored_errors_regex.source + '.*' +/\n/.source), '')
107
+ end
103
108
  str.gsub(/line [0-9]+ column [0-9]+ -/, '')
104
109
  # /line [0-9]+ column [0-9]+ - / + =~ "line 1 column 1 - Warning: missing <!DOCTYPE> declaration"
105
110
  end
106
111
 
112
+ def ignored_errors_regex
113
+ /(?:#{options[:ignored_errors].join('|')})/
114
+ end
115
+
107
116
  def validate
108
117
  stdin, stdout, stderr = Open3.popen3(tidy_command)
109
118
  stdin.puts @html
@@ -21,6 +21,33 @@ module PageValidations
21
21
 
22
22
  class HTMLValidation
23
23
 
24
+ def self.result_attributes *names
25
+ @@result_attributes = names.each do |name|
26
+ class_eval(%Q{
27
+ def self.#{name}=(obj)
28
+ @@#{name} = obj
29
+ end
30
+
31
+ def self.#{name}
32
+ @@#{name}
33
+ end
34
+ })
35
+ end
36
+ end
37
+
38
+ def result_attributes_and_values
39
+ {}.tap do |res|
40
+ @@result_attributes.each do |attr|
41
+ res[attr] = self.class.send attr
42
+ end
43
+ end
44
+ end
45
+
46
+ result_attributes :ignored_errors, :ignored_attribute_errors, :ignored_tag_errors
47
+ self.ignored_attribute_errors = []
48
+ self.ignored_tag_errors = []
49
+ self.ignored_errors = []
50
+
24
51
  @@default_tidy_flags = ['-quiet', '-indent']
25
52
 
26
53
  # The data_folder is where we store our output. options[:tidyopts], which defaults to "-qi"
@@ -40,7 +67,7 @@ module PageValidations
40
67
  def initialize(folder_for_data = nil, tidy_flags = [], options={})
41
68
  self.data_folder = folder_for_data || default_result_file_path
42
69
  @tidy_flags = tidy_flags
43
- @options = options
70
+ @options = result_attributes_and_values.merge options
44
71
  end
45
72
 
46
73
 
@@ -1,3 +1,3 @@
1
1
  module PageValidations
2
- HTML_VALIDATOR_VERSION = "1.0.0"
2
+ HTML_VALIDATOR_VERSION = "1.1.0"
3
3
  end
@@ -89,6 +89,29 @@ describe "HTMLValidation" do
89
89
  result.exceptions.should_not be_empty
90
90
  end
91
91
 
92
+ it 'should ignore ignored_attribute_errors' do
93
+ HTMLValidation.ignored_attribute_errors = ['tabindex']
94
+ h = HTMLValidation.new()
95
+ result = h.validation(good_html.gsub('<body>','<body><span tabindex="-1">blabla</span>'), "http://mywarningsite.com")
96
+ result.valid?.should be_true
97
+ HTMLValidation.ignored_attribute_errors = []
98
+ end
99
+
100
+ it 'should ignored_tag_errors' do
101
+ HTMLValidation.ignored_tag_errors = ['inline']
102
+ h = HTMLValidation.new()
103
+ result = h.validation(good_html.gsub('<body>','<body><inline>rrr</inline>'), "http://mywarningsite.com")
104
+ result.valid?.should be_true
105
+ HTMLValidation.ignored_tag_errors = []
106
+ end
107
+
108
+ it 'should ignored_errors' do
109
+ HTMLValidation.ignored_errors = ['inline']
110
+ h = HTMLValidation.new()
111
+ result = h.validation(good_html.gsub('<body>','<body><inline>rrr</inline>'), "http://mywarningsite.com")
112
+ result.valid?.should be_true
113
+ HTMLValidation.ignored_errors = []
114
+ end
92
115
 
93
116
  describe "when launching HTML Tidy" do
94
117
 
metadata CHANGED
@@ -1,15 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: html_validation
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
5
- prerelease:
4
+ version: 1.1.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Eric Beland
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-07-17 00:00:00.000000000 Z
11
+ date: 2014-03-21 00:00:00.000000000 Z
13
12
  dependencies: []
14
13
  description: HTML Validation lets you validate html locally. Lets you build html validation
15
14
  into your test suite, but break the rules if you must.
@@ -40,32 +39,31 @@ files:
40
39
  - spec/html_validation_spec.rb
41
40
  - spec/spec_helper.rb
42
41
  homepage: https://github.com/ericbeland/html_validation
43
- licenses: []
42
+ licenses:
43
+ - MIT
44
+ metadata: {}
44
45
  post_install_message:
45
46
  rdoc_options: []
46
47
  require_paths:
47
48
  - lib
48
49
  required_ruby_version: !ruby/object:Gem::Requirement
49
- none: false
50
50
  requirements:
51
- - - ! '>='
51
+ - - '>='
52
52
  - !ruby/object:Gem::Version
53
53
  version: '0'
54
54
  required_rubygems_version: !ruby/object:Gem::Requirement
55
- none: false
56
55
  requirements:
57
- - - ! '>='
56
+ - - '>='
58
57
  - !ruby/object:Gem::Version
59
58
  version: '0'
60
59
  requirements: []
61
60
  rubyforge_project:
62
- rubygems_version: 1.8.25
61
+ rubygems_version: 2.2.1
63
62
  signing_key:
64
- specification_version: 3
63
+ specification_version: 4
65
64
  summary: Local HTML validation for tests and RSpec.
66
65
  test_files:
67
66
  - spec/helpers/html_validation_helpers.rb
68
67
  - spec/html_validation_matcher_spec.rb
69
68
  - spec/html_validation_spec.rb
70
69
  - spec/spec_helper.rb
71
- has_rdoc: