Class: W3CValidators::CSSValidator
- Defined in:
- lib/w3c_validators/css_validator.rb
Constant Summary collapse
- CSS_VALIDATOR_URI =
'http://jigsaw.w3.org/css-validator/validator'
Constants inherited from Validator
Validator::HEAD_ERROR_COUNT_HEADER, Validator::HEAD_STATUS_HEADER, Validator::SOAP_OUTPUT_PARAM, Validator::USER_AGENT, Validator::VERSION
Instance Attribute Summary
Attributes inherited from Validator
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ CSSValidator
constructor
Create a new instance of the CSSValidator.
-
#set_language!(lang = 'en') ⇒ Object
The language used for the response.
-
#set_profile!(profile) ⇒ Object
The CSS profile used for the validation.
-
#set_warn_level!(level = 2) ⇒ Object
The warning level, no for no warnings, 0 for less warnings, 1or 2 for more warnings.
-
#validate_file(file_path) ⇒ Object
Validate the CSS of a local file.
-
#validate_text(text) ⇒ Object
Validate the CSS of a string.
-
#validate_uri(uri) ⇒ Object
Validate the CSS of an URI.
Constructor Details
#initialize(options = {}) ⇒ CSSValidator
Create a new instance of the CSSValidator.
Options
You can pass in your own validator’s URI (i.e. CSSValidator.new(:validator_uri => 'http://localhost/check')
).
10 11 12 13 14 15 16 17 18 |
# File 'lib/w3c_validators/css_validator.rb', line 10 def initialize( = {}) if [:validator_uri] @validator_uri = URI.parse([:validator_uri]) .delete([:validator_uri]) else @validator_uri = URI.parse(CSS_VALIDATOR_URI) end super() end |
Instance Method Details
#set_language!(lang = 'en') ⇒ Object
The language used for the response.
47 48 49 |
# File 'lib/w3c_validators/css_validator.rb', line 47 def set_language!(lang = 'en') @options[:lang] = lang end |
#set_profile!(profile) ⇒ Object
The CSS profile used for the validation.
charset
can be a string or a symbl from the W3CValidators::CSS_PROFILES hash.
Example
set_profile!('css1')
set_profile!(:css1)
27 28 29 30 31 32 33 34 35 36 |
# File 'lib/w3c_validators/css_validator.rb', line 27 def set_profile!(profile) if profile.kind_of?(Symbol) if CSS_PROFILES.has_key?(profile) profile = profile.to_s else return end end @options[:profile] = profile end |
#set_warn_level!(level = 2) ⇒ Object
The warning level, no for no warnings, 0 for less warnings, 1or 2 for more warnings
39 40 41 42 43 44 |
# File 'lib/w3c_validators/css_validator.rb', line 39 def set_warn_level!(level = 2) warn_levels = ['0','1','2','no'] return unless warn_levels.include?(level.to_s.downcase) @options[:warning] = level end |
#validate_file(file_path) ⇒ Object
Validate the CSS 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.
71 72 73 74 75 76 77 78 |
# File 'lib/w3c_validators/css_validator.rb', line 71 def validate_file(file_path) if file_path.respond_to? :read src = file_path.read else src = read_local_file(file_path) end return validate_text(src) end |
#validate_text(text) ⇒ Object
Validate the CSS of a string.
Returns W3CValidators::Results.
61 62 63 |
# File 'lib/w3c_validators/css_validator.rb', line 61 def validate_text(text) return validate({:text => text}) end |
#validate_uri(uri) ⇒ Object
Validate the CSS of an URI.
Returns W3CValidators::Results.
54 55 56 |
# File 'lib/w3c_validators/css_validator.rb', line 54 def validate_uri(uri) return validate({:uri => uri}) end |