Class: Compass::Validator

Inherits:
Object
  • Object
show all
Defined in:
lib/compass-validator.rb

Overview

Validates generated CSS against the W3 using Java

Constant Summary collapse

VALIDATOR_DIR =
File.join(File.dirname(__FILE__), 'java_validator')
VALIDATOR_FILE =
File.join(VALIDATOR_DIR, 'css-validator.jar')

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(css_directory) ⇒ Validator

Returns a new instance of Validator.



12
13
14
15
16
17
18
19
20
21
# File 'lib/compass-validator.rb', line 12

def initialize(css_directory)
  @css_directory = css_directory
  @error_count = 0
  @bad_files = 0
  @files = 0
  @results = []
  @logger = Compass::Logger.new(:valid, :invalid)
  Compass::Logger::ACTION_COLORS[:valid] = :green
  Compass::Logger::ACTION_COLORS[:invalid] = :red
end

Instance Attribute Details

#css_directoryObject (readonly)

Returns the value of attribute css_directory.



10
11
12
# File 'lib/compass-validator.rb', line 10

def css_directory
  @css_directory
end

#error_countObject (readonly)

Returns the value of attribute error_count.



9
10
11
# File 'lib/compass-validator.rb', line 9

def error_count
  @error_count
end

Class Method Details

.execute(*directories) ⇒ Object



23
24
25
26
27
# File 'lib/compass-validator.rb', line 23

def self.execute(*directories)
  directories.each do |dir|
    new(dir).validate
  end
end

Instance Method Details

#validateObject

Validates all three CSS files



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/compass-validator.rb', line 30

def validate
  java_path = `which java`.rstrip
  raise "You do not have a Java installed, but it is required." unless java_path && !java_path.empty?

  Dir.glob(File.join(css_directory, "**", "*.css")).each do |file_name|
    @files += 1
    if (count = validate_css_file(java_path, file_name))
      @error_count += count
      @bad_files += 1
      @logger.record(:invalid, file_name)
    else
      @logger.record(:valid, file_name)
    end
  end

  output_results
end