| Class | W3CValidators::MarkupValidator |
| In: |
lib/w3c_validators/markup_validator.rb
|
| Parent: | Validator |
| MARKUP_VALIDATOR_URI | = | 'http://validator.w3.org/check' |
Create a new instance of the MarkupValidator.
The options hash allows you to set request parameters (see validator.w3.org/docs/api.html#requestformat) quickly. Request parameters can also be set using set_charset!, set_debug! and set_doctype!.
You can pass in your own validator‘s URI (i.e. MarkupValidator.new(:validator_uri => ‘localhost/check’)).
# File lib/w3c_validators/markup_validator.rb, line 14
14: def initialize(options = {})
15: if options[:validator_uri]
16: @validator_uri = URI.parse(options[:validator_uri])
17: options.delete(options[:validator_uri])
18: else
19: @validator_uri = URI.parse(MARKUP_VALIDATOR_URI)
20: end
21: super(options)
22: end
Specify the character encoding to use when parsing the document.
When only_as_fallback is true, the given encoding will only be used as a fallback value, in case the charset is absent or unrecognized.
charset can be a string (e.g. set_charset!(‘utf-8’)) or a symbol (e.g. set_charset!(:utf_8)) from the W3CValidators::CHARSETS hash.
Has no effect when using validate_uri_quickly.
# File lib/w3c_validators/markup_validator.rb, line 34
34: def set_charset!(charset, only_as_fallback = false)
35: if charset.kind_of?(Symbol)
36: if CHARSETS.has_key?(charset)
37: charset = CHARSETS[charset]
38: else
39: return
40: end
41: end
42: @options[:charset] = charset
43: @options[:fbc] = only_as_fallback
44: end
When set the validator will output some extra debugging information on the validated resource (such as HTTP headers) and validation process (such as parser used, parse mode, etc.).
Debugging information is stored in the Results debug_messages hash. Custom debugging messages can be set with Results#add_debug_message.
Has no effect when using validate_uri_quickly.
# File lib/w3c_validators/markup_validator.rb, line 77
77: def set_debug!(debug = true)
78: @options[:debug] = debug
79: end
Specify the Document Type (DOCTYPE) to use when parsing the document.
When only_as_fallback is true, the given document type will only be used as a fallback value, in case the document‘s DOCTYPE declaration is missing or unrecognized.
doctype can be a string (e.g. set_doctype!(‘HTML 3.2’)) or a symbol (e.g. set_doctype!(:html32)) from the W3CValidators::DOCTYPES hash.
Has no effect when using validate_uri_quickly.
# File lib/w3c_validators/markup_validator.rb, line 57
57: def set_doctype!(doctype, only_as_fallback = false)
58: if doctype.kind_of?(Symbol)
59: if DOCTYPES.has_key?(doctype)
60: doctype = DOCTYPES[doctype]
61: else
62: return
63: end
64: end
65: @options[:doctype] = doctype
66: @options[:fbd] = only_as_fallback
67: end
Validate the markup of a local file.
file_path may be either the fully-expanded path to the file or an IO object (like File).
Returns W3CValidators::Results.
# File lib/w3c_validators/markup_validator.rb, line 108
108: def validate_file(file_path)
109: if file_path.respond_to? :read
110: src = file_path.read
111: else
112: src = read_local_file(file_path)
113: end
114:
115: return validate({:uploaded_file => src, :file_path => file_path}, false)
116: end
Validate the markup of a string.
Returns W3CValidators::Results.
# File lib/w3c_validators/markup_validator.rb, line 98
98: def validate_text(text)
99: return validate({:fragment => text}, false)
100: end
Validate the markup of an URI using a SOAP request.
Returns W3CValidators::Results.
# File lib/w3c_validators/markup_validator.rb, line 84
84: def validate_uri(uri)
85: return validate({:uri => uri}, false)
86: end
Validate the markup of an URI using a HEAD request.
Returns W3CValidators::Results with an error count, not full error messages.
# File lib/w3c_validators/markup_validator.rb, line 91
91: def validate_uri_quickly(uri)
92: return validate({:uri => uri}, true)
93: end