utility_palettes 0.1.1 → 1.0.1
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 +137 -123
- data/Rakefile +8 -8
- data/lib/generators/templates/config/utility_palettes.rb +55 -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 +83 -25
- data/lib/utility_palettes/defaults.rb +48 -46
- data/lib/utility_palettes/outputs.rb +126 -122
- data/lib/utility_palettes/palettes.rb +120 -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,126 @@
|
|
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
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
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
|
-
def self.
|
119
|
-
"
|
120
|
-
end
|
121
|
-
|
122
|
-
|
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
|
+
# TODO: sort by non-ASCII so that -50 is before -100 -> `naturally` gem
|
57
|
+
output_palettes.sort.to_h
|
58
|
+
end
|
59
|
+
|
60
|
+
def self.json(filename, output_palettes)
|
61
|
+
content = JSON.pretty_generate(output_palettes)
|
62
|
+
filepath = "#{filename}.json"
|
63
|
+
|
64
|
+
# Create directory if it doesn't exist
|
65
|
+
FileUtils.mkdir_p(File.dirname(filepath))
|
66
|
+
File.write(filepath, content)
|
67
|
+
|
68
|
+
puts 'Exporting utility palettes JSON...'
|
69
|
+
true
|
70
|
+
end
|
71
|
+
|
72
|
+
def self.scss(filename, output_palettes)
|
73
|
+
content = output_palettes.collect { |label, hex| "$#{label}: #{hex};" }.join("\n")
|
74
|
+
filepath = "#{filename}.scss"
|
75
|
+
|
76
|
+
# Create directory if it doesn't exist
|
77
|
+
FileUtils.mkdir_p(File.dirname(filepath))
|
78
|
+
File.write(filepath, content)
|
79
|
+
|
80
|
+
puts 'Exporting utility palettes SCSS...'
|
81
|
+
true
|
82
|
+
end
|
83
|
+
|
84
|
+
def self.css(filename, output_palettes)
|
85
|
+
content = ":root {\n\t#{output_palettes.collect { |label, hex| "--#{label}: #{hex};" }.join("\n\t")}\n}"
|
86
|
+
filepath = "#{filename}.css"
|
87
|
+
|
88
|
+
# Create directory if it doesn't exist
|
89
|
+
FileUtils.mkdir_p(File.dirname(filepath))
|
90
|
+
File.write(filepath, content)
|
91
|
+
|
92
|
+
puts 'Exporting utility palettes CSS...'
|
93
|
+
true
|
94
|
+
end
|
95
|
+
|
96
|
+
def bespoke_property_variables
|
97
|
+
# const utilities = {
|
98
|
+
# bg: (value) => ({ 'background-color': value }),
|
99
|
+
# text: (value) => ({ 'color': value }),
|
100
|
+
# border: (value) => ({ 'border-color': value }),
|
101
|
+
# 'border-t': (value) => ({ '--tw-border-opacity': 1, 'border-top-color': value }),
|
102
|
+
# 'border-r': (value) => ({ '--tw-border-opacity': 1, 'border-right-color': value }),
|
103
|
+
# 'border-b': (value) => ({ '--tw-border-opacity': 1, 'border-bottom-color': value }),
|
104
|
+
# 'border-l': (value) => ({ '--tw-border-opacity': 1, 'border-left-color': value }),
|
105
|
+
# outline: (value) => ({ 'outline-color': value }),
|
106
|
+
# ring: (value) => ({ '--tw-ring-opacity': 1, '--tw-ring-color': value }),
|
107
|
+
# 'ring-offset': (value) => ({ '--tw-ring-offset-color': value }),
|
108
|
+
# 'shadow': (value) => ({ '--tw-shadow-color': value, '--tw-shadow': 'var(--tw-shadow-colored)' }),
|
109
|
+
# accent: (value) => ({ 'accent-color': value }),
|
110
|
+
# caret: (value) => ({ 'caret-color': value }),
|
111
|
+
# fill: (value) => ({ 'fill': value }),
|
112
|
+
# stroke: (value) => ({ 'stroke': value }),
|
113
|
+
# };
|
114
|
+
end
|
115
|
+
|
116
|
+
private
|
117
|
+
|
118
|
+
def self.append_percentage(value)
|
119
|
+
"#{value}%"
|
120
|
+
end
|
121
|
+
|
122
|
+
def self.append_alpha(alpha)
|
123
|
+
"/ #{alpha * 100}"
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|
@@ -1,133 +1,120 @@
|
|
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
|
-
filename
|
53
|
-
filename
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
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
|
-
end
|
122
|
-
|
123
|
-
def self.format_palette(palettes)
|
124
|
-
palettes.compact_blank!
|
125
|
-
|
126
|
-
palettes.transform_keys!(&:to_s)
|
127
|
-
palettes.transform_keys! { |key| @config.dig(:output, :prefix) + key } if @config.dig(:output, :prefix).present?
|
128
|
-
palettes.transform_keys! { |key| key + @config.dig(:output, :suffix) } if @config.dig(:output, :suffix).present?
|
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 = configuration.output_filename
|
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
|
+
UtilityPalettes::Outputs.json(filename, output_palettes) if output_files.include?('json')
|
53
|
+
UtilityPalettes::Outputs.scss(filename, output_palettes) if output_files.include?('scss')
|
54
|
+
UtilityPalettes::Outputs.css(filename, output_palettes) if output_files.include?('css')
|
55
|
+
|
56
|
+
true
|
57
|
+
end
|
58
|
+
|
59
|
+
private
|
60
|
+
|
61
|
+
def self.colourize_values(basic_hash)
|
62
|
+
colourized_hash = {}
|
63
|
+
|
64
|
+
basic_hash.each do |label, colour|
|
65
|
+
begin
|
66
|
+
if colour.is_a?(String) && colour.start_with?('$')
|
67
|
+
# if the colour label begins with $ then it is a reference to a different defined colour, so must be looked up in the main
|
68
|
+
colourized_hash[label] = ColorConverters::Color.new(@combined_samples.dig(colour.slice(1..-1).to_sym))
|
69
|
+
else
|
70
|
+
colourized_hash[label] = ColorConverters::Color.new(colour)
|
71
|
+
end
|
72
|
+
|
73
|
+
# TODO
|
74
|
+
# provide a name if the label is left blank
|
75
|
+
# if label.to_s == '$blank'
|
76
|
+
# hash[colourized_hash[label].name] = hash.delete(label)
|
77
|
+
# puts "Blank colour #{colour} has been given the name: #{colourized_hash[label].name}"
|
78
|
+
# end
|
79
|
+
rescue ColorConverters::InvalidColorError => e
|
80
|
+
warn "Error processing colour #{label} with value #{colour}: #{e.message}"
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
colourized_hash
|
85
|
+
end
|
86
|
+
|
87
|
+
# * Palettes
|
88
|
+
|
89
|
+
# ? Multiple Colour's Palette
|
90
|
+
# 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
|
91
|
+
|
92
|
+
def self.palette_looper(colourized_hash, palette_type)
|
93
|
+
looped_generated_palettes = {}
|
94
|
+
|
95
|
+
colourized_hash.each do |label, base_colour|
|
96
|
+
# create a palette for a single colour from the providing mapping
|
97
|
+
if palette_type == 'absolutes'
|
98
|
+
generated_swatches = UtilityPalettes::Swatch.absolute_generator(label, base_colour)
|
99
|
+
elsif palette_type == 'relatives'
|
100
|
+
generated_swatches = UtilityPalettes::Swatch.relative_generator(label, base_colour)
|
101
|
+
end
|
102
|
+
|
103
|
+
# merge the colours absolute palette into the collective mapping
|
104
|
+
looped_generated_palettes.merge!(generated_swatches)
|
105
|
+
end
|
106
|
+
|
107
|
+
looped_generated_palettes
|
108
|
+
end
|
109
|
+
|
110
|
+
def self.format_palette(generated_hash)
|
111
|
+
configuration = UtilityPalettes.configuration
|
112
|
+
|
113
|
+
generated_hash.transform_keys!(&:to_s)
|
114
|
+
generated_hash.transform_keys! { |key| configuration.output_prefix + key } if configuration.output_prefix.present?
|
115
|
+
generated_hash.transform_keys! { |key| key + configuration.output_suffix } if configuration.output_suffix.present?
|
116
|
+
|
117
|
+
generated_hash
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|