utility_palettes 0.1.0 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +135 -123
- data/Rakefile +8 -8
- data/lib/generators/templates/config/utility_palettes.rb +54 -0
- data/lib/generators/utility_palettes/config_generator.rb +13 -13
- data/lib/generators/utility_palettes/generate_generator.rb +29 -35
- data/lib/utility_palettes/configuration.rb +82 -25
- data/lib/utility_palettes/defaults.rb +48 -46
- data/lib/utility_palettes/outputs.rb +122 -122
- data/lib/utility_palettes/palettes.rb +128 -133
- data/lib/utility_palettes/sequences.rb +88 -90
- data/lib/utility_palettes/swatch.rb +107 -108
- data/lib/utility_palettes/version.rb +5 -5
- data/lib/utility_palettes.rb +18 -16
- metadata +3 -4
- data/lib/generators/templates/config/utility_palettes.yml +0 -36
- data/lib/utility_palettes/validations.rb +0 -24
@@ -1,46 +1,48 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module UtilityPalettes
|
4
|
-
class Defaults
|
5
|
-
def self.absolutes
|
6
|
-
{
|
7
|
-
'red' => 'hsl(2, 78%, 64%)',
|
8
|
-
'rust' => 'hsl(16, 82%, 62%)',
|
9
|
-
'orange' => 'hsl(31, 90%, 65%)',
|
10
|
-
'gold' => 'hsl(46, 93%, 54%)',
|
11
|
-
'yellow' => 'hsl(58, 87%, 55%)',
|
12
|
-
'pear' => 'hsl(80, 74%, 57%)',
|
13
|
-
'green' => 'hsl(110, 69%, 58%)',
|
14
|
-
'seaside' => 'hsl(156, 78%, 57%)',
|
15
|
-
'cyan' => 'hsl(180, 69%, 37%)',
|
16
|
-
'capri' => 'hsl(197, 90%, 46%)',
|
17
|
-
'blue' => 'hsl(214, 78%, 36%)',
|
18
|
-
'iris' => 'hsl(265, 87%, 57%)',
|
19
|
-
'purple' => 'hsl(279, 85%, 56%)',
|
20
|
-
'magenta' => 'hsl(300, 64%, 66%)',
|
21
|
-
'pink' => 'hsl(320, 74%, 66%)',
|
22
|
-
'satin' => 'hsl(348, 74%, 57%)',
|
23
|
-
'cement' => 'hsl(42, 6%, 87%)',
|
24
|
-
'grey' => 'hsl(0, 3%, 46%)',
|
25
|
-
'base' => 'hsl(0, 3%, 46%)'
|
26
|
-
}
|
27
|
-
end
|
28
|
-
|
29
|
-
def self.relatives
|
30
|
-
{
|
31
|
-
'success' => 'hsl(110, 69%, 58%)',
|
32
|
-
'danger' => 'hsl(2, 78%, 64%)',
|
33
|
-
'information' => 'hsl(214, 78%, 36%)',
|
34
|
-
'warning' => 'hsl(46, 93%, 54%)'
|
35
|
-
}
|
36
|
-
end
|
37
|
-
|
38
|
-
def self.singles
|
39
|
-
{
|
40
|
-
'white' => '#fff',
|
41
|
-
'black' => '#000',
|
42
|
-
'translucent' => 'rgba(0, 0, 0, 0.45)'
|
43
|
-
}
|
44
|
-
end
|
45
|
-
|
46
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module UtilityPalettes
|
4
|
+
class Defaults
|
5
|
+
def self.absolutes
|
6
|
+
{
|
7
|
+
'red' => 'hsl(2, 78%, 64%)',
|
8
|
+
'rust' => 'hsl(16, 82%, 62%)',
|
9
|
+
'orange' => 'hsl(31, 90%, 65%)',
|
10
|
+
'gold' => 'hsl(46, 93%, 54%)',
|
11
|
+
'yellow' => 'hsl(58, 87%, 55%)',
|
12
|
+
'pear' => 'hsl(80, 74%, 57%)',
|
13
|
+
'green' => 'hsl(110, 69%, 58%)',
|
14
|
+
'seaside' => 'hsl(156, 78%, 57%)',
|
15
|
+
'cyan' => 'hsl(180, 69%, 37%)',
|
16
|
+
'capri' => 'hsl(197, 90%, 46%)',
|
17
|
+
'blue' => 'hsl(214, 78%, 36%)',
|
18
|
+
'iris' => 'hsl(265, 87%, 57%)',
|
19
|
+
'purple' => 'hsl(279, 85%, 56%)',
|
20
|
+
'magenta' => 'hsl(300, 64%, 66%)',
|
21
|
+
'pink' => 'hsl(320, 74%, 66%)',
|
22
|
+
'satin' => 'hsl(348, 74%, 57%)',
|
23
|
+
'cement' => 'hsl(42, 6%, 87%)',
|
24
|
+
'grey' => 'hsl(0, 3%, 46%)',
|
25
|
+
'base' => 'hsl(0, 3%, 46%)'
|
26
|
+
}
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.relatives
|
30
|
+
{
|
31
|
+
'success' => 'hsl(110, 69%, 58%)',
|
32
|
+
'danger' => 'hsl(2, 78%, 64%)',
|
33
|
+
'information' => 'hsl(214, 78%, 36%)',
|
34
|
+
'warning' => 'hsl(46, 93%, 54%)'
|
35
|
+
}
|
36
|
+
end
|
37
|
+
|
38
|
+
def self.singles
|
39
|
+
{
|
40
|
+
'white' => '#fff',
|
41
|
+
'black' => '#000',
|
42
|
+
'translucent' => 'rgba(0, 0, 0, 0.45)'
|
43
|
+
}
|
44
|
+
end
|
45
|
+
|
46
|
+
# TODO: add tailwind v4 absolutes
|
47
|
+
end
|
48
|
+
end
|
@@ -1,122 +1,122 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module UtilityPalettes
|
4
|
-
class Outputs
|
5
|
-
def self.generate(generated_palettes
|
6
|
-
output_format =
|
7
|
-
output_palettes = {}
|
8
|
-
|
9
|
-
generated_palettes.each do |label, colourize_colour|
|
10
|
-
case output_format
|
11
|
-
when 'rgb'
|
12
|
-
values = colourize_colour.rgb.values
|
13
|
-
when 'hsl'
|
14
|
-
values = colourize_colour.hsl.values
|
15
|
-
values[1] = self.append_percentage(values[1])
|
16
|
-
values[2] = self.append_percentage(values[2])
|
17
|
-
when 'hsv'
|
18
|
-
values = colourize_colour.hsv.values
|
19
|
-
values[1] = self.append_percentage(values[1])
|
20
|
-
values[2] = self.append_percentage(values[2])
|
21
|
-
when 'hsb'
|
22
|
-
values = colourize_colour.hsb.values
|
23
|
-
values[1] = self.append_percentage(values[1])
|
24
|
-
values[2] = self.append_percentage(values[2])
|
25
|
-
when 'cmyk'
|
26
|
-
values = colourize_colour.cmyk.values
|
27
|
-
values[1] = self.append_percentage(values[1])
|
28
|
-
values[2] = self.append_percentage(values[2])
|
29
|
-
values[3] = self.append_percentage(values[3])
|
30
|
-
output_format = 'device-cmyk'
|
31
|
-
when 'cielab', 'lab'
|
32
|
-
values = colourize_colour.cielab.values
|
33
|
-
values[0] = self.append_percentage(values[0])
|
34
|
-
output_format = 'lab'
|
35
|
-
when 'cielch', 'lch'
|
36
|
-
values = colourize_colour.cielch.values
|
37
|
-
values[0] = self.append_percentage(values[0])
|
38
|
-
output_format = 'lch'
|
39
|
-
when 'hex'
|
40
|
-
values = colourize_colour.hex
|
41
|
-
else
|
42
|
-
values = colourize_colour.rgb.values
|
43
|
-
output_format = 'rgb'
|
44
|
-
end
|
45
|
-
|
46
|
-
case output_format
|
47
|
-
when 'hex'
|
48
|
-
values += (colourize_colour.alpha * 255).round.to_s(16).slice(0, 2).upcase if colourize_colour.alpha < 1.0
|
49
|
-
output_palettes[label] = values
|
50
|
-
else
|
51
|
-
values << self.append_alpha(colourize_colour.alpha) if colourize_colour.alpha < 1.0
|
52
|
-
output_palettes[label] = "#{output_format}(#{values.join(' ')})"
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
output_palettes
|
57
|
-
end
|
58
|
-
|
59
|
-
def self.json(filename, output_palettes)
|
60
|
-
file = Tempfile.new([filename, '.json'])
|
61
|
-
|
62
|
-
File.open(file, 'w') do |f|
|
63
|
-
f.write(JSON.pretty_generate(output_palettes))
|
64
|
-
end
|
65
|
-
|
66
|
-
puts 'Exporting utility palettes JSON...'
|
67
|
-
file
|
68
|
-
end
|
69
|
-
|
70
|
-
def self.scss(filename, output_palettes)
|
71
|
-
file = Tempfile.new([filename, '.scss'])
|
72
|
-
|
73
|
-
File.open(file, 'w') do |f|
|
74
|
-
f.write(output_palettes.collect { |label, hex| "$#{label}: #{hex};" }.join("\n"))
|
75
|
-
end
|
76
|
-
|
77
|
-
puts 'Exporting utility palettes SCSS...'
|
78
|
-
file
|
79
|
-
end
|
80
|
-
|
81
|
-
def self.css(filename, output_palettes)
|
82
|
-
file = Tempfile.new([filename, '.css'])
|
83
|
-
|
84
|
-
File.open(file, 'w') do |f|
|
85
|
-
f.write(":root {\n\t#{output_palettes.collect { |label, hex| "--#{label}: #{hex};" }.join("\n\t")}\n}")
|
86
|
-
end
|
87
|
-
|
88
|
-
puts 'Exporting utility palettes CSS...'
|
89
|
-
file
|
90
|
-
end
|
91
|
-
|
92
|
-
def bespoke_property_variables
|
93
|
-
# const utilities = {
|
94
|
-
# bg: (value) => ({ 'background-color': value }),
|
95
|
-
# text: (value) => ({ 'color': value }),
|
96
|
-
# border: (value) => ({ 'border-color': value }),
|
97
|
-
# 'border-t': (value) => ({ '--tw-border-opacity': 1, 'border-top-color': value }),
|
98
|
-
# 'border-r': (value) => ({ '--tw-border-opacity': 1, 'border-right-color': value }),
|
99
|
-
# 'border-b': (value) => ({ '--tw-border-opacity': 1, 'border-bottom-color': value }),
|
100
|
-
# 'border-l': (value) => ({ '--tw-border-opacity': 1, 'border-left-color': value }),
|
101
|
-
# outline: (value) => ({ 'outline-color': value }),
|
102
|
-
# ring: (value) => ({ '--tw-ring-opacity': 1, '--tw-ring-color': value }),
|
103
|
-
# 'ring-offset': (value) => ({ '--tw-ring-offset-color': value }),
|
104
|
-
# 'shadow': (value) => ({ '--tw-shadow-color': value, '--tw-shadow': 'var(--tw-shadow-colored)' }),
|
105
|
-
# accent: (value) => ({ 'accent-color': value }),
|
106
|
-
# caret: (value) => ({ 'caret-color': value }),
|
107
|
-
# fill: (value) => ({ 'fill': value }),
|
108
|
-
# stroke: (value) => ({ 'stroke': value }),
|
109
|
-
# };
|
110
|
-
end
|
111
|
-
|
112
|
-
private
|
113
|
-
|
114
|
-
def self.append_percentage(value)
|
115
|
-
"#{value}%"
|
116
|
-
end
|
117
|
-
|
118
|
-
def self.append_alpha(alpha)
|
119
|
-
"/ #{alpha * 100}"
|
120
|
-
end
|
121
|
-
end
|
122
|
-
end
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module UtilityPalettes
|
4
|
+
class Outputs
|
5
|
+
def self.generate(generated_palettes)
|
6
|
+
output_format = UtilityPalettes.configuration.output_format.to_s.downcase.presence
|
7
|
+
output_palettes = {}
|
8
|
+
|
9
|
+
generated_palettes.each do |label, colourize_colour|
|
10
|
+
case output_format
|
11
|
+
when 'rgb'
|
12
|
+
values = colourize_colour.rgb.values
|
13
|
+
when 'hsl'
|
14
|
+
values = colourize_colour.hsl.values
|
15
|
+
values[1] = self.append_percentage(values[1])
|
16
|
+
values[2] = self.append_percentage(values[2])
|
17
|
+
when 'hsv'
|
18
|
+
values = colourize_colour.hsv.values
|
19
|
+
values[1] = self.append_percentage(values[1])
|
20
|
+
values[2] = self.append_percentage(values[2])
|
21
|
+
when 'hsb'
|
22
|
+
values = colourize_colour.hsb.values
|
23
|
+
values[1] = self.append_percentage(values[1])
|
24
|
+
values[2] = self.append_percentage(values[2])
|
25
|
+
when 'cmyk'
|
26
|
+
values = colourize_colour.cmyk.values
|
27
|
+
values[1] = self.append_percentage(values[1])
|
28
|
+
values[2] = self.append_percentage(values[2])
|
29
|
+
values[3] = self.append_percentage(values[3])
|
30
|
+
output_format = 'device-cmyk'
|
31
|
+
when 'cielab', 'lab'
|
32
|
+
values = colourize_colour.cielab.values
|
33
|
+
values[0] = self.append_percentage(values[0])
|
34
|
+
output_format = 'lab'
|
35
|
+
when 'cielch', 'lch'
|
36
|
+
values = colourize_colour.cielch.values
|
37
|
+
values[0] = self.append_percentage(values[0])
|
38
|
+
output_format = 'lch'
|
39
|
+
when 'hex'
|
40
|
+
values = colourize_colour.hex
|
41
|
+
else
|
42
|
+
values = colourize_colour.rgb.values
|
43
|
+
output_format = 'rgb'
|
44
|
+
end
|
45
|
+
|
46
|
+
case output_format
|
47
|
+
when 'hex'
|
48
|
+
values += (colourize_colour.alpha * 255).round.to_s(16).slice(0, 2).upcase if colourize_colour.alpha < 1.0
|
49
|
+
output_palettes[label] = values
|
50
|
+
else
|
51
|
+
values << self.append_alpha(colourize_colour.alpha) if colourize_colour.alpha < 1.0
|
52
|
+
output_palettes[label] = "#{output_format}(#{values.join(' ')})"
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
output_palettes
|
57
|
+
end
|
58
|
+
|
59
|
+
def self.json(filename, output_palettes)
|
60
|
+
file = Tempfile.new([filename, '.json'])
|
61
|
+
|
62
|
+
File.open(file, 'w') do |f|
|
63
|
+
f.write(JSON.pretty_generate(output_palettes))
|
64
|
+
end
|
65
|
+
|
66
|
+
puts 'Exporting utility palettes JSON...'
|
67
|
+
file
|
68
|
+
end
|
69
|
+
|
70
|
+
def self.scss(filename, output_palettes)
|
71
|
+
file = Tempfile.new([filename, '.scss'])
|
72
|
+
|
73
|
+
File.open(file, 'w') do |f|
|
74
|
+
f.write(output_palettes.collect { |label, hex| "$#{label}: #{hex};" }.join("\n"))
|
75
|
+
end
|
76
|
+
|
77
|
+
puts 'Exporting utility palettes SCSS...'
|
78
|
+
file
|
79
|
+
end
|
80
|
+
|
81
|
+
def self.css(filename, output_palettes)
|
82
|
+
file = Tempfile.new([filename, '.css'])
|
83
|
+
|
84
|
+
File.open(file, 'w') do |f|
|
85
|
+
f.write(":root {\n\t#{output_palettes.collect { |label, hex| "--#{label}: #{hex};" }.join("\n\t")}\n}")
|
86
|
+
end
|
87
|
+
|
88
|
+
puts 'Exporting utility palettes CSS...'
|
89
|
+
file
|
90
|
+
end
|
91
|
+
|
92
|
+
def bespoke_property_variables
|
93
|
+
# const utilities = {
|
94
|
+
# bg: (value) => ({ 'background-color': value }),
|
95
|
+
# text: (value) => ({ 'color': value }),
|
96
|
+
# border: (value) => ({ 'border-color': value }),
|
97
|
+
# 'border-t': (value) => ({ '--tw-border-opacity': 1, 'border-top-color': value }),
|
98
|
+
# 'border-r': (value) => ({ '--tw-border-opacity': 1, 'border-right-color': value }),
|
99
|
+
# 'border-b': (value) => ({ '--tw-border-opacity': 1, 'border-bottom-color': value }),
|
100
|
+
# 'border-l': (value) => ({ '--tw-border-opacity': 1, 'border-left-color': value }),
|
101
|
+
# outline: (value) => ({ 'outline-color': value }),
|
102
|
+
# ring: (value) => ({ '--tw-ring-opacity': 1, '--tw-ring-color': value }),
|
103
|
+
# 'ring-offset': (value) => ({ '--tw-ring-offset-color': value }),
|
104
|
+
# 'shadow': (value) => ({ '--tw-shadow-color': value, '--tw-shadow': 'var(--tw-shadow-colored)' }),
|
105
|
+
# accent: (value) => ({ 'accent-color': value }),
|
106
|
+
# caret: (value) => ({ 'caret-color': value }),
|
107
|
+
# fill: (value) => ({ 'fill': value }),
|
108
|
+
# stroke: (value) => ({ 'stroke': value }),
|
109
|
+
# };
|
110
|
+
end
|
111
|
+
|
112
|
+
private
|
113
|
+
|
114
|
+
def self.append_percentage(value)
|
115
|
+
"#{value}%"
|
116
|
+
end
|
117
|
+
|
118
|
+
def self.append_alpha(alpha)
|
119
|
+
"/ #{alpha * 100}"
|
120
|
+
end
|
121
|
+
end
|
122
|
+
end
|
@@ -1,133 +1,128 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module UtilityPalettes
|
4
|
-
class Palettes
|
5
|
-
def self.generate
|
6
|
-
|
7
|
-
|
8
|
-
puts 'Generating utility palettes...'
|
9
|
-
|
10
|
-
UtilityPalettes::
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
file =
|
58
|
-
file
|
59
|
-
|
60
|
-
|
61
|
-
file =
|
62
|
-
file
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
#
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
palettes
|
131
|
-
end
|
132
|
-
end
|
133
|
-
end
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module UtilityPalettes
|
4
|
+
class Palettes
|
5
|
+
def self.generate
|
6
|
+
configuration = UtilityPalettes.configuration
|
7
|
+
|
8
|
+
puts 'Generating utility palettes...'
|
9
|
+
|
10
|
+
default_absolutes = configuration.use_default_absolutes == true ? UtilityPalettes::Defaults.absolutes : {}
|
11
|
+
default_relatives = configuration.use_default_relatives == true ? UtilityPalettes::Defaults.relatives : {}
|
12
|
+
default_singles = configuration.use_default_singles == true ? UtilityPalettes::Defaults.singles : {}
|
13
|
+
|
14
|
+
puts 'Defined default palettes...'
|
15
|
+
|
16
|
+
user_absolutes = configuration.absolutes
|
17
|
+
user_relatives = configuration.relatives
|
18
|
+
user_singles = configuration.singles
|
19
|
+
|
20
|
+
puts 'Retrieved user palettes...'
|
21
|
+
|
22
|
+
# merging should mean any user colours will overwrite default colours with the same key names
|
23
|
+
combined_absolutes = default_absolutes.merge(user_absolutes)
|
24
|
+
combined_relatives = default_relatives.merge(user_relatives)
|
25
|
+
combined_singles = {}.merge(default_absolutes, user_absolutes, default_singles, user_singles)
|
26
|
+
|
27
|
+
@combined_samples = combined_absolutes.merge(combined_relatives).merge(combined_singles)
|
28
|
+
|
29
|
+
puts 'Merged palettes...'
|
30
|
+
|
31
|
+
converted_absolutes = self.colourize_values(combined_absolutes)
|
32
|
+
converted_relatives = self.colourize_values(combined_relatives)
|
33
|
+
converted_singles = self.colourize_values(combined_singles)
|
34
|
+
|
35
|
+
puts 'Converted palettes...'
|
36
|
+
|
37
|
+
generated_absolutes = self.palette_looper(converted_absolutes, 'absolutes')
|
38
|
+
generated_relatives = self.palette_looper(converted_relatives, 'relatives')
|
39
|
+
generated_singles = converted_singles
|
40
|
+
|
41
|
+
puts 'Generated utility palettes...'
|
42
|
+
|
43
|
+
generated_palettes = {}.merge(generated_absolutes, generated_relatives, generated_singles)
|
44
|
+
generated_palettes = self.format_palette(generated_palettes)
|
45
|
+
output_palettes = UtilityPalettes::Outputs.generate(generated_palettes)
|
46
|
+
|
47
|
+
filename = 'utility_palettes'
|
48
|
+
filename += "-#{Time.zone.now.strftime('%Y%m%d-%H%M%S')}" if configuration.output_dated == true
|
49
|
+
|
50
|
+
output_files = configuration.output_files.map(&:strip)
|
51
|
+
|
52
|
+
file = nil
|
53
|
+
file = UtilityPalettes::Outputs.json(filename, output_palettes) if output_files.include?('json')
|
54
|
+
File.rename(file.path, "#{filename}.json") if file.present?
|
55
|
+
|
56
|
+
file = nil
|
57
|
+
file = UtilityPalettes::Outputs.scss(filename, output_palettes) if output_files.include?('scss')
|
58
|
+
File.rename(file.path, "app/assets/stylesheets/#{filename}.scss") if file.present?
|
59
|
+
|
60
|
+
file = nil
|
61
|
+
file = UtilityPalettes::Outputs.css(filename, output_palettes) if output_files.include?('css')
|
62
|
+
File.rename(file.path, "app/assets/stylesheets/#{filename}.css") if file.present?
|
63
|
+
|
64
|
+
true
|
65
|
+
end
|
66
|
+
|
67
|
+
private
|
68
|
+
|
69
|
+
def self.colourize_values(basic_hash)
|
70
|
+
colourized_hash = {}
|
71
|
+
|
72
|
+
basic_hash.each do |label, colour|
|
73
|
+
begin
|
74
|
+
if colour.is_a?(String) && colour.start_with?('$')
|
75
|
+
# if the colour label begins with $ then it is a reference to a different defined colour, so must be looked up in the main
|
76
|
+
colourized_hash[label] = ColorConverters::Color.new(@combined_samples.dig(colour.slice(1..-1).to_sym))
|
77
|
+
else
|
78
|
+
colourized_hash[label] = ColorConverters::Color.new(colour)
|
79
|
+
end
|
80
|
+
|
81
|
+
# TODO
|
82
|
+
# provide a name if the label is left blank
|
83
|
+
# if label.to_s == '$blank'
|
84
|
+
# hash[colourized_hash[label].name] = hash.delete(label)
|
85
|
+
# puts "Blank colour #{colour} has been given the name: #{colourized_hash[label].name}"
|
86
|
+
# end
|
87
|
+
rescue ColorConverters::InvalidColorError => e
|
88
|
+
warn "Error processing colour #{label} with value #{colour}: #{e.message}"
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
colourized_hash
|
93
|
+
end
|
94
|
+
|
95
|
+
# * Palettes
|
96
|
+
|
97
|
+
# ? Multiple Colour's Palette
|
98
|
+
# a function to loop through a map of colours and create absolute or relative palettes for them all and collect this into a single map
|
99
|
+
|
100
|
+
def self.palette_looper(colourized_hash, palette_type)
|
101
|
+
looped_generated_palettes = {}
|
102
|
+
|
103
|
+
colourized_hash.each do |label, base_colour|
|
104
|
+
# create a palette for a single colour from the providing mapping
|
105
|
+
if palette_type == 'absolutes'
|
106
|
+
generated_swatches = UtilityPalettes::Swatch.absolute_generator(label, base_colour)
|
107
|
+
elsif palette_type == 'relatives'
|
108
|
+
generated_swatches = UtilityPalettes::Swatch.relative_generator(label, base_colour)
|
109
|
+
end
|
110
|
+
|
111
|
+
# merge the colours absolute palette into the collective mapping
|
112
|
+
looped_generated_palettes.merge!(generated_swatches)
|
113
|
+
end
|
114
|
+
|
115
|
+
looped_generated_palettes
|
116
|
+
end
|
117
|
+
|
118
|
+
def self.format_palette(generated_hash)
|
119
|
+
configuration = UtilityPalettes.configuration
|
120
|
+
|
121
|
+
generated_hash.transform_keys!(&:to_s)
|
122
|
+
generated_hash.transform_keys! { |key| configuration.output_prefix + key } if configuration.output_prefix.present?
|
123
|
+
generated_hash.transform_keys! { |key| key + configuration.output_suffix } if configuration.output_suffix.present?
|
124
|
+
|
125
|
+
generated_hash
|
126
|
+
end
|
127
|
+
end
|
128
|
+
end
|