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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ebf11e0859fc84f7928583f086575ea80626453438a19ef1740e6fcbb36c8a53
4
- data.tar.gz: 544c439e27d9f85b30e2e9228ec3764035f7bed0e7029aa06e4240b8e1f05135
3
+ metadata.gz: 9a6e5099e722349306f58dae45a7e1d694eb964a4328d2c9f58b59c1c92144c9
4
+ data.tar.gz: 04f373b712af10ce1b282941b89b7eca1206056a6a9dd7049e3440cb2dacd8ae
5
5
  SHA512:
6
- metadata.gz: 78c0d296405a00af4cdb1624bf24ca972e7e384a156a9fa275e31213b68ed6f4647b3c87d1057a63f84eb84cca9ff42556a14f697915a32e07f40ef98e625311
7
- data.tar.gz: 966fcf3ea287899bd494ae167b613dd0d222daedef433aae17747e3983ee5e567f95d40bd97c225b0ed988874b707c1587ad9bb8960d6a717d393022da8806a7
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: 'text-lg font-semibold text-center'
31
+ base: 'font-semibold text-center'
29
32
  variants:
30
- grande: 'text-4xl'
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: :grande)
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
- require "bundler/setup"
1
+ # frozen_string_literal: true
2
2
 
3
- require "bundler/gem_tasks"
4
- require "rake/testtask"
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 << "test"
8
- t.pattern = "test/**/*_test.rb"
9
+ t.libs << 'test'
10
+ t.pattern = 'test/**/*_test.rb'
9
11
  t.verbose = false
10
12
  end
11
13
 
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  # desc "Explaining what the task does"
2
3
  # task :utility_classes do
3
4
  # # Task goes here
@@ -1,4 +1,8 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module UtilityClasses
4
+ ##
5
+ # Railtie for UtilityClasses
2
6
  class Railtie < ::Rails::Railtie
3
7
  end
4
8
  end
@@ -15,15 +15,10 @@ module UtilityClasses
15
15
  end
16
16
 
17
17
  def for(type, variant: nil)
18
- reload_config! if config_changed?
18
+ reload_config if config_changed?
19
19
 
20
- classes = styles.dig(type, :base)
21
- raise UtilityClasses::Exceptions::TypeKeyNotFound.new(type_key: type) unless classes
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module UtilityClasses
4
- VERSION = '0.1.1'
4
+ VERSION = '0.2.0'
5
5
  end
@@ -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.1.1
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-05 00:00:00.000000000 Z
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: '0'
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.15
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.