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 =
"  def self.ruleset_classifications\n    {\n      \"adjoining-classes\" => RubyCssLint::WARNING,\n      \"box-model\" => RubyCssLint::WARNING,\n      \"box-sizing\" => RubyCssLint::WARNING,\n      \"compatible-vendor-prefixes\" => RubyCssLint::WARNING,\n      \"display-property-grouping\" => RubyCssLint::WARNING,\n      \"duplicate-background-images\" => RubyCssLint::WARNING,\n      \"duplicate-properties\" => RubyCssLint::WARNING,\n      \"empty-rules\" => RubyCssLint::WARNING,\n      \"errors\" => RubyCssLint::WARNING,\n      \"fallback-colors\" => RubyCssLint::WARNING,\n      \"floats\" => RubyCssLint::WARNING,\n      \"font-faces\" => RubyCssLint::WARNING,\n      \"font-sizes\" => RubyCssLint::WARNING,\n      \"gradients\" => RubyCssLint::WARNING,\n      \"ids\" => RubyCssLint::WARNING,\n      \"import\" => RubyCssLint::WARNING,\n      \"important\" => RubyCssLint::WARNING,\n      \"known-properties\" => RubyCssLint::WARNING,\n      \"outline-none\" => RubyCssLint::WARNING,\n      \"overqualified-elements\" => RubyCssLint::WARNING,\n      \"qualified-headings\" => RubyCssLint::WARNING,\n      \"regex-selectors\" => RubyCssLint::WARNING,\n      \"rules-count\" => RubyCssLint::WARNING,\n      \"shorthand\" => RubyCssLint::WARNING,\n      \"star-property-hack\" => RubyCssLint::WARNING,\n      \"text-indent\" => RubyCssLint::WARNING,\n      \"underscore-property-hack\" => RubyCssLint::WARNING,\n      \"unique-headings\" => RubyCssLint::WARNING,\n      \"universal-selector\" => RubyCssLint::WARNING,\n      \"unqualified-attributes\" => RubyCssLint::WARNING,\n      \"vendor-prefix\" => RubyCssLint::WARNING,\n      \"zero-units\" => RubyCssLint::WARNING,\n    }\n  end\n\n  def self.location_of_custom_rules(rails_root)\n    []\n  end\n\n  def self.location_of_css_files(rails_root)\n    [rails_root.to_s+\"/public/assets/application.css\"]\n  end\n\n"

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 "var CSSLint = (function(){      \n"
    tempfile.puts`cat #{list_of_js_files_to_compile_step_1}`
    tempfile.puts "  return CSSLint;\n})();\n"
    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