Module: RubyCssLint

Defined in:
lib/ruby_css_lint.rb,
lib/ruby_css_lint.rb

Defined Under Namespace

Classes: Railtie

Constant Summary collapse

WARNING =
1
ERROR =
2
DONT_CARE =
nil
DEFAULT_CONFIG =
<<-CSS_LINT_DEFAULT
  def self.ruleset_classifications
    {
      "adjoining-classes" => RubyCssLint::WARNING,
      "box-model" => RubyCssLint::WARNING,
      "box-sizing" => RubyCssLint::WARNING,
      "compatible-vendor-prefixes" => RubyCssLint::WARNING,
      "display-property-grouping" => RubyCssLint::WARNING,
      "duplicate-background-images" => RubyCssLint::WARNING,
      "duplicate-properties" => RubyCssLint::WARNING,
      "empty-rules" => RubyCssLint::WARNING,
      "errors" => RubyCssLint::WARNING,
      "fallback-colors" => RubyCssLint::WARNING,
      "floats" => RubyCssLint::WARNING,
      "font-faces" => RubyCssLint::WARNING,
      "font-sizes" => RubyCssLint::WARNING,
      "gradients" => RubyCssLint::WARNING,
      "ids" => RubyCssLint::WARNING,
      "import" => RubyCssLint::WARNING,
      "important" => RubyCssLint::WARNING,
      "known-properties" => RubyCssLint::WARNING,
      "outline-none" => RubyCssLint::WARNING,
      "overqualified-elements" => RubyCssLint::WARNING,
      "qualified-headings" => RubyCssLint::WARNING,
      "regex-selectors" => RubyCssLint::WARNING,
      "rules-count" => RubyCssLint::WARNING,
      "shorthand" => RubyCssLint::WARNING,
      "star-property-hack" => RubyCssLint::WARNING,
      "text-indent" => RubyCssLint::WARNING,
      "underscore-property-hack" => RubyCssLint::WARNING,
      "unique-headings" => RubyCssLint::WARNING,
      "universal-selector" => RubyCssLint::WARNING,
      "unqualified-attributes" => RubyCssLint::WARNING,
      "vendor-prefix" => RubyCssLint::WARNING,
      "zero-units" => RubyCssLint::WARNING,
    }
  end

  def self.location_of_custom_rules(rails_root)
    []
  end

  def self.location_of_css_files(rails_root)
    [rails_root.to_s+"/public/assets/application.css"]
  end

CSS_LINT_DEFAULT

Class Method Summary collapse

Class Method Details

.construct_error_and_warning_optionsObject



93
94
95
96
97
98
99
100
101
# File 'lib/ruby_css_lint.rb', line 93

def self.construct_error_and_warning_options
  rc = self.ruleset_classifications
  warnings = rc.keys.select{|k| rc[k] == RubyCssLint::WARNING}
  errors = rc.keys.select{|k| rc[k] == RubyCssLint::ERROR}
  result = " "
  result += "--warnings=#{warnings.join(',')} " if warnings.size > 0
  result += "--errors=#{errors.join(',')} " if errors.size > 0
  result
end

.construct_js_and_run_rhino(css_files, output_location = nil) ⇒ Object



103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
# File 'lib/ruby_css_lint.rb', line 103

def self.construct_js_and_run_rhino(css_files, output_location = nil)
  css_files = css_files.join(" ") if css_files.is_a?(Array)
  
  Tempfile.open("csslint_temp_js") do |tempfile|
    tempfile.puts <<-HEADER
var CSSLint = (function(){      
HEADER
    tempfile.puts`cat #{list_of_js_files_to_compile_step_1}`
    tempfile.puts <<-FOOTER
  return CSSLint;
})();
FOOTER
    tempfile.puts`cat #{list_of_js_files_to_compile_step_2}`
    tempfile.flush
    run_rhino_with_js_file(tempfile.path, css_files, output_location)
  end

  
end

.list_of_js_files_to_compile_step_1Object



131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
# File 'lib/ruby_css_lint.rb', line 131

def self.list_of_js_files_to_compile_step_1
  css_lint_root_directory = File.dirname(__FILE__) + "/../csslint/"
  
  parserlib_location = css_lint_root_directory + "/lib/parserlib.js"
  csslint_main_location = css_lint_root_directory + "/src/core/CSSLint.js"
  other_core_files = `ls -d #{(css_lint_root_directory+"/src/core/*.js")} | grep -v CSSLint`.split(/\n/).join(" ")
  built_in_rules_file = css_lint_root_directory + "/src/rules/*.js"

  custom_rules_files = location_of_custom_rules(Rails.root).join(" ")

  formatters = css_lint_root_directory + "/src/formatters/*.js"
  
  [
    parserlib_location, 
    csslint_main_location, 
    other_core_files, 
    built_in_rules_file, 
    custom_rules_files, 
    formatters
  ].join(" ")
end

.list_of_js_files_to_compile_step_2Object



153
154
155
156
157
158
159
160
161
162
# File 'lib/ruby_css_lint.rb', line 153

def self.list_of_js_files_to_compile_step_2
  css_lint_root_directory = File.dirname(__FILE__) + "/../csslint/"
  
  cli_common = css_lint_root_directory + "/src/cli/common.js"
  cli_rhino = css_lint_root_directory + "/src/cli/rhino.js"
  [
    cli_common,
    cli_rhino 
  ].join(" ")
end

.run_rhino_with_js_file(file, css_files, output_location = nil) ⇒ Object



123
124
125
126
127
128
129
# File 'lib/ruby_css_lint.rb', line 123

def self.run_rhino_with_js_file(file, css_files, output_location = nil)
  rhino_jarfile = File.dirname(__FILE__) + "/../js.jar"
  command = "java -jar #{rhino_jarfile} #{file} #{construct_error_and_warning_options} #{css_files}"
  command += " > #{output_location}" if output_location
  result = `#{command}`
  puts result
end