utility_colors 0.1.8 → 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.
Files changed (39) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +131 -174
  3. data/Rakefile +8 -12
  4. data/lib/generators/templates/config/utility_colors.rb +22 -0
  5. data/lib/generators/templates/palettes/_color-variables.scss +34 -0
  6. data/lib/generators/utility_colors/config_generator.rb +13 -0
  7. data/lib/generators/utility_colors/generate_generator.rb +31 -0
  8. data/lib/utility_colors/builders.rb +75 -0
  9. data/lib/utility_colors/colors.rb +106 -0
  10. data/lib/utility_colors/configuration.rb +67 -0
  11. data/lib/utility_colors/exports.rb +54 -0
  12. data/lib/utility_colors/imports.rb +42 -0
  13. data/lib/utility_colors/properties.rb +77 -0
  14. data/lib/utility_colors/version.rb +5 -5
  15. data/lib/utility_colors.rb +15 -8
  16. metadata +18 -35
  17. data/.npmignore +0 -28
  18. data/.rspec +0 -3
  19. data/.rubocop.yml +0 -13
  20. data/CHANGELOG.md +0 -46
  21. data/CODE_OF_CONDUCT.md +0 -84
  22. data/Gemfile +0 -12
  23. data/LICENSE.txt +0 -21
  24. data/examples/v0.1.8.png +0 -0
  25. data/index.js +0 -5
  26. data/package.json +0 -26
  27. data/utility_colors/_utility_colors.scss +0 -11
  28. data/utility_colors/utility_colors_files/functions/_functions.scss +0 -4
  29. data/utility_colors/utility_colors_files/functions/_mappings.scss +0 -25
  30. data/utility_colors/utility_colors_files/functions/_palettes.scss +0 -123
  31. data/utility_colors/utility_colors_files/functions/_references.scss +0 -7
  32. data/utility_colors/utility_colors_files/functions/_sequences.scss +0 -17
  33. data/utility_colors/utility_colors_files/mixins/_mixins.scss +0 -60
  34. data/utility_colors/utility_colors_files/utilities/_color.scss +0 -22
  35. data/utility_colors/utility_colors_files/validators/_validations.scss +0 -3
  36. data/utility_colors/utility_colors_files/variables/_color-variables.scss +0 -64
  37. data/utility_colors/utility_colors_files/variables/_mod-variables.scss +0 -53
  38. data/utility_colors/utility_colors_files/variables/_user-variables.scss +0 -78
  39. data/utility_colors/utility_colors_files/variables/_variables.scss +0 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4aa8ad1559d7078464f2f5c7d0202bd5d6b9ee1e0618a8cc37bfd216cc0f9f2e
4
- data.tar.gz: 53466d34894454a5b95f22d47b5e4f7a200dd7ba5e52bf8d4a21a0e0d898f40e
3
+ metadata.gz: 7bcb54e43ef56335b61de7c5657477471310d42b4c7150821d874e35cc48af36
4
+ data.tar.gz: b45099cb134d67fb04898daf013d78a1908d970c63950220e6fc9368eca4653c
5
5
  SHA512:
