Class: CSSLint::Lint

Inherits:
Object
  • Object
show all
Defined in:
lib/css_lint.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Lint

Returns a new instance of Lint.



8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/css_lint.rb', line 8

def initialize(*args)
  @gem_vendor_dir = File.join(File.dirname(__FILE__), 'vendor')
  if args.empty?
    @css = error_message
  else
    @args = []
    @css = []
    args.each do |arg|
      arg.start_with?("--") ? @args << arg : @css << arg
    end
  end
end

Instance Attribute Details

#argsObject (readonly)

Returns the value of attribute args.



4
5
6
# File 'lib/css_lint.rb', line 4

def args
  @args
end

#cssObject (readonly)

Returns the value of attribute css.



5
6
7
# File 'lib/css_lint.rb', line 5

def css
  @css
end

#gem_vendor_dirObject (readonly)

Returns the value of attribute gem_vendor_dir.



3
4
5
# File 'lib/css_lint.rb', line 3

def gem_vendor_dir
  @gem_vendor_dir
end

#optionsObject (readonly)

Returns the value of attribute options.



6
7
8
# File 'lib/css_lint.rb', line 6

def options
  @options
end

Instance Method Details

#error_messageObject



33
34
35
# File 'lib/css_lint.rb', line 33

def error_message
  'Must provide css_lint a CSS file or directory'
end

#execute(*compass_options) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
# File 'lib/css_lint.rb', line 21

def execute(*compass_options)
  if @css == error_message
    puts @css
  else
    if !compass_options.empty?
      run_lint(*compass_options)
    else
      run_lint(@args)
    end
  end
end

#get_java_pathObject



37
38
39
# File 'lib/css_lint.rb', line 37

def get_java_path
  `which java`.to_s.rstrip
end

#run_lint(*options) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/css_lint.rb', line 41

def run_lint(*options)
  java_path = get_java_path
  raise "You do not have a Java installed, but it is required." unless java_path && !java_path.empty?
  
  options.empty? ? @options = '' : @options = options.join(' ') + ' '

  if !@css.empty?
    @css.each do |item|
      system("java -jar #{@gem_vendor_dir}/js.jar #{@gem_vendor_dir}/csslint-rhino.js #{@options}#{item}")
    end
  else
    system("java -jar #{@gem_vendor_dir}/js.jar #{@gem_vendor_dir}/csslint-rhino.js #{@options}")
  end
end