class Codeqa::Checkers::HtmlValidator
Constants
- REMOVED_NOKOGIRI_ERRORS
Public Class Methods
available?()
click to toggle source
# File lib/codeqa/checkers/html_validator.rb, line 10 def self.available? nokogiri? end
check?(sourcefile)
click to toggle source
# File lib/codeqa/checkers/html_validator.rb, line 6 def self.check?(sourcefile) sourcefile.html? end
nokogiri?()
click to toggle source
# File lib/codeqa/checkers/html_validator.rb, line 49 def self.nokogiri? @loaded ||= begin require 'nokogiri' true end end
Public Instance Methods
check()
click to toggle source
# File lib/codeqa/checkers/html_validator.rb, line 29 def check return unless self.class.nokogiri? doc = Nokogiri::XML "<special>#{stripped_html}</special>" doc.errors.delete_if{ |e| e.message =~ REMOVED_NOKOGIRI_ERRORS } errors.add(:source, sourcefile.content) unless doc.errors.empty? doc.errors.each do |error| errors.add(error.line, error.message) unless error.warning? end end
hint()
click to toggle source
# File lib/codeqa/checkers/html_validator.rb, line 18 def hint 'Nokogiri found XHTML errors, please fix them.' end
name()
click to toggle source
# File lib/codeqa/checkers/html_validator.rb, line 14 def name 'html' end
stripped_html()
click to toggle source
# File lib/codeqa/checkers/html_validator.rb, line 40 def stripped_html @stripped_html ||= ErbSanitizer. new(sourcefile.content). result. gsub(%r{<script[ >](.*?)</script>}m) do "<!-- script#{"\n" * $1.scan("\n").count} /script -->" end end