From dd750391be66b19781790cdfc25d02bb56c1e0e0 Mon Sep 17 00:00:00 2001 From: Chris Eppstein Date: Mon, 26 Oct 2009 09:25:52 -0700 Subject: [PATCH] Subcommand for CSS validation. --- features/command_line.feature | 2 +- .../step_definitions/command_line_steps.rb | 6 +- lib/compass/commands/validate_project.rb | 58 ++++++++++++++++++- 3 files changed, 60 insertions(+), 6 deletions(-) diff --git a/features/command_line.feature b/features/command_line.feature index 03f4da42..782fdd86 100644 --- a/features/command_line.feature +++ b/features/command_line.feature @@ -204,7 +204,7 @@ Feature: Command Line Given I am using the existing project in test/fixtures/stylesheets/compass When I run: compass validate Then my css is validated - And I am informed that it is not, because IE6 hacks suck. + And I am informed that my css is valid. Scenario: Get stats for my project Given I am using the existing project in test/fixtures/stylesheets/compass diff --git a/features/step_definitions/command_line_steps.rb b/features/step_definitions/command_line_steps.rb index 9307c88c..cf92c8c1 100644 --- a/features/step_definitions/command_line_steps.rb +++ b/features/step_definitions/command_line_steps.rb @@ -170,11 +170,11 @@ Then /^the following configuration properties are set in config\/compass\.rb:$/ end Then /^my css is validated$/ do - pending + @last_result.should =~ /Compass CSS Validator/ end -Then /^I am informed that it is not, because IE6 hacks suck\.$/ do - pending +Then /^I am informed that my css is valid.$/ do + @last_result.should =~ /Your CSS files are valid\./ end Then /^I am told statistics for each file:$/ do |table| diff --git a/lib/compass/commands/validate_project.rb b/lib/compass/commands/validate_project.rb index cd19ce60..bd326560 100644 --- a/lib/compass/commands/validate_project.rb +++ b/lib/compass/commands/validate_project.rb @@ -3,8 +3,26 @@ require 'compass/commands/update_project' module Compass module Commands + module ValidationOptionsParser + def set_options(opts) + opts.banner = %Q{ + Usage: compass validate [path/to/project] [options] + + Description: + Compile project at the path specified or the current + directory if not specified and then validate the + generated CSS. + + Options: + }.strip.split("\n").map{|l| l.gsub(/^ {0,10}/,'')}.join("\n") + + super + end + end class ValidateProject < ProjectBase - + + register :validate + def initialize(working_path, options) super assert_project_directory_exists! @@ -16,6 +34,42 @@ module Compass Validator.new(project_css_subdirectory).validate() end + class << self + + def option_parser(arguments) + parser = Compass::Exec::CommandOptionParser.new(arguments) + parser.extend(Compass::Exec::GlobalOptionsParser) + parser.extend(Compass::Exec::ProjectOptionsParser) + parser.extend(ValidationOptionsParser) + end + + def usage + option_parser([]).to_s + end + + def description(command) + "Validate your generated css." + end + + def parse!(arguments) + parser = option_parser(arguments) + parser.parse! + parse_arguments!(parser, arguments) + parser.options + end + + def parse_arguments!(parser, arguments) + if arguments.size == 1 + parser.options[:project_name] = arguments.shift + elsif arguments.size == 0 + # default to the current directory. + else + raise Compass::Error, "Too many arguments were specified." + end + end + + end + end end -end \ No newline at end of file +end