Class: W3CValidators::CSSValidator

Inherits:
Validator
  • Object
show all
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

#results, #validator_uri

Instance Method Summary collapse

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')).

See Validator#new for proxy server options.



12
13
14
15
16
17
18
19
20
21
# File 'lib/w3c_validators/css_validator.rb', line 12

def initialize(options = {})
  if options[:validator_uri]
    @validator_uri = URI.parse(options[:validator_uri])
    options.delete(options[:validator_uri])
  else
    @validator_uri = URI.parse(CSS_VALIDATOR_URI)
  end
  options[:profile] ||= 'css3'
  super(options)
end

Instance Method Details

#set_language!(lang = 'en') ⇒ Object

The language used for the response.



50
51
52
# File 'lib/w3c_validators/css_validator.rb', line 50

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)


30
31
32
33
34
35
36
37
38
39
# File 'lib/w3c_validators/css_validator.rb', line 30

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



42
43
44
45
46
47
# File 'lib/w3c_validators/css_validator.rb', line 42

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.



74
75
76
77
78
79
80
81
# File 'lib/w3c_validators/css_validator.rb', line 74

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.



64
65
66
# File 'lib/w3c_validators/css_validator.rb', line 64

def validate_text(text)
  return validate({:text => text})
end

#validate_uri(uri) ⇒ Object

Validate the CSS of an URI.

Returns W3CValidators::Results.



57
58
59
# File 'lib/w3c_validators/css_validator.rb', line 57

def validate_uri(uri)
  return validate({:uri => uri})
end