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
-
.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.
-
#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
40 41 42 43 44 |
# File 'lib/html_validation/page_validations.rb', line 40 def initialize(folder_for_data = nil, tidy_flags = [], ={}) self.data_folder = folder_for_data || default_result_file_path @tidy_flags = tidy_flags = 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
51 52 53 |
# File 'lib/html_validation/page_validations.rb', line 51 def self.default_tidy_flags @@default_tidy_flags end |
.default_tidy_flags=(val) ⇒ Object
55 56 57 |
# File 'lib/html_validation/page_validations.rb', line 55 def self.default_tidy_flags=(val) @@default_tidy_flags = val 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.
65 66 67 68 69 70 71 |
# File 'lib/html_validation/page_validations.rb', line 65 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
92 93 94 95 |
# File 'lib/html_validation/page_validations.rb', line 92 def data_folder=(path) FileUtils.mkdir_p(path) @data_folder = path end |
#default_result_file_path ⇒ Object
97 98 99 100 101 102 103 |
# File 'lib/html_validation/page_validations.rb', line 97 def default_result_file_path posix = RbConfig::CONFIG['host_os'] =~ /(darwin|linux)/ rootpath = Rails.root if defined?(Rails) rootpath ||= ::PageValidations.data_path if ::PageValidations.data_path 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.
76 77 78 79 80 81 82 83 |
# File 'lib/html_validation/page_validations.rb', line 76 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 |
#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.
87 88 89 90 |
# File 'lib/html_validation/page_validations.rb', line 87 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 |