compass-validator 1.0.0 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.markdown CHANGED
@@ -1,6 +1,20 @@
1
1
  # compass-validator
2
2
 
3
- This is a library dependency for [compass](http://compass-style.org/) that provides a css validator for compass projects. It is only useful during development and should be installed separately. Very little is original code. Java is required and must be on the $PATH.
3
+ This is a library dependency for [compass](http://compass-style.org/) that provides a css
4
+ validator for compass projects. It is only useful during development and should be installed
5
+ separately. Very little is original code. Java is required and must be on the $PATH.
6
+
7
+ # Validating a CSS Folder
8
+
9
+ The W3C Validator can be challenging to install and get working. The Compass Validator
10
+ makes it much easier. On a system with java installed all you have do is this:
11
+
12
+ $ gem install compass-validator
13
+ $ compass-validate <css_folder>
14
+
15
+ In your compass project all you have to do is:
16
+
17
+ $ compass validate
4
18
 
5
19
  == Copyright
6
20
 
data/VERSION.yml CHANGED
@@ -1,4 +1,4 @@
1
1
  ---
2
- :major: 1
2
+ :major: 3
3
3
  :minor: 0
4
4
  :patch: 0
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+ require 'compass'
3
+ require 'compass/logger'
4
+ require 'compass-validator'
5
+ Compass::Validator.execute(*ARGV)
@@ -1,16 +1,30 @@
1
1
  # This file was extracted from the blueprint project and then modified.
2
+ require "open3"
2
3
  require File.join(Compass.lib_directory, 'compass', 'core_ext')
3
4
 
4
5
  module Compass
5
6
  # Validates generated CSS against the W3 using Java
6
7
  class Validator
7
- VALIDATOR_FILE = File.join(File.dirname(__FILE__), 'java_validator', 'css-validator.jar')
8
+ VALIDATOR_DIR = File.join(File.dirname(__FILE__), 'java_validator')
9
+ VALIDATOR_FILE = File.join(VALIDATOR_DIR, 'css-validator.jar')
8
10
  attr_reader :error_count
9
11
  attr_reader :css_directory
10
12
 
11
13
  def initialize(css_directory)
12
14
  @css_directory = css_directory
13
15
  @error_count = 0
16
+ @bad_files = 0
17
+ @files = 0
18
+ @results = []
19
+ @logger = Compass::Logger.new(:valid, :invalid)
20
+ Compass::Logger::ACTION_COLORS[:valid] = :green
21
+ Compass::Logger::ACTION_COLORS[:invalid] = :red
22
+ end
23
+
24
+ def self.execute(*directories)
25
+ directories.each do |dir|
26
+ new(dir).validate
27
+ end
14
28
  end
15
29
 
16
30
  # Validates all three CSS files
@@ -18,40 +32,60 @@ module Compass
18
32
  java_path = `which java`.rstrip
19
33
  raise "You do not have a Java installed, but it is required." if java_path.blank?
20
34
 
21
- output_header
22
-
23
35
  Dir.glob(File.join(css_directory, "**", "*.css")).each do |file_name|
24
- @error_count += 1 if !validate_css_file(java_path, file_name)
36
+ @files += 1
37
+ if (count = validate_css_file(java_path, file_name))
38
+ @error_count += count
39
+ @bad_files += 1
40
+ @logger.record(:invalid, file_name)
41
+ else
42
+ @logger.record(:valid, file_name)
43
+ end
25
44
  end
26
45
 
27
- output_footer
46
+ output_results
28
47
  end
29
48
 
30
49
  private
31
50
  def validate_css_file(java_path, css_file)
32
- puts "\n\nTesting #{css_file}"
33
- puts "Output ============================================================\n\n"
34
- system("#{java_path} -jar '#{VALIDATOR_FILE}' -e '#{css_file}'")
51
+ jars = Dir.glob("#{VALIDATOR_DIR}/*.jar")
52
+ cmd = "#{java_path} -classpath '#{jars.join(File::PATH_SEPARATOR)}' org.w3c.css.css.CssValidator -output text -profile css3 'file:#{css_file}'"
53
+ Open3.popen3(cmd) do |stdin, stdout, stderr|
54
+ result = stdout.read
55
+ if result =~ /found the following errors \((\d+)\)/
56
+ @results << [css_file, result]
57
+ return $1.to_i
58
+ end
59
+ end
60
+ nil
35
61
  end
36
62
 
37
- def output_header
38
- puts "\n\n"
39
- puts "************************************************************"
40
- puts "**"
41
- puts "** Compass CSS Validator"
42
- puts "** Validates output CSS files"
43
- puts "**"
44
- puts "************************************************************"
45
- end
46
-
47
- def output_footer
48
- puts "\n\n"
49
- puts "************************************************************"
50
- puts "**"
51
- puts "** Done!"
52
- puts "** Your CSS files are#{" not" if error_count > 0} valid.#{" You had #{error_count} error(s) within your files" if error_count > 0}"
53
- puts "**"
54
- puts "************************************************************"
63
+ def output_results
64
+ if @error_count == 0
65
+ puts "\n\n"
66
+ puts "************************************************************"
67
+ puts
68
+ puts "Result: Valid"
69
+ puts "#{@files} file#{"s" if @files > 1 || @files == 0} validated."
70
+ puts "So INTENSE!"
71
+ puts
72
+ puts "************************************************************"
73
+ else
74
+ puts "\n\n"
75
+ puts "************************************************************"
76
+ puts
77
+ puts "Result: Invalid"
78
+ puts "#{@files} file#{"s" if @files > 1} validated."
79
+ puts "#{@error_count} error#{"s" if @error_count > 1} found in #{@bad_files} file#{"s" if @bad_files > 1}."
80
+ puts "Somewhere, a kitten is crying."
81
+ puts
82
+ puts "************************************************************"
83
+ @results.each do |file, result|
84
+ puts "Output from: #{file}"
85
+ puts result
86
+ puts "************************************************************"
87
+ end
88
+ end
55
89
  end
56
90
  end
57
91
  end
Binary file
metadata CHANGED
@@ -1,12 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: compass-validator
3
3
  version: !ruby/object:Gem::Version
4
+ hash: 7
4
5
  prerelease: false
5
6
  segments:
6
- - 1
7
+ - 3
7
8
  - 0
8
9
  - 0
9
- version: 1.0.0
10
+ version: 3.0.0
10
11
  platform: ruby
11
12
  authors:
12
13
  - Chris Eppstein
@@ -14,14 +15,14 @@ autorequire:
14
15
  bindir: bin
15
16
  cert_chain: []
16
17
 
17
- date: 2010-04-05 00:00:00 -07:00
18
- default_executable:
18
+ date: 2010-10-31 00:00:00 -07:00
19
+ default_executable: compass-validate
19
20
  dependencies: []
20
21
 
21
22
  description:
22
23
  email: chris@eppsteins.net
23
- executables: []
24
-
24
+ executables:
25
+ - compass-validate
25
26
  extensions: []
26
27
 
27
28
  extra_rdoc_files:
@@ -37,10 +38,14 @@ files:
37
38
  - lib/java_validator/JIGSAW_COPYRIGHT
38
39
  - lib/java_validator/README.html
39
40
  - lib/java_validator/XERCES_COPYING.txt
41
+ - lib/java_validator/commons-collections-3.2.1.jar
42
+ - lib/java_validator/commons-lang-2.5.jar
40
43
  - lib/java_validator/css-validator-javadoc.jar
41
44
  - lib/java_validator/css-validator.jar
42
45
  - lib/java_validator/jigsaw.jar
46
+ - lib/java_validator/velocity-1.6.1.jar
43
47
  - lib/java_validator/xerces.jar
48
+ - bin/compass-validate
44
49
  has_rdoc: true
45
50
  homepage: http://github.com/chriseppstein/compass-validator
46
51
  licenses: []
@@ -51,23 +56,27 @@ rdoc_options:
51
56
  require_paths:
52
57
  - lib
53
58
  required_ruby_version: !ruby/object:Gem::Requirement
59
+ none: false
54
60
  requirements:
55
61
  - - ">="
56
62
  - !ruby/object:Gem::Version
63
+ hash: 3
57
64
  segments:
58
65
  - 0
59
66
  version: "0"
60
67
  required_rubygems_version: !ruby/object:Gem::Requirement
68
+ none: false
61
69
  requirements:
62
70
  - - ">="
63
71
  - !ruby/object:Gem::Version
72
+ hash: 3
64
73
  segments:
65
74
  - 0
66
75
  version: "0"
67
76
  requirements: []
68
77
 
69
78
  rubyforge_project:
70
- rubygems_version: 1.3.6
79
+ rubygems_version: 1.3.7
71
80
  signing_key:
72
81
  specification_version: 3
73
82
  summary: A CSS Validator that is used by the Compass CSS Framework.