6
- metadata.gz: 12c2461a4cba263e3c031aec7d83f5f978ac9aa4652fc4cde2f91b3ae32fd9b88597a9f8907d6c91176fa94f9d6c28d08ca236d62d578cb273fa7d69bd7802c4
7
- data.tar.gz: e061a29c8b2e256e396f8256fdf01e7c4849413b33c5adad9670d19a6b03fd5f0f2cd879e9dbfe5d1c170490575780d699952a0ec11fc698493b647b791cd75e
6
+ metadata.gz: ad703fe0a83d64355550e011eed509101935794f3954e20c8d4bca8b5556ab86f41d6ba0777e021f6afd447c2c5d03b1ba6c3341155a0c8289472b840b38a4d8
7
+ data.tar.gz: 5ac4ff72a529536744477e3317578c0001f5bb76181aa2618183d984db22900b26f0c5c611124d9ac82d6fcadfff4165227a495cd7a65529376c6c1cec39a155
data/README.md CHANGED
@@ -1,174 +1,131 @@
1
- # UtilityColors
2
-
3
- Utility Colors is a library built and centred around creating quick and effective colour palettes based off of any base colour and then utilizing them in a wide variety of BEM style modifier classes to be used in styling that can come into effect at varying screen sizes and element states.
4
-
5
- It's
6
- - pure sass
7
- - simple and easily usable right out of the box
8
- - configurable with the intent to become part of a larger utility class eco-system
9
- - easily swappable between the gem and package with minimal changes
10
-
11
- Firstly, yes the library is called Utility COLORS (for a wide range of reasons) but in this documentation, unless referencing something library specific I'll be spelling it 'colours'.
12
-
13
-
14
- ## Installation
15
-
16
- ### Yarn
17
-
18
- Add the package
19
-
20
- $ yarn add utility_colors;
21
-
22
- Import the styles from your node_modules and add the **OPTIONAL** configuration map at the top of your scss file
23
-
24
- ```scss
25
- $utility_colors: (
26
- config: (
27
- classes: BOOLEAN,
28
- breakpoint: BOOLEAN,
29
- pseudo: BOOLEAN,
30
- defaults: BOOLEAN,
31
- ),
32
- colors: (
33
- shades-use: (
34
- 'base-colour-A-name': value,
35
- // and more colours
36
- ),
37
- tri-use: (
38
- 'base-colour-B-name': value,
39
- // and more colours
40
- ),
41
- single-use: (
42
- 'base-colour-C-name': value,
43
- // and more colours
44
- ),
45
- )
46
- );
47
-
48
- @import "utility_colors/utility_colors/utility_colors";
49
- ```
50
-
51
- ### Ruby
52
-
53
- **Please be aware there seem to be widespread issues with importing gem styles when using cssbundling so if you are using that you may want to use the package until this is resolved**
54
-
55
- Add this line to your application's Gemfile:
56
-
57
- ```ruby
58
- gem 'utility_colors'
59
- ```
60
-
61
- And then execute:
62
-
63
- $ bundle install
64
-
65
- Or install it yourself as:
66
-
67
- $ gem install utility_colors
68
-
69
- Import the styles from the gem and add the **optional** configuration map at the top of your scss file
70
-
71
- ```scss
72
- $utility_colors: (
73
- config: (
74
- classes: BOOLEAN,
75
- breakpoint: BOOLEAN,
76
- pseudo: BOOLEAN,
77
- defaults: BOOLEAN,
78
- ),
79
- colors: (
80
- shades-use: (
81
- 'base-colour-A-name': value,
82
- // and more colours
83
- ),
84
- tri-use: (
85
- 'base-colour-B-name': value,
86
- // and more colours
87
- ),
88
- single-use: (
89
- 'base-colour-C-name': value,
90
- // and more colours
91
- ),
92
- )
93
- );
94
-
95
- @import "utility_colors";
96
- ```
97
-
98
- ## Examples
99
-
100
- ![v0.1.8 Colour Palette Example](https://github.com/louiswdavis/utility_colors/blob/master/examples/v0.1.8.png)
101
-
102
- ## Usage
103
-
104
- ### Palettes & Classes
105
-
106
- After importing the UtilityColors stylesheet your styles will produce a large array of BEM classes that you can use to quickly modify the colour properties of your components. If you have a generic card class being used but in one place you want it to be red and another you want it to be light blue you can add the classes `.color--red` and `.color--blue-200` respectively to your html.
107
-
108
- Every default colour supplied by UtilityColors has a base, and a shades palette based off that base. These colours are all given keys which are then appended to the various classes available. The base colours key is simply it's name; 'red', 'blue'. The shade palette colours keys are the base colour they are based off, then appended with a '-' and then a value of **50, 100, 200, ..., 900**, where the large number indicates a darker colour. You may be familiar with this style of naming if you've used other style frameworks.
109
-
110
- Additionally to the default colours, UtilityColors also supplies a small collection of role colours based off the defaults; success (green), danger (red), information (blue), warning (gold). And each of these has a light and dark variation where the key is the colour role appended with either `-light` or `-dark`. These variations are referred to as the 'tri palette' (the base, the light, and the dark).
111
-
112
- Classes available:
113
- - change the color property: `.color--key`
114
- - change the background-color property: `.bg--key`
115
- - change the border-color property: `.border-c--key`
116
- - change the outline-color property: `.outline-c--key`
117
- - change the text-decoration-color property: `.decoration-c--key`
118
-
119
- where the key is the colour's 'name' i.e. `red` `green-100` `blue-900` `success-light` `danger-dark`
120
-
121
- ### Advanced Classes
122
-
123
- As previously stated you can use basic UtilityColors classes to change the colours properties of your components but sometimes you may want to make adjustments only in select circumstances. One of these circumstances is the size of the screen, or more accurately the width of the screen.
124
-
125
- You can turn any basic class into an advanced breakpoint class by prepending it with sm, md, lg, or xl followed by a '|' i.e. `.md|color--red` where 325px, 768px, 1024px, 1440px are the minimum screen width where the class will come into effect respectively.
126
- Alongside breakpoint classes there are also pseudo-state classes which are advanced classes that can make a colour property come into effect a certain state or condition of an element if achieved. These follow the style of breakpoint where they must be prepended to the basic classes separated by a '|' i.e. `.hover|color--red`. The pseudo properties currently applicable to these classes are; checked, disabled, enabled, focus, in-range, invalid, optional, out-of-range, read-only, read-write, require, valid, active, hover, link, target, visited, root, first-child, first-of-type, last-child, last-of-type, only-of-type, only-child, empty.
127
- And if that wasn't enough you can also combine pseudo-state and breakpoint classes i.e. `.hover|md|color--red`
128
-
129
-
130
- ### Custom Configuration
131
-
132
- There are some optional configuration options you can tweak to reduce the number of classes or colours the library will produce for you. All the options listed above are true by default. If you don't want to produce any classes at all you can set `classes` to false. If you don't want to produce any breakpoint classes you can set `breakpoint` to false. This will also not produce the hybrid pseudo-state|breakpoint classes. If you don't want to produce any pseudo-state classes you can set `pseudo` to false. This will also not produce the hybrid pseudo-state|breakpoint classes. If you want to remove all the default colour and subsequent palettes right from the start you can set `defaults` to false.
133
-
134
- Obviously a default palette is nice, but it may not include the colours you want or the current named ones may not be based off your preferred variant of that colour (maybe you want your red palette to have a hint more orange to it). That is where the `colors` portion of the $utility_colors configuration variable comes in.
135
- If you want to create a new palette or overwrite an existing one simply add the name you want to use for your colour as the key, and the hex, rgb, or hsl code related to it as the value. If you add this colour to the `shades-use` then a base colour and shades palette of colours will be produced and have corresponding classes created for them.
136
- If you add this colour to the `tri-use` then a base colour and tri palette of colours will be produced and have corresponding classes created for them.
137
- If you add this colour to the `single-use` then just the base colour will be used to create corresponding classes created for it.
138
- Don't worry if you want to produce a shades and tri palette for a single base. Adding that colour to both sections will produce all the colours you want and the latter base colour will replace the former. This can also be useful if you want to make slight adjustments to shades or tri palettes as you can add the **full** colour name as a single-use key with the value you want to use and this will overwrite the corresponding matching key colour from any of the palettes.
139
-
140
- ### Additional Usability
141
-
142
- There is also a scss function called `get-uc` that will retrieve the colours value from the various palettes so that it can be used in your later custom classes. It just requires the correct colour key to be called with the function i.e. `color: get-uc(red-400)`.
143
-
144
- ## Palette Creation
145
-
146
- To achieve the shades or tri colour palettes, colours are created by incrementing and decrementing the lightness and saturation of a base colour to get the colours on either side of the base needed for the palettes. I have found this the most effective way of creating custom colour palettes compared to other generators as this method uses and retains your base colour as a part of the larger palette, unlike other generators which take your base and adjust it to suit the generators preferred colour style. This may work if you need to integrate various colours into a larger, pre-determined colour palette but often we are creating the colour palettes from scratch and with the requirement that our base colour be used in it.
147
-
148
- This also gives the added benefit that if you used one of the specific shade colour's as your key and provided a different colour value then it would use this new value in the palette and replace the previously created one. As the methods used to create the shade and tri palettes are the same, their outputs will overlap which means you don't have to worry about a extra large amount of classes. Tri colours are two 'steps' away from their base so a base colour `col` that produces that produces the colour `col-400` will mean `col-200` and `col-light` are the same, and `col-600` and `col-dark`.
149
- This is just another way to keep palettes in sync and prevent palettes of the same base from becoming unlinked from one another. Be aware that if a colour is very dark or very light one of it's tri colours may only be one step away, or may not be created at all, corresponding to the amount of 'space' available on either side of the base to create the colour.
150
-
151
- ## Future Development
152
-
153
- - add classes for the singular sides of borders and outlines
154
- - add config variables to disable the creation of certain classes i.e. color, background-color, etc
155
- - move the config variables to a config.js file as per the norm across many packages
156
- - make a page/partial/component that can be used to view the colour outputs
157
- - first step is putting raw html in a file that can be copied and used
158
- - second step is to make a page that can be added to routes
159
- - further development of this would be to show accessibilty ratings and more in-depth information of the palettes
160
- - add the ability to output colour variables/palettes in the terminal to make them more accessible for users to see, check and export
161
- - validate the user variables added before they are used
162
- - create a site that will display the descriptions and examples of colours and classes produced by the library more effectively than this markdown file (this markdown is getting a little crowded already)
163
-
164
- ## Contributing
165
-
166
- Bug reports and pull requests are welcome on GitHub at https://github.com/louiswdavis/utility_colors. 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_colors/blob/master/CODE_OF_CONDUCT.md). I am not incredibly familiar with creating gems or packages so there may be things missing that seem obvious to others but are not to me.
167
-
168
- ## License
169
-
170
- The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
171
-
172
- ## Code of Conduct
173
-
174
- Everyone interacting in the UtilityColors project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/louiswdavis/utility_colors/blob/master/CODE_OF_CONDUCT.md).
1
+ # UtilityColors
2
+
3
+ ![Static Badge](https://img.shields.io/badge/Gem_Version-1.0.0-blue)
4
+ [![Static Badge](https://img.shields.io/badge/RubyGems-red)](https://rubygems.org/gems/utility_colors)
5
+
6
+ > Generate your own colour specific classes in an instance.
7
+
8
+ Utility Colors is an ruby gem package for use in ruby or other projects that generates styling classes based on your supplied colours.
9
+ It can take your SCSS or CSS variable, or even a JSON file of them, and provide you with all the classes you need for adding colour to your HTML.
10
+ After importing the UtilityColors stylesheet your styles will produce a large array of BEM classes that you can use to quickly modify the colour properties of your components. If you have a generic card class being used but in one place you want it to be red and another you want it to be light blue you can add the classes `.color--red` and `.color--blue-200` respectively to your html.
11
+
12
+ ## Installation
13
+
14
+ Install the gem and add to the application's Gemfile by executing:
15
+
16
+ ```bash
17
+ bundle add utility_colors
18
+ ```
19
+
20
+ If bundler is not being used to manage dependencies, install the gem by executing:
21
+
22
+ ```bash
23
+ gem install utility_colors
24
+ ```
25
+
26
+ ## Usage
27
+
28
+ To get the config:
29
+
30
+ ```bash
31
+ rails generate utility_colors:config
32
+ ```
33
+
34
+ To generate the colour classes:
35
+
36
+ ```bash
37
+ rails generate utility_colors:generate
38
+ ```
39
+
40
+ ## Configuration
41
+
42
+ >[!WARNING]
43
+ > UtilityColors has moved to a Ruby Config file from v1.0.0.
44
+ > The Pure SCSS version of the gem and JS package are still fully usable and [the documentation can be found here](README_v0.1.8.md).
45
+ > Run `rails generate utility_colors:config` to get the new config and move your values across.
46
+ > The `colors` section of the config is now a part of [UtilityPalettes](https://github.com/louiswdavis/utility_palettes)
47
+
48
+ ### Environment
49
+
50
+ Set the environment that the sub-data will be read in, meaning that the palette generator can only be run in certain environments.
51
+
52
+ | Option | Default | Value Type | Possible Values |
53
+ | :------------------- | :------------: | :--------: | :--------------------: |
54
+ | enable_environments | [:development] | Array | <any Rails.env symbol> |
55
+
56
+ ### Import
57
+
58
+ The location of the palette file that you will use to build your colour classes.
59
+ Examples can be found for [SCSS](spec/fixtures/imports.palette.scss), [CSS](spec/fixtures/imports.palette.css), or [JSON](spec/fixtures/imports.palette.json) files, and this is how [UtilityPalettes](https://github.com/louiswdavis/utility_palettes) would be exported.
60
+
61
+ | Option | Default | Value Type | Possible Values |
62
+ | :---------------- | :---------------------: | :--------: | :-------------------: |
63
+ | import_palettes_filepath | 'utility_palettes.scss' | String | <any filepath string> |
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_colors' | 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_prefix | A string that is appended to the start of all class names, i.e. 'uc-' | nil | String | <any string> |
75
+ | ouput_suffix | A string that is appended to the end of all class names, i.e. '-custom' | nil | String | <any string> |
76
+
77
+ ### Classes
78
+
79
+ What types of classes should be built:
80
+
81
+ | Option | Description | Default | Value Type | Possible Values |
82
+ | :----------------------- | :------------------------------------------------------------------------ | :-----: | :--------: | :-------------------: |
83
+ | regular_classes | Should 'regular' classes be built, e.g. ".bg--red-50" | true | Boolean | true / false |
84
+ | breakpoint_classes | Should 'breakpoint' classes be built, e.g. ".md\\|color--black" | false | Boolean | true / false |
85
+ | pseudo_classes | Should 'pseudo' classes be built, e.g. ".hover\\|border-c--blue-50:hover" | false | Boolean | true / false |
86
+ | breakpoint_pseudo_classes | Should 'regular' classes be built, e.g. ".hover\\|md\\|bg--blue-50:hover" | false | Boolean | true / false |
87
+
88
+ ### Extra Information
89
+
90
+ Breakpoint list:
91
+
92
+ - sm: 325px
93
+ - md: 768px
94
+ - lg: 1024px
95
+ - xl: 1440px
96
+
97
+ Pseudo list:
98
+
99
+ - input: 'checked', 'disabled', 'enabled', 'focus'
100
+ - action: 'active', 'hover', 'link', 'target', 'visited'
101
+ - child: 'root', 'first-child', 'first-of-type', 'last-child', 'last-of-type', 'only-of-type', 'only-child', 'empty'
102
+
103
+ Classes available:
104
+
105
+ - 'color--key': will change the `color` property
106
+ - 'bg--key': will change the `background-color` property
107
+ - 'accent-c--key': will change the `accent-color` property
108
+ - 'border-c--key': will change the `border-color` property
109
+ - 'outline-c--key': will change the `outline-color` property
110
+ - 'decoration-c--key': will change the `text-decoration-color` property
111
+ - 'caret-c--key': will change the `caret-color` property
112
+ - 'svg-fill-c--key': will change the `fill` property
113
+ - 'svg-stroke-c--key': will change the `stroke` property
114
+
115
+ ## Development
116
+
117
+ 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.
118
+
119
+ 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).
120
+
121
+ ## Contributing
122
+
123
+ Bug reports and pull requests are welcome on GitHub at <https://github.com/louiswdavis/utility_colors>. 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_colors/blob/master/CODE_OF_CONDUCT.md).
124
+
125
+ ## License
126
+
127
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
128
+
129
+ ## Code of Conduct
130
+
131
+ Everyone interacting in the UtilityColors project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/louiswdavis/utility_colors/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile CHANGED
@@ -1,12 +1,8 @@
1
- # frozen_string_literal: true
2
-
3
- require "bundler/gem_tasks"
4
- require "rspec/core/rake_task"
5
-
6
- RSpec::Core::RakeTask.new(:spec)
7
-
8
- require "rubocop/rake_task"
9
-
10
- RuboCop::RakeTask.new
11
-
12
- task default: %i[spec rubocop]
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rspec/core/rake_task'
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ task default: :spec
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ UtilityColors.configure do |config|
4
+ # Enabled Environments
5
+ # config.enable_environments = [:development]
6
+
7
+ # Import
8
+ # config.import_palettes_filepath = 'utility_palettes.scss'
9
+
10
+ # Output
11
+ # config.output_filename = 'utility_colors'
12
+ # config.output_dated = false
13
+ # config.output_files = ['scss']
14
+ # config.output_prefix = nil
15
+ # config.output_suffix = nil
16
+
17
+ # Class Types
18
+ # config.regular_classes = true
19
+ # config.breakpoint_classes = false
20
+ # config.pseudo_classes = false
21
+ # config.breakpoint_pseudo_classes = false
22
+ end
@@ -0,0 +1,34 @@
1
+ // v0.1.8 Absolute Sources
2
+
3
+ $red: hsl(2, 78%, 64%);
4
+ $rust: hsl(16, 82%, 62%);
5
+ $orange: hsl(31, 90%, 65%);
6
+ $gold: hsl(46, 93%, 54%);
7
+ $yellow: hsl(58, 87%, 55%);
8
+ $pear: hsl(80, 74%, 57%);
9
+ $green: hsl(110, 69%, 58%);
10
+ $seaside: hsl(156, 78%, 57%);
11
+ $cyan: hsl(180, 69%, 37%);
12
+ $capri: hsl(197, 90%, 46%);
13
+ $blue: hsl(214, 78%, 36%);
14
+ $iris: hsl(265, 87%, 57%);
15
+ $purple: hsl(279, 85%, 56%);
16
+ $magenta: hsl(300, 64%, 66%);
17
+ $pink: hsl(320, 74%, 66%);
18
+ $satin: hsl(348, 74%, 57%);
19
+ $cement: hsl(42, 6%, 87%);
20
+ $grey: hsl(0, 3%, 46%);
21
+ $base: hsl(0, 3%, 46%);
22
+
23
+ // v0.1.8 Relative Sources
24
+
25
+ $success: $green-400;
26
+ $danger: $red-400;
27
+ $information: $blue-400;
28
+ $warning: $gold-400;
29
+
30
+ // v0.1.8 Single Sources
31
+
32
+ $white: #fff;
33
+ $black: #000;
34
+ $translucent: rgba(#000, 0.45);
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module UtilityColors
4
+ module Generators
5
+ class ConfigGenerator < Rails::Generators::Base
6
+ source_root File.expand_path('../../..', __dir__)
7
+
8
+ def copy_config
9
+ copy_file 'lib/generators/templates/config/utility_colors.rb', 'config/initializers/utility_colors.rb'
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ module UtilityColors
4
+ module Generators
5
+ class GenerateGenerator < Rails::Generators::Base
6
+ def generate_utility_colors
7
+ # TODO: check if the v0.1.8 scss files exists
8
+ # "app/app/assets/stylesheets/utility_colors_files" directory
9
+ self.class.config_format_warn if File.exist?('config/utility_colors.yml') || File.exist?('config/utility_colors.json')
10
+
11
+ if UtilityColors.configuration.enable_environments.include?(Rails.env.to_sym)
12
+ UtilityColors::Colors.generate
13
+ else
14
+ self.class.disabled_warn
15
+ end
16
+ end
17
+
18
+ private
19
+
20
+ # TODO: add links to README for migration
21
+ def self.config_format_warn
22
+ warn 'WARNING: Utility Colors now uses an initializer to set config. You need to migrate and remove your YML/JSON file.'
23
+ end
24
+
25
+ # TODO: add links to README for environment setting
26
+ def self.disabled_warn
27
+ warn 'ERROR: Utility Colors is disabled for this environment. Color classes will not be generated.'
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,75 @@
1
+ # frozen_string_literal: true
2
+
3
+ module UtilityColors
4
+ class Builders
5
+ # '.' are appended during final formatting
6
+
7
+ # 'color--red-400'
8
+ def self.utility_classes_creation(class_name, content)
9
+ content = [content] unless content.is_a?(Array)
10
+ { class_name => "#{content.join(': ')};" }
11
+ end
12
+
13
+ # 'md|color--red-400'
14
+ def self.utility_pseudo_classes_creation(class_name, content, pseudo)
15
+ content = [content] unless content.is_a?(Array)
16
+ { "#{pseudo}\|#{class_name}:#{pseudo}" => "#{content.join(': ')};" }
17
+ end
18
+
19
+ # 'hover|color--red-400'
20
+ def self.utility_breakpoint_classes_creation(class_name, content, initial, screen_size)
21
+ content = [content] unless content.is_a?(Array)
22
+ { "#{initial}\|#{class_name}" => "@media only screen and (min-width: #{screen_size - 1}) { #{content.join(': ')}; }" }
23
+ end
24
+
25
+ # 'hover|md|color--red-400'
26
+ def self.utility_pseudo_breakpoint_classes_creation(class_name, content, pseudo, initial, screen_size)
27
+ content = [content] unless content.is_a?(Array)
28
+ { "#{pseudo}\|#{initial}\|#{class_name}:#{pseudo}" => "@media only screen and (min-width: #{screen_size - 1}) { #{content.join(': ')}; }" }
29
+ end
30
+
31
+ # Bulk Methods
32
+
33
+ def self.utility_classes(class_name, content)
34
+ UtilityColors::Builders.utility_classes_creation(class_name, content)
35
+ end
36
+
37
+ def self.bulk_breakpoint_class_creation(class_hash)
38
+ uc_screens = UtilityColors::Properties.screen_sizes.transform_values(&:to_f)
39
+
40
+ uc_screens.collect do |initial, screen_size|
41
+ class_hash.collect do |class_name, content|
42
+ UtilityColors::Builders.utility_breakpoint_classes_creation(class_name, content, initial, screen_size)
43
+ end
44
+ end.flatten.reduce({}, :merge)
45
+ end
46
+
47
+ def self.bulk_pseudo_class_creation(class_hash)
48
+ uc_pseudos = UtilityColors::Properties.pseudos
49
+
50
+ uc_pseudos.collect do |pseudo|
51
+ class_hash.collect do |class_name, content|
52
+ UtilityColors::Builders.utility_pseudo_classes_creation(class_name, content, pseudo)
53
+ end
54
+ end.flatten.reduce({}, :merge)
55
+ end
56
+
57
+ def self.bulk_pseudo_breakpoint_class_creation(class_hash)
58
+ uc_screens = UtilityColors::Properties.screen_sizes.transform_values(&:to_f)
59
+ uc_pseudos = UtilityColors::Properties.pseudos
60
+
61
+ uc_screens.collect do |initial, screen_size|
62
+ uc_pseudos.collect do |pseudo|
63
+ class_hash.collect do |class_name, content|
64
+ UtilityColors::Builders.utility_pseudo_breakpoint_classes_creation(class_name, content, pseudo, initial, screen_size)
65
+ end
66
+ end
67
+ end.flatten.flatten.reduce({}, :merge)
68
+ end
69
+
70
+ # * Advanced Classes
71
+
72
+ # utility_classes(class)
73
+ # .class { content }
74
+ end
75
+ end
@@ -0,0 +1,106 @@
1
+ # frozen_string_literal: true
2
+
3
+ module UtilityColors
4
+ class Colors
5
+ def self.generate
6
+ configuration = UtilityColors.configuration
7
+
8
+ generated_regular_classes = {}
9
+ generated_breakpoint_classes = {}
10
+ generated_pseudo_classes = {}
11
+ generated_pseudo_breakpoint_classes = {}
12
+
13
+ puts 'Generating utility colour classes...'
14
+
15
+ colour_palette = UtilityColors::Imports.import
16
+
17
+ puts 'Retrieved colour palettes...'
18
+
19
+ generated_source_classes = UtilityColors::Colors.build_source_classes(colour_palette)
20
+
21
+ puts 'Generated source colour classes...'
22
+
23
+ if configuration.regular_classes
24
+ generated_regular_classes = generated_source_classes
25
+ puts 'Generated regular colour classes...'
26
+ end
27
+
28
+ if configuration.breakpoint_classes
29
+ generated_breakpoint_classes = UtilityColors::Builders.bulk_breakpoint_class_creation(generated_source_classes)
30
+ puts 'Generated breakpoint colour classes...'
31
+ end
32
+
33
+ if configuration.breakpoint_classes
34
+ generated_pseudo_classes = UtilityColors::Builders.bulk_pseudo_class_creation(generated_source_classes)
35
+ puts 'Generated breakpoint colour classes...'
36
+ end
37
+
38
+ if configuration.breakpoint_classes
39
+ generated_pseudo_breakpoint_classes = UtilityColors::Builders.bulk_pseudo_breakpoint_class_creation(generated_source_classes)
40
+ puts 'Generated breakpoint colour classes...'
41
+ end
42
+
43
+ generated_classes = {}.merge(generated_regular_classes, generated_breakpoint_classes, generated_pseudo_classes, generated_pseudo_breakpoint_classes)
44
+ formatted_classes = self.format_classes(generated_classes)
45
+
46
+ filename = configuration.output_filename
47
+ filename += "-#{Time.zone.now.strftime('%Y%m%d-%H%M%S')}" if configuration.output_dated == true
48
+
49
+ output_files = configuration.output_files.map(&:strip)
50
+
51
+ UtilityColors::Exports.json(filename, formatted_classes) if output_files.include?('json')
52
+ UtilityColors::Exports.scss(filename, formatted_classes) if output_files.include?('scss')
53
+ UtilityColors::Exports.css(filename, formatted_classes) if output_files.include?('css')
54
+
55
+ true
56
+ end
57
+
58
+ private
59
+
60
+ def self.build_source_classes(colour_palette)
61
+ colour_style_prefix_and_property = {
62
+ 'color' => 'color',
63
+ 'bg' => 'background-color',
64
+ 'accent-c' => 'accent-color',
65
+ 'border-c' => 'border-color',
66
+ 'outline-c' => 'outline-color',
67
+ 'decoration-c' => 'text-decoration-color',
68
+ 'caret-c' => 'caret-color',
69
+ 'svg-fill-c' => 'fill',
70
+ 'svg-stroke-c' => 'stroke'
71
+ }
72
+
73
+ # 'border-t' => 'border-top-color',
74
+ # 'border-r' => 'border-right-color',
75
+ # 'border-b' => 'border-bottom-color',
76
+ # 'border-l' => 'border-left-color',
77
+ # 'box-shadow' => '--uc-box-shadow-c'
78
+ # 'drop-shadow' => '--uc-drop-shadow-c'
79
+
80
+ current_colour_class = colour_style_prefix_and_property.collect do |style_class_type, style_property|
81
+ UtilityColors::Builders.utility_classes_creation("#{style_class_type}--current", [style_property, 'currentColor'])
82
+ end.reduce({}, :merge)
83
+
84
+ # initially use the palette key as the style value so that it can be more easily replaced for the correct type of variable when it is exported
85
+ base_colour_classes = colour_palette.keys.collect do |style_modifier|
86
+ colour_style_prefix_and_property.collect do |style_class_type, style_property|
87
+ UtilityColors::Builders.utility_classes_creation("#{style_class_type}--#{style_modifier}", [style_property, "£$#{style_modifier}$£"])
88
+ end
89
+ end.flatten.reduce({}, :merge)
90
+
91
+ {}.merge!(current_colour_class, base_colour_classes)
92
+ end
93
+
94
+ def self.format_classes(generated_hash)
95
+ configuration = UtilityColors.configuration
96
+
97
+ generated_hash.transform_keys!(&:to_s)
98
+ generated_hash.transform_keys! { |key| configuration.output_prefix + key } if configuration.output_prefix.present?
99
+ generated_hash.transform_keys! { |key| key + configuration.output_suffix } if configuration.output_suffix.present?
100
+
101
+ generated_hash.transform_keys! { |key| ".#{key}" }
102
+
103
+ generated_hash
104
+ end
105
+ end
106
+ end