Class: SeeLessEssEss::Checker

Inherits:
Object
  • Object
show all
Defined in:
lib/see-less-ess-ess.rb

Instance Method Summary collapse

Constructor Details

#initialize(extractor, used_classes) ⇒ Checker

Returns a new instance of Checker.



59
60
61
62
# File 'lib/see-less-ess-ess.rb', line 59

def initialize(extractor, used_classes)
  @extractor = extractor
  @used_classes = used_classes
end

Instance Method Details

#css_classes_whitelistObject



83
84
85
# File 'lib/see-less-ess-ess.rb', line 83

def css_classes_whitelist
  @class_whitelist ||= @extractor.css_classes + @used_classes
end

#does_not_use(sequence) ⇒ Object



64
65
66
67
68
69
70
71
# File 'lib/see-less-ess-ess.rb', line 64

def does_not_use(sequence)
  selectors = sequence.members.reject { |s| s.is_a?(String) }
  selectors.any? do |selector|
    selector.members.any? do |simple|
      unused(simple)
    end
  end
end

#html_tags_whitelistObject



86
87
88
# File 'lib/see-less-ess-ess.rb', line 86

def html_tags_whitelist
  @tag_whitelist ||= @extractor.html_tags
end

#unused(simple) ⇒ Object



73
74
75
76
77
78
79
80
81
# File 'lib/see-less-ess-ess.rb', line 73

def unused(simple)
  if simple.is_a?(Sass::Selector::Class)
    !css_classes_whitelist.include?(simple.name[0].to_s)
  elsif simple.is_a?(Sass::Selector::Element)
    !html_tags_whitelist.include?(simple.name[0].to_s)
  else
    false
  end
end