Class: Rack::Validate::Validator

Inherits:
Object
  • Object
show all
Includes:
W3CValidators
Defined in:
lib/rack-validate/validator.rb

Class Method Summary collapse

Class Method Details

.generate_report(issues) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/rack-validate/validator.rb', line 16

def self.generate_report( issues )        
  report = ""
  report << STYLES
  report << SCRIPT
  
  report << "<div id='message_toolbar'>"
    report << '<div id="controls">'        
      summary = "<span>There were " + issues.errors.size.to_s + " errors and " + issues.warnings.size.to_s + " warnings</span><br/><br/>"
		  report << summary  		  
		  report << LINKS  		  
  report << '</div>'
  
    if !issues.errors.empty?
      report << "<table id='errors_table' style='display:none;'>"
      report << "<tr><td colspan='2' class='header_column'>Errors</td></tr>"
      issues.errors.each do |item|
        report << "<tr><td class='line_number_column'>Line #{item.line}</td><td class='message_column'>#{html_escape( item.message )}</td></tr>"
      end
      report << "</table>"
    end
  
    if !issues.warnings.empty?
      report << "<table id='warnings_table' style='display:none;'>"
      report << "<tr><td colspan='2' class='header_column'>Warnings</td></tr>"
      issues.warnings.each do |item|
        report << "<tr><td class='line_number_column'>--</td><td class='message_column'>#{html_escape( item.message )}</td></tr>"
      end
      report << "</table>"
    end
  report << "</div>"
end

.validate(response) ⇒ Object



9
10
11
12
13
14
# File 'lib/rack-validate/validator.rb', line 9

def self.validate( response )
  validator = MarkupValidator.new    
  # Wrap response in ResponseFile class so that we can use #validate_file
  # this ensures that long responses won't error out 
  validator.validate_file( ResponseFile.new(response) )        
end