Validate your project's CSS files by running compass --validate.

This commit is contained in:
Chris Eppstein 2009-04-01 18:23:22 -07:00
parent a8b36a6441
commit 63de13debd
6 changed files with 45 additions and 54 deletions

View File

@ -55,7 +55,6 @@ examples/yui/sub_divisions.html.haml
examples/yui/templates.html.haml examples/yui/templates.html.haml
examples/yui/test.jpg examples/yui/test.jpg
examples/yui/typography.html.haml examples/yui/typography.html.haml
frameworks/blueprint/lib/blueprint/constants.rb
frameworks/blueprint/lib/blueprint/grid_builder.rb frameworks/blueprint/lib/blueprint/grid_builder.rb
frameworks/blueprint/stylesheets/_blueprint.sass frameworks/blueprint/stylesheets/_blueprint.sass
frameworks/blueprint/stylesheets/blueprint/_ie.sass frameworks/blueprint/stylesheets/blueprint/_ie.sass
@ -125,6 +124,7 @@ lib/compass/commands/list_frameworks.rb
lib/compass/commands/print_version.rb lib/compass/commands/print_version.rb
lib/compass/commands/project_base.rb lib/compass/commands/project_base.rb
lib/compass/commands/update_project.rb lib/compass/commands/update_project.rb
lib/compass/commands/validate_project.rb
lib/compass/commands/watch_project.rb lib/compass/commands/watch_project.rb
lib/compass/commands/write_configuration.rb lib/compass/commands/write_configuration.rb
lib/compass/compiler.rb lib/compass/compiler.rb
@ -149,7 +149,6 @@ lib/compass/validate/JIGSAW_COPYRIGHT
lib/compass/validate/README.html lib/compass/validate/README.html
lib/compass/validate/xerces.jar lib/compass/validate/xerces.jar
lib/compass/validate/XERCES_COPYING.txt lib/compass/validate/XERCES_COPYING.txt
lib/compass/validate.rb
lib/compass/validator.rb lib/compass/validator.rb
lib/compass/version.rb lib/compass/version.rb
lib/compass.rb lib/compass.rb

View File

@ -1,17 +0,0 @@
require 'fileutils'
module Blueprint
module Constants
# path to the root Blueprint directory
ROOT_PATH = File.expand_path(File.join(File.dirname(__FILE__), "../../"))
# path to where the Blueprint CSS files are stored
BLUEPRINT_ROOT_PATH = File.join(ROOT_PATH, 'blueprint')
# path to where the Blueprint CSS raw Sass files are stored
SOURCE_PATH = File.join(ROOT_PATH, 'src')
# path to where the Blueprint CSS generated test files are stored
EXAMPLES_PATH = File.join(ROOT_PATH, 'examples')
# path to the root of the Blueprint scripts
LIB_PATH = File.join(ROOT_PATH, 'lib', 'blueprint')
# path to validator jar file to validate generated CSS files
VALIDATOR_FILE = File.join(LIB_PATH, 'validate', 'css-validator.jar')
end
end

View File

@ -0,0 +1,21 @@
require File.join(File.dirname(__FILE__), 'project_base')
require File.join(File.dirname(__FILE__), 'update_project')
require File.join(File.dirname(__FILE__), '..', 'validator')
module Compass
module Commands
class ValidateProject < ProjectBase
def initialize(working_path, options)
super
assert_project_directory_exists!
end
def perform
UpdateProject.new(working_path, options).perform
Validator.new(project_css_subdirectory).validate()
end
end
end
end

View File

@ -158,6 +158,10 @@ END
exit exit
end end
opts.on('--validate', :NONE, 'Validate your project\'s compiled css') do
self.options[:command] = :validate_project
end
opts.on_tail("-?", "-h", "--help", "Show this message") do opts.on_tail("-?", "-h", "--help", "Show this message") do
puts opts puts opts
exit exit

View File

@ -1,13 +0,0 @@
#!/usr/bin/env ruby
require File.join(File.dirname(__FILE__), 'compass', 'validator')
# This script will validate the core Compass files.
#
# The files are not completely valid. This has to do
# with a small number of CSS hacks needed to ensure
# consistent rendering across browsers.
#
# To add your own CSS files for validation, see
# /lib/compass/validator.rb
Compass::Validator.new.validate

View File

@ -1,13 +1,14 @@
require File.join(File.dirname(__FILE__), 'core_ext') require File.join(File.dirname(__FILE__), 'core_ext')
require File.join(File.dirname(__FILE__), 'constants')
module Compass module Compass
# Validates generated CSS against the W3 using Java # Validates generated CSS against the W3 using Java
class Validator class Validator
VALIDATOR_FILE = File.join(File.dirname(__FILE__), 'validate', 'css-validator.jar') VALIDATOR_FILE = File.join(File.dirname(__FILE__), 'validate', 'css-validator.jar')
attr_reader :error_count attr_reader :error_count
attr_reader :css_directory
def initialize def initialize(css_directory)
@css_directory = css_directory
@error_count = 0 @error_count = 0
end end
@ -18,12 +19,8 @@ module Compass
output_header output_header
Dir.new(Compass::Constants::BLUEPRINT_ROOT_PATH).each do |file_name| Dir.glob(File.join(css_directory, "**", "*.css")).each do |file_name|
puts "#{file_name}" @error_count += 1 if !validate_css_file(java_path, 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 end
output_footer output_footer
@ -31,29 +28,29 @@ module Compass
private private
def validate_css_file(java_path, css_file) def validate_css_file(java_path, css_file)
puts "\n\n Testing #{css_file}" puts "\n\nTesting #{css_file}"
puts " Output ============================================================\n\n" puts "Output ============================================================\n\n"
system("#{java_path} -jar '#{VALIDATOR_FILE}' -e '#{css_file}'") system("#{java_path} -jar '#{VALIDATOR_FILE}' -e '#{css_file}'")
end end
def output_header def output_header
puts "\n\n" puts "\n\n"
puts " ************************************************************" puts "************************************************************"
puts " **" puts "**"
puts " ** Compass CSS Validator" puts "** Compass CSS Validator"
puts " ** Validates output CSS files" puts "** Validates output CSS files"
puts " **" puts "**"
puts " ************************************************************" puts "************************************************************"
end end
def output_footer def output_footer
puts "\n\n" puts "\n\n"
puts " ************************************************************" puts "************************************************************"
puts " **" puts "**"
puts " ** Done!" 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 "** 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 "**"
puts " ************************************************************" puts "************************************************************"
end end
end end
end end