utility_classes 0.1.1 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +40 -5
- data/Rakefile +7 -5
- data/lib/tasks/utility_classes_tasks.rake +1 -0
- data/lib/utility_classes/railtie.rb +4 -0
- data/lib/utility_classes/utility_class_reader.rb +18 -9
- data/lib/utility_classes/version.rb +1 -1
- data/lib/utility_classes.rb +3 -1
- metadata +6 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9a6e5099e722349306f58dae45a7e1d694eb964a4328d2c9f58b59c1c92144c9
|
4
|
+
data.tar.gz: 04f373b712af10ce1b282941b89b7eca1206056a6a9dd7049e3440cb2dacd8ae
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1e6904b5733c4350794a9200385548af755477a72acc274c71c92cb7a1ffa0ebab08de9f152a5b52859ad43c331d05446bb7cabe4fe8bc4f2b0ab9f5297fa09a
|
7
|
+
data.tar.gz: e8d37d19dda559a73e38736f6333e0b041af3c6a6913d25f591eb2a592d34add03dc5881987dbf85279c3006d298b95426cdff3fc99a232f8e5918885f8c3740
|
data/README.md
CHANGED
@@ -8,8 +8,9 @@ This project was inspired by the [classy-yaml](https://github.com/Tonksthebear/c
|
|
8
8
|
|
9
9
|
You can easily define a base class list for a given type:
|
10
10
|
|
11
|
-
`config/utility_classes.yml`
|
12
11
|
```yaml
|
12
|
+
# config/utility_classes.yml
|
13
|
+
|
13
14
|
heading:
|
14
15
|
base: 'text-lg font-semibold text-center'
|
15
16
|
```
|
@@ -18,22 +19,27 @@ And then retrieve the class list in your code:
|
|
18
19
|
|
19
20
|
```ruby
|
20
21
|
UtilityClasses.for(:heading)
|
22
|
+
# "text-lg font-semibold text-center"
|
21
23
|
```
|
22
24
|
|
23
25
|
You can optionally define variants for each type:
|
24
26
|
|
25
|
-
`config/utility_classes.yml`
|
26
27
|
```yaml
|
28
|
+
# config/utility_classes.yml
|
29
|
+
|
27
30
|
heading:
|
28
|
-
base: '
|
31
|
+
base: 'font-semibold text-center'
|
29
32
|
variants:
|
30
|
-
|
33
|
+
normal: 'text-lg'
|
34
|
+
large: 'text-2xl'
|
35
|
+
xlarge: 'text-4xl'
|
31
36
|
```
|
32
37
|
|
33
38
|
And then retrieve the class list by passing the variant key:
|
34
39
|
|
35
40
|
```ruby
|
36
|
-
UtilityClasses.for(:heading, variant: :
|
41
|
+
UtilityClasses.for(:heading, variant: :large)
|
42
|
+
# "font-semibold text-center text-2xl"
|
37
43
|
```
|
38
44
|
|
39
45
|
The returned string will contain the base classes with the variant classes appended.
|
@@ -68,6 +74,35 @@ $ bin/rails generate utility_classes:install
|
|
68
74
|
|
69
75
|
Add your classes to the generated config file following the structure of the examples.
|
70
76
|
|
77
|
+
If you are using TailwindCSS, ensure that your configuration lists the `utility_classes.yml` file.
|
78
|
+
|
79
|
+
`webpacker` approach:
|
80
|
+
|
81
|
+
```javascript
|
82
|
+
// tailwind.config.js
|
83
|
+
|
84
|
+
module.exports = {
|
85
|
+
purge: [
|
86
|
+
'./app/**/**.html.erb',
|
87
|
+
'./config/utility_classes.yml' // add this line
|
88
|
+
],
|
89
|
+
theme: {},
|
90
|
+
variants: {},
|
91
|
+
plugins: [],
|
92
|
+
}
|
93
|
+
```
|
94
|
+
|
95
|
+
`tailwindcss-rails` approach:
|
96
|
+
|
97
|
+
```ruby
|
98
|
+
# add to your `config/environments/production.rb` file
|
99
|
+
|
100
|
+
config.assets.css_compressor = :purger
|
101
|
+
config.assets.css_compressor = Tailwindcss::Compressor.new(
|
102
|
+
files_with_class_names: Rails.root.glob('app/views/**/*.*') + Rails.root.glob('config/utility_classes.yml')
|
103
|
+
)
|
104
|
+
```
|
105
|
+
|
71
106
|
## Contributing
|
72
107
|
|
73
108
|
Contributions are welcome. Feel free to open a PR.
|
data/Rakefile
CHANGED
@@ -1,11 +1,13 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
4
|
-
|
3
|
+
require 'bundler/setup'
|
4
|
+
|
5
|
+
require 'bundler/gem_tasks'
|
6
|
+
require 'rake/testtask'
|
5
7
|
|
6
8
|
Rake::TestTask.new(:test) do |t|
|
7
|
-
t.libs <<
|
8
|
-
t.pattern =
|
9
|
+
t.libs << 'test'
|
10
|
+
t.pattern = 'test/**/*_test.rb'
|
9
11
|
t.verbose = false
|
10
12
|
end
|
11
13
|
|
@@ -15,15 +15,10 @@ module UtilityClasses
|
|
15
15
|
end
|
16
16
|
|
17
17
|
def for(type, variant: nil)
|
18
|
-
reload_config
|
18
|
+
reload_config if config_changed?
|
19
19
|
|
20
|
-
classes =
|
21
|
-
|
22
|
-
|
23
|
-
if variant
|
24
|
-
variant_classes = styles.dig(type, :variants, variant)
|
25
|
-
raise UtilityClasses::Exceptions::VariantKeyNotFound.new(variant_key: variant) unless variant_classes
|
26
|
-
end
|
20
|
+
classes = retrieve_classes_for_type(type)
|
21
|
+
variant_classes = retrieve_classes_for_variant(type, variant) if variant
|
27
22
|
|
28
23
|
variant_classes ? "#{classes} #{variant_classes}" : classes
|
29
24
|
end
|
@@ -40,7 +35,7 @@ module UtilityClasses
|
|
40
35
|
Rails.root.join('config/utility_classes.yml')
|
41
36
|
end
|
42
37
|
|
43
|
-
def reload_config
|
38
|
+
def reload_config
|
44
39
|
@styles = data_from_config
|
45
40
|
@last_updated = File.ctime(config_file)
|
46
41
|
end
|
@@ -50,5 +45,19 @@ module UtilityClasses
|
|
50
45
|
|
51
46
|
last_updated != File.ctime(config_file)
|
52
47
|
end
|
48
|
+
|
49
|
+
def retrieve_classes_for_type(type)
|
50
|
+
classes = styles.dig(type, :base)
|
51
|
+
raise UtilityClasses::Exceptions::TypeKeyNotFound.new(type_key: type) unless classes
|
52
|
+
|
53
|
+
classes
|
54
|
+
end
|
55
|
+
|
56
|
+
def retrieve_classes_for_variant(type, variant)
|
57
|
+
classes = styles.dig(type, :variants, variant)
|
58
|
+
raise UtilityClasses::Exceptions::VariantKeyNotFound.new(variant_key: variant) unless classes
|
59
|
+
|
60
|
+
classes
|
61
|
+
end
|
53
62
|
end
|
54
63
|
end
|
data/lib/utility_classes.rb
CHANGED
@@ -4,6 +4,9 @@ require 'rails'
|
|
4
4
|
require 'active_support/dependencies'
|
5
5
|
require 'utility_classes/version'
|
6
6
|
require 'utility_classes/railtie'
|
7
|
+
require 'utility_classes/utility_class_reader'
|
8
|
+
require 'utility_classes/exceptions/type_key_not_found'
|
9
|
+
require 'utility_classes/exceptions/variant_key_not_found'
|
7
10
|
|
8
11
|
##
|
9
12
|
# Namespace for UtilityClasses gem
|
@@ -12,7 +15,6 @@ module UtilityClasses
|
|
12
15
|
autoload :TypeKeyNotFound, 'utility_classes/exceptions/type_key_not_found'
|
13
16
|
autoload :VariantKeyNotFound, 'utility_classes/exceptions/variant_key_not_found'
|
14
17
|
|
15
|
-
mattr_accessor :reader
|
16
18
|
def self.reader
|
17
19
|
@reader ||= UtilityClassReader.new
|
18
20
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: utility_classes
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dick Davis
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-12-
|
11
|
+
date: 2021-12-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -47,9 +47,10 @@ homepage: https://github.com/d3d1rty/utility_classes
|
|
47
47
|
licenses:
|
48
48
|
- MIT
|
49
49
|
metadata:
|
50
|
+
rubygems_mfa_required: 'true'
|
50
51
|
homepage_uri: https://github.com/d3d1rty/utility_classes
|
51
52
|
source_code_uri: https://github.com/d3d1rty/utility_classes
|
52
|
-
changelog_uri: https://github.com/d3d1rty/utility_classes
|
53
|
+
changelog_uri: https://github.com/d3d1rty/utility_classes/blob/main/CHANGELOG.md
|
53
54
|
post_install_message:
|
54
55
|
rdoc_options: []
|
55
56
|
require_paths:
|
@@ -58,14 +59,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
58
59
|
requirements:
|
59
60
|
- - ">="
|
60
61
|
- !ruby/object:Gem::Version
|
61
|
-
version: '
|
62
|
+
version: '2.7'
|
62
63
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
63
64
|
requirements:
|
64
65
|
- - ">="
|
65
66
|
- !ruby/object:Gem::Version
|
66
67
|
version: '0'
|
67
68
|
requirements: []
|
68
|
-
rubygems_version: 3.2
|
69
|
+
rubygems_version: 3.1.2
|
69
70
|
signing_key:
|
70
71
|
specification_version: 4
|
71
72
|
summary: Rails gem that facilitates the use of utility CSS frameworks.
|