Class: W3CValidators::NuValidator
- Defined in:
- lib/w3c_validators/nu_validator.rb
Constant Summary collapse
- MARKUP_VALIDATOR_URI =
'https://validator.w3.org/nu/'
Constants inherited from Validator
Validator::HEAD_ERROR_COUNT_HEADER, Validator::HEAD_STATUS_HEADER, Validator::SOAP_OUTPUT_PARAM, Validator::USER_AGENT, Validator::USE_NEW_EXCEPTION
Instance Attribute Summary
Attributes inherited from Validator
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ NuValidator
constructor
Create a new instance of the NuValidator.
-
#validate_file(file) ⇒ Object
Validate the markup of a local file.
-
#validate_text(text) ⇒ Object
Validate the markup of a string.
-
#validate_uri(uri) ⇒ Object
Validate the markup of an URI.
Constructor Details
#initialize(options = {}) ⇒ NuValidator
Create a new instance of the NuValidator.
Options
The options
hash allows you to set request parameters (see wiki.whatwg.org/wiki/Validator.nu_Common_Input_Parameters) quickly. Request parameters can also be set using set_charset! and set_doctype!.
You can pass in your own validator’s URI (i.e. NuValidator.new(:validator_uri => 'http://localhost/check')
).
See Validator#new for proxy server options.
18 19 20 21 22 23 24 25 26 27 |
# File 'lib/w3c_validators/nu_validator.rb', line 18 def initialize( = {}) [:parser] = 'html' if [:validator_uri] @validator_uri = URI.parse([:validator_uri]) .delete([:validator_uri]) else @validator_uri = URI.parse(MARKUP_VALIDATOR_URI) end super() end |
Instance Method Details
#validate_file(file) ⇒ Object
Validate the markup of a local file.
file
may be either the fully-expanded path to the file or an IO object (like File).
Returns W3CValidators::Results.
51 52 53 54 55 56 57 58 59 |
# File 'lib/w3c_validators/nu_validator.rb', line 51 def validate_file(file) if file.respond_to? :read src = file.read else src = read_local_file(file) end return validate_text(src) end |
#validate_text(text) ⇒ Object
Validate the markup of a string.
Returns W3CValidators::Results.
41 42 43 |
# File 'lib/w3c_validators/nu_validator.rb', line 41 def validate_text(text) return validate({:content => text}) end |
#validate_uri(uri) ⇒ Object
Validate the markup of an URI.
Returns W3CValidators::Results.
33 34 35 |
# File 'lib/w3c_validators/nu_validator.rb', line 33 def validate_uri(uri) return validate({:doc => uri}) end |