utility_palettes 1.0.5 → 1.0.6

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 23332faf82c72ba20e4cf27ddfd3d9f1518b78b2f94ebc561fe69a5e881f2743
4
- data.tar.gz: 2f636967a325e694deb98ec7960dff63d62bfce4c25dd966452ccb288cca9f4d
3
+ metadata.gz: 1d8f31793c6a4e60c252482c30055502d70144de5bed9d23df9de024db4368f1
4
+ data.tar.gz: 5ced674f30ca462a559654de7316a3b62613fbbad08e491f1869c2d7c7c9e9d6
5
5
  SHA512:
6
- metadata.gz: 71f73653beeb5ccb1566dd1561510de4f53cb91c35271a2a7c80658783c0e20f0f9cb93facf97c16bf15e7a7e7ab48db80084d0e5e030be01584c303328f9d6b
7
- data.tar.gz: 34499831e9976f15d273c626506adfc3083ad563553b4639f1376967565fefdd6e31f6dd4ba692b4515a0006c8d38433be59bd15eabbeb6893a93d16345850da
6
+ metadata.gz: abbf9cf347cf917305600ee6c8a844a2775a55e33e4e03021780c944a8b8c11063c5f009ef6c22f878d8f88b613675af47a4db6bdb55ddc069d6aed70784077b
7
+ data.tar.gz: 355f1c3c73f49348332ea1f65fcf72a0ca1ab0f18b6491973f5c773e14948c8f21b9764563c0f888471fe52d77b41d63b09dfc503be2a486f7c467cedcfae7e7
data/README.md CHANGED
@@ -1,138 +1,138 @@
1
- # UtilityPalettes
2
-
3
- ![Static Badge](https://img.shields.io/badge/Gem_Version-1.0.5-blue)
4
- [![Static Badge](https://img.shields.io/badge/RubyGems-red)](https://rubygems.org/gems/utility_palettes)
5
-
6
- > Generate your own colour palettes in an instance.
7
-
8
- Utility Palettes is an ruby gem package for use in ruby or other projects that generates palettes and shades based on supplied colours.
9
- Take a single colour and generate a full tailwind-style set of "absolute" shades ranging from -50 to -900 where the given colour is inserted into the range where it suits best.
10
- Or generate "relative" shades that have the supplied colour at it's core and add a -light and -dark shade.
11
-
12
- ## Installation
13
-
14
- Install the gem and add to the application's Gemfile by executing:
15
-
16
- ```bash
17
- bundle add utility_palettes
18
- ```
19
-
20
- If bundler is not being used to manage dependencies, install the gem by executing:
21
-
22
- ```bash
23
- gem install utility_palettes
24
- ```
25
-
26
- ## Usage
27
-
28
- To get the config file:
29
-
30
- ```bash
31
- rails generate utility_palettes:config
32
- ```
33
-
34
- To generate the palettes:
35
-
36
- ```bash
37
- rails generate utility_palettes:generate
38
- ```
39
-
40
- ## Configuration
41
-
42
- >[!NOTE]
43
- > UtilityPalettes has moved to a Ruby Config file so if you used the YML config previously you will need to migrate off that now.
44
- > Run `rails generate utility_palettes:config` to get the new config and move your values across.
45
- > Most keys have stayed the same apart from some prepends and the `enable_environments` key which determines what environments code can be run in.
46
-
47
- ### Environment
48
-
49
- Set the environment that the sub-data will be read in, meaning that the palette generator can only be run in certain environments.
50
-
51
- | Option | Default | Value Type | Possible Values |
52
- | :------------------- | :------------: | :--------: | :--------------------: |
53
- | enable_environments | [:development] | Array | <any Rails.env symbol> |
54
-
55
- ### Defaults
56
-
57
- Should the default colours be included for the palette generator. Even if they are included, they can be overwritten by the user's own colour of the same name:
58
-
59
- | Option | Default | Value Type | Possible Values |
60
- | :---------------- | :-----: | :--------: | :-------------: |
61
- | default_absolutes | true | Boolean | true / false |
62
- | default_relatives | true | Boolean | true / false |
63
- | default_singles | true | Boolean | true / false |
64
-
65
- ### Output
66
-
67
- How the output file and values should be written:
68
-
69
- | Option | Description | Default | Value Type | Possible Values |
70
- | :------------ | :-------------------------------------------------------------------------------- | :----------------: | :--------: | :-----------------------------------------------------: |
71
- | ouput_filename | Where the file should be output to including filename, without the file extension | 'utility_palettes' | String | <any filepath string> |
72
- | ouput_dated | Should a timestamp be included in the filenames | false | Boolean | true / false |
73
- | ouput_files | The types of files the palette should be output in | ['scss'] | Array | json, scss, css |
74
- | ouput_format | The colour syntax the output colours should be written in | hex | String | rgb, hsl, hsv, hsb, cmyk, cielab, lab, cielch, lch, hex |
75
- | ouput_prefix | A string that is appended to the start of all colour names, i.e. 'up-' | nil | String | <any string> |
76
- | ouput_suffix | A string that is appended to the end of all colour names, i.e. '-col' | nil | String | <any string> |
77
-
78
- ### Method (WIP)
79
-
80
- It allows you to determine how you want the colours to be adjusted to create the variance in your palette, but for now all colour adjustments are made by changing the HSL values as it is the best combination of the simple yet effective and accurate method available.
81
- In the future you will be able to shift the colours by changing values for different colour models and colour spaces; like RGB, CieLAB, OkLCH and others.
82
-
83
- | Option | Description | Default | Value Type | Possible Values |
84
- | :------- | :----------------------------------------------- | :-----: | :--------: | :-------------: |
85
- | method | What colour space to adjust the colour values in | 'hsl' | String | hsl |
86
-
87
- ### Steps (WIP)
88
-
89
- Defines the percentage you want each colour to be adjusted by when moving through the colour palette. For now all steps are for the HSL method of adjusting colours
90
- In the future you will be able to shift the colours by changing values for different colour models and colour spaces; like RGB, CieLAB, OkLCH and others.
91
-
92
- | Option | Description | Default | Possible Values |
93
- | :------ | :----------------------------------: | :-----: | :-------------: |
94
- | steps_h | How much to adjust the hue by | 0 | 0 - 100 |
95
- | steps_s | How much to adjust the saturation by | 3 | 0 - 100 |
96
- | steps_l | How much to adjust the lightness by | 8 | 0 - 100 |
97
-
98
- ### Colours
99
-
100
- You can define colour names and values that you would like to create an "absolute palette"; where for each colour given, a range of colours are output with -50, -100, ..., -900 suffixes using that colour as the base.
101
-
102
- You can define colour names and values that you would like to create an "relative palette"; where for each colour given, a -light and -dark colour are generated one step up and down from the base colour.
103
- If a colour is included in both the "absolutes" and "relatives" sections, then the -light and -dark colours will match with colours in the absolute palette.
104
-
105
- You can define colour names and values that you would like copied directly to the output as you have defined them.
106
-
107
- All these options all colours to be passed in the same way; as a hash.
108
- The key is the base name of the colour.
109
- The value can be;
110
-
111
- - a string such as '#ff0000' or 'rgb(51, 102, 204)',
112
- - a hash of colour space keys and values such as { r: 51, g: 102, b: 204 } or { h: 30, s: 50, l: 75 },
113
- - a 'reference' to a colour the is also defined in one of your config be using that colour name as the value but prepended with '$', such as '$red' (this felt useful if there are colours if you re-use the same colours under different use names)
114
- - currently you can only reference colours defined in the config, not colours that would be generated as part of the palette generator process
115
-
116
- | Option | Default | Possible Values |
117
- | :-------- | :-----: | :-----------------------------------: |
118
- | absolutes | {} | { '<colour name>' => <colour value> } |
119
- | relatives | {} | { '<colour name>' => <colour value> } |
120
- | singles | {} | { '<colour name>' => <colour value> } |
121
-
122
- ## Development
123
-
124
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
125
-
126
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
127
-
128
- ## Contributing
129
-
130
- Bug reports and pull requests are welcome on GitHub at <https://github.com/louiswdavis/utility_palettes>. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/louiswdavis/utility_palettes/blob/master/CODE_OF_CONDUCT.md).
131
-
132
- ## License
133
-
134
- The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
135
-
136
- ## Code of Conduct
137
-
138
- Everyone interacting in the UtilityPalettes project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/louiswdavis/utility_palettes/blob/master/CODE_OF_CONDUCT.md).
1
+ # UtilityPalettes
2
+
3
+ ![Static Badge](https://img.shields.io/badge/Gem_Version-1.0.6-blue)
4
+ [![Static Badge](https://img.shields.io/badge/RubyGems-red)](https://rubygems.org/gems/utility_palettes)
5
+
6
+ > Generate your own colour palettes in an instance.
7
+
8
+ Utility Palettes is an ruby gem package for use in ruby or other projects that generates palettes and shades based on supplied colours.
9
+ Take a single colour and generate a full tailwind-style set of "absolute" shades ranging from -50 to -900 where the given colour is inserted into the range where it suits best.
10
+ Or generate "relative" shades that have the supplied colour at it's core and add a -light and -dark shade.
11
+
12
+ ## Installation
13
+
14
+ Install the gem and add to the application's Gemfile by executing:
15
+
16
+ ```bash
17
+ bundle add utility_palettes
18
+ ```
19
+
20
+ If bundler is not being used to manage dependencies, install the gem by executing:
21
+
22
+ ```bash
23
+ gem install utility_palettes
24
+ ```
25
+
26
+ ## Usage
27
+
28
+ To get the config file:
29
+
30
+ ```bash
31
+ rails generate utility_palettes:config
32
+ ```
33
+
34
+ To generate the palettes:
35
+
36
+ ```bash
37
+ rails generate utility_palettes:generate
38
+ ```
39
+
40
+ ## Configuration
41
+
42
+ >[!NOTE]
43
+ > UtilityPalettes has moved to a Ruby Config file so if you used the YML config previously you will need to migrate off that now.
44
+ > Run `rails generate utility_palettes:config` to get the new config and move your values across.
45
+ > Most keys have stayed the same apart from some prepends and the `enable_environments` key which determines what environments code can be run in.
46
+
47
+ ### Environment
48
+
49
+ Set the environment that the sub-data will be read in, meaning that the palette generator can only be run in certain environments.
50
+
51
+ | Option | Default | Value Type | Possible Values |
52
+ | :------------------- | :------------: | :--------: | :--------------------: |
53
+ | enable_environments | [:development] | Array | <any Rails.env symbol> |
54
+
55
+ ### Defaults
56
+
57
+ Should the default colours be included for the palette generator. Even if they are included, they can be overwritten by the user's own colour of the same name:
58
+
59
+ | Option | Default | Value Type | Possible Values |
60
+ | :---------------- | :-----: | :--------: | :-------------: |
61
+ | default_absolutes | true | Boolean | true / false |
62
+ | default_relatives | true | Boolean | true / false |
63
+ | default_singles | true | Boolean | true / false |
64
+
65
+ ### Output
66
+
67
+ How the output file and values should be written:
68
+
69
+ | Option | Description | Default | Value Type | Possible Values |
70
+ | :------------ | :-------------------------------------------------------------------------------- | :----------------: | :--------: | :-----------------------------------------------------: |
71
+ | ouput_filename | Where the file should be output to including filename, without the file extension | 'utility_palettes' | String | <any filepath string> |
72
+ | ouput_dated | Should a timestamp be included in the filenames | false | Boolean | true / false |
73
+ | ouput_files | The types of files the palette should be output in | ['scss'] | Array | json, scss, css |
74
+ | ouput_format | The colour syntax the output colours should be written in | hex | String | rgb, hsl, hsv, hsb, cmyk, cielab, lab, cielch, lch, hex |
75
+ | ouput_prefix | A string that is appended to the start of all colour names, i.e. 'up-' | nil | String | <any string> |
76
+ | ouput_suffix | A string that is appended to the end of all colour names, i.e. '-col' | nil | String | <any string> |
77
+
78
+ ### Method (WIP)
79
+
80
+ It allows you to determine how you want the colours to be adjusted to create the variance in your palette, but for now all colour adjustments are made by changing the HSL values as it is the best combination of the simple yet effective and accurate method available.
81
+ In the future you will be able to shift the colours by changing values for different colour models and colour spaces; like RGB, CieLAB, OkLCH and others.
82
+
83
+ | Option | Description | Default | Value Type | Possible Values |
84
+ | :------- | :----------------------------------------------- | :-----: | :--------: | :-------------: |
85
+ | method | What colour space to adjust the colour values in | 'hsl' | String | hsl |
86
+
87
+ ### Steps (WIP)
88
+
89
+ Defines the percentage you want each colour to be adjusted by when moving through the colour palette. For now all steps are for the HSL method of adjusting colours
90
+ In the future you will be able to shift the colours by changing values for different colour models and colour spaces; like RGB, CieLAB, OkLCH and others.
91
+
92
+ | Option | Description | Default | Possible Values |
93
+ | :------ | :----------------------------------: | :-----: | :-------------: |
94
+ | steps_h | How much to adjust the hue by | 0 | 0 - 100 |
95
+ | steps_s | How much to adjust the saturation by | 3 | 0 - 100 |
96
+ | steps_l | How much to adjust the lightness by | 8 | 0 - 100 |
97
+
98
+ ### Colours
99
+
100
+ You can define colour names and values that you would like to create an "absolute palette"; where for each colour given, a range of colours are output with -50, -100, ..., -900 suffixes using that colour as the base.
101
+
102
+ You can define colour names and values that you would like to create an "relative palette"; where for each colour given, a -light and -dark colour are generated one step up and down from the base colour.
103
+ If a colour is included in both the "absolutes" and "relatives" sections, then the -light and -dark colours will match with colours in the absolute palette.
104
+
105
+ You can define colour names and values that you would like copied directly to the output as you have defined them.
106
+
107
+ All these options all colours to be passed in the same way; as a hash.
108
+ The key is the base name of the colour.
109
+ The value can be;
110
+
111
+ - a string such as '#ff0000' or 'rgb(51, 102, 204)',
112
+ - a hash of colour space keys and values such as { r: 51, g: 102, b: 204 } or { h: 30, s: 50, l: 75 },
113
+ - a 'reference' to a colour the is also defined in one of your config be using that colour name as the value but prepended with '$', such as '$red' (this felt useful if there are colours if you re-use the same colours under different use names)
114
+ - currently you can only reference colours defined in the config, not colours that would be generated as part of the palette generator process
115
+
116
+ | Option | Default | Possible Values |
117
+ | :-------- | :-----: | :-----------------------------------: |
118
+ | absolutes | {} | { '<colour name>' => <colour value> } |
119
+ | relatives | {} | { '<colour name>' => <colour value> } |
120
+ | singles | {} | { '<colour name>' => <colour value> } |
121
+
122
+ ## Development
123
+
124
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
125
+
126
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
127
+
128
+ ## Contributing
129
+
130
+ Bug reports and pull requests are welcome on GitHub at <https://github.com/louiswdavis/utility_palettes>. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/louiswdavis/utility_palettes/blob/master/CODE_OF_CONDUCT.md).
131
+
132
+ ## License
133
+
134
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
135
+
136
+ ## Code of Conduct
137
+
138
+ Everyone interacting in the UtilityPalettes project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/louiswdavis/utility_palettes/blob/master/CODE_OF_CONDUCT.md).
@@ -1,126 +1,126 @@
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 to #{filepath}..."
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 to #{filepath}..."
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 to #{filepath}..."
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
+ # 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 to #{filepath}..."
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 to #{filepath}..."
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 to #{filepath}..."
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,131 +1,131 @@
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
- colour_ref_array = [colour]
68
-
69
- # if the colour label begins with $ then it is a reference to a different defined colour, so must be looked up in the main hash
70
- while colour_ref_array.last.is_a?(String) && colour_ref_array.last.start_with?('$')
71
- colour_ref = @combined_samples.dig(colour_ref_array.last.slice(1..-1))
72
- raise UtilityPalettes::Error, "Circular reference detected for colour '#{label}': #{colour_ref_array.join(' -> ')}" if colour_ref_array.include?(colour_ref)
73
-
74
- colour_ref_array << colour_ref
75
- end
76
-
77
- colourized_hash[label] = ColorConverters::Color.new(colour_ref)
78
- else
79
- colourized_hash[label] = ColorConverters::Color.new(colour)
80
- end
81
-
82
- # TODO
83
- # provide a name if the label is left blank
84
- # if label.to_s == '$blank'
85
- # hash[colourized_hash[label].name] = hash.delete(label)
86
- # puts "Blank colour #{colour} has been given the name: #{colourized_hash[label].name}"
87
- # end
88
- rescue UtilityPalettes::Error => e
89
- warn "Error processing colour #{label}: #{e.message}"
90
- rescue ColorConverters::InvalidColorError => e
91
- warn "Error processing colour #{label} with value #{colour}: #{e.message}"
92
- end
93
- end
94
-
95
- colourized_hash
96
- end
97
-
98
- # * Palettes
99
-
100
- # ? Multiple Colour's Palette
101
- # 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
102
-
103
- def self.palette_looper(colourized_hash, palette_type)
104
- looped_generated_palettes = {}
105
-
106
- colourized_hash.each do |label, base_colour|
107
- # create a palette for a single colour from the providing mapping
108
- if palette_type == 'absolutes'
109
- generated_swatches = UtilityPalettes::Swatch.absolute_generator(label, base_colour)
110
- elsif palette_type == 'relatives'
111
- generated_swatches = UtilityPalettes::Swatch.relative_generator(label, base_colour)
112
- end
113
-
114
- # merge the colours absolute palette into the collective mapping
115
- looped_generated_palettes.merge!(generated_swatches)
116
- end
117
-
118
- looped_generated_palettes
119
- end
120
-
121
- def self.format_palette(generated_hash)
122
- configuration = UtilityPalettes.configuration
123
-
124
- generated_hash.transform_keys!(&:to_s)
125
- generated_hash.transform_keys! { |key| configuration.output_prefix + key } if configuration.output_prefix.present?
126
- generated_hash.transform_keys! { |key| key + configuration.output_suffix } if configuration.output_suffix.present?
127
-
128
- generated_hash
129
- end
130
- end
131
- 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
+ colour_ref_array = [colour]
68
+
69
+ # if the colour label begins with $ then it is a reference to a different defined colour, so must be looked up in the main hash
70
+ while colour_ref_array.last.is_a?(String) && colour_ref_array.last.start_with?('$')
71
+ colour_ref = @combined_samples.dig(colour_ref_array.last.slice(1..-1))
72
+ raise UtilityPalettes::Error, "Circular reference detected for colour '#{label}': #{colour_ref_array.join(' -> ')}" if colour_ref_array.include?(colour_ref)
73
+
74
+ colour_ref_array << colour_ref
75
+ end
76
+
77
+ colourized_hash[label] = ColorConverters::Color.new(colour_ref)
78
+ else
79
+ colourized_hash[label] = ColorConverters::Color.new(colour)
80
+ end
81
+
82
+ # TODO
83
+ # provide a name if the label is left blank
84
+ # if label.to_s == '$blank'
85
+ # hash[colourized_hash[label].name] = hash.delete(label)
86
+ # puts "Blank colour #{colour} has been given the name: #{colourized_hash[label].name}"
87
+ # end
88
+ rescue UtilityPalettes::Error => e
89
+ warn "Error processing colour #{label}: #{e.message}"
90
+ rescue ColorConverters::InvalidColorError => e
91
+ warn "Error processing colour #{label} with value #{colour}: #{e.message}"
92
+ end
93
+ end
94
+
95
+ colourized_hash
96
+ end
97
+
98
+ # * Palettes
99
+
100
+ # ? Multiple Colour's Palette
101
+ # 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
102
+
103
+ def self.palette_looper(colourized_hash, palette_type)
104
+ looped_generated_palettes = {}
105
+
106
+ colourized_hash.each do |label, base_colour|
107
+ # create a palette for a single colour from the providing mapping
108
+ if palette_type == 'absolutes'
109
+ generated_swatches = UtilityPalettes::Swatch.absolute_generator(label, base_colour)
110
+ elsif palette_type == 'relatives'
111
+ generated_swatches = UtilityPalettes::Swatch.relative_generator(label, base_colour)
112
+ end
113
+
114
+ # merge the colours absolute palette into the collective mapping
115
+ looped_generated_palettes.merge!(generated_swatches)
116
+ end
117
+
118
+ looped_generated_palettes
119
+ end
120
+
121
+ def self.format_palette(generated_hash)
122
+ configuration = UtilityPalettes.configuration
123
+
124
+ generated_hash.transform_keys!(&:to_s)
125
+ generated_hash.transform_keys! { |key| configuration.output_prefix + key } if configuration.output_prefix.present?
126
+ generated_hash.transform_keys! { |key| key + configuration.output_suffix } if configuration.output_suffix.present?
127
+
128
+ generated_hash
129
+ end
130
+ end
131
+ end
@@ -58,7 +58,7 @@ module UtilityPalettes
58
58
  elsif base_level.positive?
59
59
  lighter_colour = UtilityPalettes::Swatch.generate(base_colour, base_level, base_level + 1)
60
60
  else
61
- lighter_colour = nil
61
+ lighter_colour = base_colour # TODO: should this be differently? but needs to return something for output loop
62
62
  end
63
63
 
64
64
  # Darker Colour
@@ -67,7 +67,7 @@ module UtilityPalettes
67
67
  elsif base_level < 9
68
68
  darker_colour = UtilityPalettes::Swatch.generate(base_colour, base_level, base_level - 1)
69
69
  else
70
- darker_colour = nil
70
+ darker_colour = base_colour # TODO: should this be differently? but needs to return something for output loop
71
71
  end
72
72
 
73
73
  generated_relative_swatches.merge!({ "#{label}-light" => lighter_colour })
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module UtilityPalettes
4
- VERSION = '1.0.5'
4
+ VERSION = '1.0.6'
5
5
  end
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: utility_palettes
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.5
4
+ version: 1.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Louis Davis
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2026-01-27 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: color_converters
@@ -67,7 +66,6 @@ metadata:
67
66
  homepage_uri: https://github.com/louiswdavis/utility_palettes
68
67
  source_code_uri: https://github.com/louiswdavis/utility_palettes
69
68
  changelog_uri: https://github.com/louiswdavis/utility_palettes/blob/master/CHANGELOG.md
70
- post_install_message:
71
69
  rdoc_options: []
72
70
  require_paths:
73
71
  - lib
@@ -82,8 +80,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
82
80
  - !ruby/object:Gem::Version
83
81
  version: '0'
84
82
  requirements: []
85
- rubygems_version: 3.5.22
86
- signing_key:
83
+ rubygems_version: 3.7.2
87
84
  specification_version: 4
88
85
  summary: Quickly build colour palettes based on default or supplied colour swatches,
89
86
  and export them for use in stylesheets.