Sha256: c740d6975d592fe4b76d64063d5e09205240b15f3e92dd31b1a26a3b9b5d82f3

Contents?: true

Size: 1.9 KB

Versions: 26

Compression:

Stored size: 1.9 KB

Contents

require File.join(File.dirname(__FILE__), 'core_ext')
require File.join(File.dirname(__FILE__), 'constants')

module Compass
  # Validates generated CSS against the W3 using Java
  class Validator
    VALIDATOR_FILE = File.join(File.dirname(__FILE__), 'validate', 'css-validator.jar')
    attr_reader :error_count
    
    def initialize
      @error_count = 0
    end

    # Validates all three CSS files
    def validate
      java_path = `which java`.rstrip
      raise "You do not have a Java installed, but it is required." if java_path.blank?
    
      output_header
    
      Dir.new(Compass::Constants::BLUEPRINT_ROOT_PATH).each do |file_name|
        puts "#{file_name}"
        if file_name =~ /\.css$/
          css_file = File.join(Compass::Constants::BLUEPRINT_ROOT_PATH, file_name)
          @error_count += 1 if !validate_css_file(java_path, css_file)
        end
      end
    
      output_footer
    end
    
    private
    def validate_css_file(java_path, css_file)
      puts "\n\n  Testing #{css_file}"
      puts "  Output ============================================================\n\n"
      system("#{java_path} -jar '#{VALIDATOR_FILE}' -e '#{css_file}'")
    end
    
    def output_header
      puts "\n\n"
      puts "  ************************************************************"
      puts "  **"
      puts "  **   Compass CSS Validator"
      puts "  **   Validates output CSS files"
      puts "  **"
      puts "  ************************************************************"
    end

    def output_footer
      puts "\n\n"
      puts "  ************************************************************"
      puts "  **"
      puts "  **   Done!"
      puts "  **   Your CSS files are#{" not" if error_count > 0} valid.#{"  You had #{error_count} error(s) within your files" if error_count > 0}"
      puts "  **"
      puts "  ************************************************************"
    end
  end
end

Version data entries

26 entries across 26 versions & 6 rubygems

Version Path
arnebrasseur-compass-0.3.5.1 lib/compass/validator.rb
arnebrasseur-compass-0.3.5 lib/compass/validator.rb
bsherman-compass-0.5.2 lib/compass/validator.rb
chriseppstein-compass-0.1.1 lib/compass/validator.rb
chriseppstein-compass-0.3.0 lib/compass/validator.rb
chriseppstein-compass-0.3.1 lib/compass/validator.rb
chriseppstein-compass-0.3.2 lib/compass/validator.rb
chriseppstein-compass-0.3.3 lib/compass/validator.rb
chriseppstein-compass-0.3.4 lib/compass/validator.rb
chriseppstein-compass-0.3.6 lib/compass/validator.rb
chriseppstein-compass-0.3.7 lib/compass/validator.rb
chriseppstein-compass-0.3.8 lib/compass/validator.rb
chriseppstein-compass-0.3.9 lib/compass/validator.rb
chriseppstein-compass-0.4.0 lib/compass/validator.rb
chriseppstein-compass-0.4.1 lib/compass/validator.rb
chriseppstein-compass-0.4.2 lib/compass/validator.rb
chriseppstein-compass-0.5.0 lib/compass/validator.rb
chriseppstein-compass-0.5.1 lib/compass/validator.rb
chriseppstein-compass-0.5.2 lib/compass/validator.rb
chriseppstein-compass-0.5.3 lib/compass/validator.rb