Class: SCSSLint::AutoCorrect::Correctors::UseHexInsteadOfColorKeywords
- Inherits:
-
Base
- Object
- Base
- SCSSLint::AutoCorrect::Correctors::UseHexInsteadOfColorKeywords
show all
- Defined in:
- lib/scss_lint/auto_correct/correctors/use_hex_instead_of_color_keywords.rb
Instance Attribute Summary
Attributes inherited from Base
#config
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Base
#enabled?, #initialize, short_name
Class Method Details
.data ⇒ Object
12
13
14
15
16
|
# File 'lib/scss_lint/auto_correct/correctors/use_hex_instead_of_color_keywords.rb', line 12
def self.data
return @data if @data
colors_file = File.expand_path(File.join(File.dirname(__FILE__), "color-keywords.csv"))
@data = Hash[File.read(colors_file).lines.map { |l| l.gsub("\n", '').split(',') }]
end
|
.description ⇒ Object
18
19
20
|
# File 'lib/scss_lint/auto_correct/correctors/use_hex_instead_of_color_keywords.rb', line 18
def self.description
"Replace named colors with their hex values"
end
|
.linter_name ⇒ Object
26
27
28
|
# File 'lib/scss_lint/auto_correct/correctors/use_hex_instead_of_color_keywords.rb', line 26
def self.linter_name
"ColorKeyword"
end
|
.priority ⇒ Object
22
23
24
|
# File 'lib/scss_lint/auto_correct/correctors/use_hex_instead_of_color_keywords.rb', line 22
def self.priority
5
end
|
Instance Method Details
#call(contents) ⇒ Object
3
4
5
6
7
8
9
10
|
# File 'lib/scss_lint/auto_correct/correctors/use_hex_instead_of_color_keywords.rb', line 3
def call(contents)
colors = self.class.data
regexp = Regexp.new("^([^\/]+ )(#{colors.keys.join('|')})([\) ;].*)$")
contents.gsub(regexp) do
Regexp.last_match[1] + colors[Regexp.last_match[2]] + Regexp.last_match[3]
end
end
|