class_variants 0.0.2 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/class_variants/action_view/helpers.rb +9 -0
- data/lib/class_variants/instance.rb +39 -0
- data/lib/class_variants/railtie.rb +12 -0
- data/lib/class_variants/version.rb +3 -0
- metadata +5 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4780d216a018db941e8e96886478a5aa7bd16f5248de9a676f015811928aa638
|
4
|
+
data.tar.gz: 17a48e550a1e22ebf16e9841e2b10252f4c1026656454ed8cd785879105bc5c6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cfa942f88c875214541e95ac2e9ce454934641570aaefb96d179120b1feefc27eb6df61f89525802f9f72ab46864364088b843cac78dd48b1d4572f89aa02d60
|
7
|
+
data.tar.gz: 427590f3b012493e159675cd96f22f7a206f171656fb22727dc0e44c93f831580c89c4ffe960a09ea37f8e75459831f39289d8cd79c4b57c63a5289d11eeb6f8
|
@@ -0,0 +1,39 @@
|
|
1
|
+
class ClassVariants::Instance
|
2
|
+
attr_reader :classes
|
3
|
+
attr_reader :variants
|
4
|
+
attr_reader :defaults
|
5
|
+
|
6
|
+
def initialize(classes = "", variants: {}, defaults: {})
|
7
|
+
@classes = classes
|
8
|
+
@variants = variants
|
9
|
+
@defaults = defaults
|
10
|
+
end
|
11
|
+
|
12
|
+
def render(**settings)
|
13
|
+
result = []
|
14
|
+
|
15
|
+
# Add the default classes if any provided
|
16
|
+
result << classes if classes
|
17
|
+
|
18
|
+
# Keep the applied variants so we can later apply the defaults
|
19
|
+
applied_options = []
|
20
|
+
|
21
|
+
# Go through each keys provided
|
22
|
+
settings.each do |key, value|
|
23
|
+
if variants.keys.include? key
|
24
|
+
applied_options << key
|
25
|
+
result << variants[key][value]
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
if defaults.present?
|
30
|
+
defaults.each do |key, key_to_use|
|
31
|
+
unless applied_options.include? key
|
32
|
+
result << @variants[key][key_to_use] if @variants[key].present?
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
result.join " "
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'rails/railtie'
|
2
|
+
|
3
|
+
module ClassVariants
|
4
|
+
class Railtie < ::Rails::Railtie
|
5
|
+
initializer "class_variants.action_view" do |app|
|
6
|
+
ActiveSupport.on_load :action_view do
|
7
|
+
require "class_variants/action_view/helpers"
|
8
|
+
include ClassVariants::ActionView::Helpers
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: class_variants
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Adrian Marin
|
@@ -17,6 +17,10 @@ extensions: []
|
|
17
17
|
extra_rdoc_files: []
|
18
18
|
files:
|
19
19
|
- lib/class_variants.rb
|
20
|
+
- lib/class_variants/action_view/helpers.rb
|
21
|
+
- lib/class_variants/instance.rb
|
22
|
+
- lib/class_variants/railtie.rb
|
23
|
+
- lib/class_variants/version.rb
|
20
24
|
homepage: https://github.com/avo-hq/class_variants
|
21
25
|
licenses:
|
22
26
|
- MIT
|