Class: PageValidations::HTMLValidation
- Inherits:
-
Object
- Object
- PageValidations::HTMLValidation
- Defined in:
- lib/html_validation/page_validations.rb
Constant Summary collapse
- @@default_tidy_flags =
['-quiet', '-indent']
Class Method Summary collapse
-
.default_tidy_flags ⇒ Object
Default command line flags to pass when tidy is executed.
- .default_tidy_flags=(val) ⇒ Object
- .result_attributes(*names) ⇒ Object
-
.show_warnings=(val) ⇒ Object
Shortcut to enable/disable whether warnings are checked in Tidy.
Instance Method Summary collapse
- #data_folder=(path) ⇒ Object
- #default_result_file_path ⇒ Object
-
#each_exception ⇒ Object
For each stored exception, yield an HTMLValidationResult object to allow the user to call .accept! on the exception if it is OK.
-
#initialize(folder_for_data = nil, tidy_flags = [], options = {}) ⇒ HTMLValidation
constructor
:folder_for_data: Storage folder path to save, and look for, result files.
- #result_attributes_and_values ⇒ Object
-
#validation(html, resource_name) ⇒ Object
:html: The html to validate :resource: Used to create a name for the result file, nothing more.
Constructor Details
#initialize(folder_for_data = nil, tidy_flags = [], options = {}) ⇒ HTMLValidation
:folder_for_data: Storage folder path to save, and look for, result files. :options: hash passed directly to HTMLValidationResult
66 67 68 69 70 |
# File 'lib/html_validation/page_validations.rb', line 66 def initialize(folder_for_data = nil, tidy_flags = [], ={}) self.data_folder = folder_for_data || default_result_file_path @tidy_flags = tidy_flags = result_attributes_and_values.merge end |
Class Method Details
.default_tidy_flags ⇒ Object
Default command line flags to pass when tidy is executed. all tidy flags flags as an array of strings like [‘–show-warnings false’] Note: Pass the entire string for each setting, NOT a name value pair settings are available from: tidy -h
77 78 79 |
# File 'lib/html_validation/page_validations.rb', line 77 def self.default_tidy_flags @@default_tidy_flags end |
.default_tidy_flags=(val) ⇒ Object
81 82 83 |
# File 'lib/html_validation/page_validations.rb', line 81 def self.default_tidy_flags=(val) @@default_tidy_flags = val end |
.result_attributes(*names) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/html_validation/page_validations.rb', line 23 def self.result_attributes *names @@result_attributes = names.each do |name| class_eval(%Q{ def self.#{name}=(obj) @@#{name} = obj end def self.#{name} @@#{name} end }) end end |
.show_warnings=(val) ⇒ Object
Shortcut to enable/disable whether warnings are checked in Tidy. Note that changing this setting (or any flag) can change how the result files are seen in terms of their acceptance. Meaning, if you have previously accepted a page with warnings either on or off, you will probably need to re-run the ‘html_validation review’ command following your first run with the new setting.
91 92 93 94 95 96 97 |
# File 'lib/html_validation/page_validations.rb', line 91 def self.show_warnings=(val) if val @@default_tidy_flags.delete('--show-warnings false') # remove the flag (rely on default: true) else (@@default_tidy_flags << '--show-warnings false').uniq! end end |
Instance Method Details
#data_folder=(path) ⇒ Object
118 119 120 121 |
# File 'lib/html_validation/page_validations.rb', line 118 def data_folder=(path) FileUtils.mkdir_p(path) @data_folder = path end |
#default_result_file_path ⇒ Object
123 124 125 126 127 128 129 |
# File 'lib/html_validation/page_validations.rb', line 123 def default_result_file_path posix = RbConfig::CONFIG['host_os'] =~ /(darwin|linux)/ rootpath = ::PageValidations.data_path if ::PageValidations.data_path rootpath ||= Rails.root if defined?(Rails) rootpath ||= posix ? '/tmp/' : "c:\\tmp\\" File.join(rootpath, '.validation') end |
#each_exception ⇒ Object
For each stored exception, yield an HTMLValidationResult object to allow the user to call .accept! on the exception if it is OK.
102 103 104 105 106 107 108 109 |
# File 'lib/html_validation/page_validations.rb', line 102 def each_exception Dir.chdir(@data_folder) Dir.glob("*.exceptions.txt").each do |file| if File.open(File.join(@data_folder, file), 'r').read != '' yield HTMLValidationResult.load_from_files(file.gsub('.exceptions.txt','')) end end end |
#result_attributes_and_values ⇒ Object
37 38 39 40 41 42 43 |
# File 'lib/html_validation/page_validations.rb', line 37 def result_attributes_and_values {}.tap do |res| @@result_attributes.each do |attr| res[attr] = self.class.send attr end end end |
#validation(html, resource_name) ⇒ Object
:html: The html to validate :resource: Used to create a name for the result file, nothing more. Usually a URL.
113 114 115 116 |
# File 'lib/html_validation/page_validations.rb', line 113 def validation(html, resource_name) resource_data_path = File.join(@data_folder, filenameize(resource_name)) HTMLValidationResult.new(resource_name, html, resource_data_path, @tidy_flags, ) end |