InternalW3cValidation 1.0.5 → 1.0.6

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.
Files changed (3) hide show
  1. checksums.yaml +8 -8
  2. data/lib/InternalW3cValidation.rb +77 -4
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- OTBhYzVmZjUwZTllZjFmZTVlMDJjN2ZjYzZlNzRmZDM1ZWFjMThmYQ==
4
+ MmY5N2IxN2Q5ZjhhY2NjNzUzYmU1ZDFlYjczMTEwMDJjNzAyODA5NQ==
5
5
  data.tar.gz: !binary |-
6
- NGZkZjk2MWNjY2YyN2Q0NmYzOWZjNWE2NTBiZjZhNzkwMzhmNjY4OQ==
6
+ ZmE5Yjc2ODBkNGFhODdmOGI5NGVkODRkZTZhMjczM2U3YjdhYTlhNA==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- NzhkYTQxZGNjM2JlYzE0NWExZDBlMDg5YzUzYjYyZWRmNDZiMDc1NjM5ZGIy
10
- NDdkYWQyOWFmNzc2MmY2OWYzMTYwYjI0NGVjNDBiMjliNmU0YTVkZDcxY2Zj
11
- NGM3MjQ5MzhjZjYwOTRjNDI2MDA4NWUzZmZlMWU0NjVkZWU0ZmQ=
9
+ OWYxNDYzODdiMTBiMTRjYjJlNDU0MzUxMTgzNGFiNmFlZThkNjExZDg4ODk5
10
+ NzNkZjFkNDkxZjU4MzlmM2ZhODRlNmE5YmY4ZjNmYWM0N2NlNWE0NDZlZmZj
11
+ MTkyNTc4OTUxNzM3OTBjNTE5NmE1M2VmYzIxYTMzNzI4ZjM1MjQ=
12
12
  data.tar.gz: !binary |-
13
- ZTBkOWU4NDgxOWVhMjA0OTc2NjE3MzljMTZmMWY4NDU0MzdiNTM1OTUzYzkw
14
- ZTQ4NjUxMTRmYTAzODUxYjA0ZTg0YTFkNTQ4OWQwNWM4NzBhMzFiMDc5ZDBk
15
- MWQxYzBhOGJjMzRlNDlkMDg5NjM5ZjM1MTk3Y2E0NGMxODE5ZTU=
13
+ YjM4OThhMTk4ZTUwYmNmZDIxMDdjYWIxMTEzZTU2N2FkNDIzZjNkNDliOWMz
14
+ MjQwNDljMWQwNDNkNGZlMzA2ZDg5MWNkOWYwOGVjZjNhYWFiYzMzZjhmYWQ0
15
+ MjZjMzgyMzA0MzQ4MzdjOTU1ZTNkZjMxMTE5NWMwMzMxNDgxNmM=
@@ -1,12 +1,13 @@
1
1
  require_relative "InternalW3cValidator"
2
2
 
3
+ include Rake::DSL
4
+
3
5
  def internalW3cValidation(*args, &block)
4
6
  internal_w3c_validator_wrapper = InternalW3cValidatorWrapper.new(&block)
5
7
  task = Proc.new { internal_w3c_validator_wrapper.run }
6
8
  Rake::Task.define_task(*args, &task)
7
9
  end
8
10
 
9
-
10
11
  class InternalW3cValidatorWrapper
11
12
  def initialize(&block)
12
13
  @block = block;
@@ -15,15 +16,87 @@ class InternalW3cValidatorWrapper
15
16
  def run()
16
17
  configuration = InternalW3cValidationConfiguration.new
17
18
  @block.call(configuration)
19
+ errorReporter = ErrorReporterFactory.create(configuration)
18
20
  results = InternalW3cValidator.new.validate_pages(configuration.pages)
19
21
  results.each do | error |
20
- puts error.to_s
22
+ errorReporter.show(error)
21
23
  end
22
- throw "There are #{results.length} W3c Validation Errors" if results.length > 0 && configuration.failOnError
24
+ errorReporter.end
25
+ throw if results.length > 0 && configuration.failOnError
26
+ end
27
+ end
28
+
29
+ class ConsoleErrorReporter
30
+ def initialize
31
+ @error_count = 0
32
+ end
33
+
34
+ def show(error)
35
+ @error_count += 1
36
+ puts error
37
+ end
38
+
39
+ def end
40
+ puts "-----------------------------------------------"
41
+ puts "There are #{@error_count} W3c Validation Errors"
42
+ puts "-----------------------------------------------"
43
+ end
44
+ end
45
+
46
+ class HtmlErrorReporter
47
+ def initialize(output_file_name)
48
+ @error_count = 0
49
+ @output_file_name = output_file_name
50
+ dirname = File.dirname(output_file_name)
51
+ puts dirname
52
+ FileUtils.mkdir_p(dirname)
53
+ @report_html_file = ReportHtmlFile.new(output_file_name)
54
+ end
55
+
56
+ def show(error)
57
+ @error_count += 1
58
+ @report_html_file.add_error(error)
59
+ end
60
+
61
+ def end
62
+ @report_html_file.save
63
+ puts "--------------------------------------------------------------------------------------"
64
+ puts "There are #{@error_count} W3c Validation Errors (see #{@output_file_name} for details)"
65
+ puts "--------------------------------------------------------------------------------------"
66
+ end
67
+ end
68
+
69
+ class ReportHtmlFile
70
+ def initialize(file_name)
71
+ @error_count = 0
72
+ @file = File.new(file_name, "w+")
73
+ @file.puts "<HTML><BODY>"
74
+ @file.puts "<H1>W3C Validation Results</H1>"
75
+ @file.puts "<UL>"
76
+ end
77
+
78
+ def add_error(error)
79
+ @error_count += 1
80
+ @file.puts "<LI>#{error}</LI>"
81
+ end
82
+
83
+ def save
84
+ @file.puts "</UL>"
85
+ @file.puts "<H3>There are #{@error_count} w3c errors</H3>"
86
+ @file.puts "</BODY></HTML>"
87
+ @file.close()
88
+ end
89
+ end
90
+
91
+ class ErrorReporterFactory
92
+ def self.create(configuration)
93
+ return ConsoleErrorReporter.new if configuration.outputFile.nil?
94
+ HtmlErrorReporter.new(configuration.outputFile)
23
95
  end
24
96
  end
25
97
 
26
98
  class InternalW3cValidationConfiguration
27
99
  attr_accessor :pages,
28
- :failOnError
100
+ :failOnError,
101
+ :outputFile
29
102
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: InternalW3cValidation
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.5
4
+ version: 1.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - iainjmitchell