phlexy_ui 0.1.15 → 0.1.18

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: 54f0cc8b2a831ce17e7db2594b848d14c374e2d59d057a0fea04c9695cc3d059
4
- data.tar.gz: f3c4226ae079c44c46ba49da6ca0e0b53709414f4022264bca190d23de3e05e4
3
+ metadata.gz: e28571932626bbfb52238b529c6dfe67ba038b32c2c735377667fa0005974295
4
+ data.tar.gz: 820d96f4249069a762071132fcbe977bd78b00b54aa9e86b4f44622459c73628
5
5
  SHA512:
6
- metadata.gz: 6bc67b1c3b0321b1f4c3d78b7e1e7524d5fad019b97925f226be89a27721d90cc13f904f26797f72bc42e169ffc0b18dfc5e4128f23431c668fabbdb63943dac
7
- data.tar.gz: 246e8df27ac5d8c48377e05fb91be4513fcfcdcb9aa4da3e1bfb40af1c62cfe5ce9a95930ca1fb4f90e8202bed4310732dc171df5ae742a6cbfbc4b2633199c0
6
+ metadata.gz: 70be19b85cf1ce3d9eb6f0837f207399830901e3dd3d8556e7881eb612c4cf6c99b022609743d51d6fa58ab08a18e919806d211490a05aa5f5a52591f474db41
7
+ data.tar.gz: d1e10d0c19ca19d07159e60a98cd3a34669cf368166231ba9ed87b3dd3b8109bba0c2f8637df5a7fdd5f02353a606738f6d873c9957327a21f346d5b28398c05
@@ -13,76 +13,70 @@ module PhlexyUI
13
13
  @base_modifiers = base_modifiers
14
14
  @options = options
15
15
  @modifiers_map = modifiers_map
16
+ @responsive_options = options.delete(:responsive)
16
17
  end
17
18
 
18
19
  def to_a
19
- classes = []
20
- add_component_class(classes)
21
- add_selected_modifiers_classes(classes)
22
- add_conditioned_modifiers_classes(classes)
23
- add_responsive_modifiers_classes(classes)
24
- add_class_option_classes(classes)
25
- classes
20
+ [
21
+ component_classes,
22
+ modifier_classes,
23
+ responsive_classes,
24
+ options.delete(:class)
25
+ ].flatten.compact
26
26
  end
27
27
 
28
28
  private
29
29
 
30
- attr_reader :component_html_class, :base_modifiers, :options, :modifiers_map
30
+ attr_reader :component_html_class,
31
+ :base_modifiers,
32
+ :options,
33
+ :modifiers_map,
34
+ :responsive_options
31
35
 
32
- def selected_base_modifiers
33
- base_modifiers.select { |modifier| modifiers_map.key?(modifier) }
34
- end
35
-
36
- def add_component_class(classes)
36
+ def component_classes
37
37
  return unless component_html_class
38
+ return if responsive_options&.values&.any? do |v|
39
+ v == true || (v.is_a?(Array) && v.include?(true))
40
+ end
38
41
 
39
- classes << with_config_prefix(component_html_class)
42
+ with_config_prefix(component_html_class)
40
43
  end
41
44
 
42
- def add_selected_modifiers_classes(classes)
43
- classes.concat(
44
- html_classes_for_modifiers(
45
- selected_base_modifiers
46
- )
47
- )
45
+ def modifier_classes
46
+ (selected_base_modifiers + conditioned_modifiers).map do |modifier|
47
+ with_config_prefix(modifiers_map[modifier])
48
+ end
48
49
  end
49
50
 
50
- def add_conditioned_modifiers_classes(classes)
51
- modifiers_map.each do |modifier, class_name|
52
- next unless options.delete(modifier)
53
-
54
- classes << with_config_prefix(class_name)
55
- end
51
+ def selected_base_modifiers
52
+ base_modifiers.select { |modifier| modifiers_map.key?(modifier) }
56
53
  end
57
54
 
58
- def html_classes_for_modifiers(modifiers, responsive_prefix: nil)
59
- modifiers.map do |modifier|
60
- with_responsive_prefix(
61
- with_config_prefix(
62
- modifiers_map.fetch(modifier)
63
- ),
64
- responsive_prefix
65
- )
66
- end
55
+ def conditioned_modifiers
56
+ modifiers_map.keys.select { |modifier| options.delete(modifier) }
67
57
  end
68
58
 
69
- def add_responsive_modifiers_classes(classes)
70
- return unless (responsive_options = options.delete(:responsive))
71
-
72
- RESPONSIVE_PREFIXES.each do |responsive_prefix|
73
- if (values = responsive_options[responsive_prefix])
74
- classes.concat(
75
- html_classes_for_modifiers(
76
- Array(values),
77
- responsive_prefix:
78
- )
79
- )
59
+ def responsive_classes
60
+ return unless responsive_options
61
+
62
+ RESPONSIVE_PREFIXES.flat_map do |prefix|
63
+ next unless responsive_options[prefix]
64
+
65
+ values = Array(responsive_options[prefix])
66
+
67
+ component_responsive_class =
68
+ if values.delete(true)
69
+ [with_responsive_prefix(with_config_prefix(component_html_class), prefix)]
70
+ else
71
+ []
72
+ end
73
+
74
+ modifier_responsive_classes = values.map do |v|
75
+ with_responsive_prefix(with_config_prefix(modifiers_map[v]), prefix)
80
76
  end
81
- end
82
- end
83
77
 
84
- def add_class_option_classes(classes)
85
- classes << options.delete(:class) if options[:class]
78
+ component_responsive_class + modifier_responsive_classes
79
+ end
86
80
  end
87
81
 
88
82
  def with_config_prefix(string)
@@ -91,14 +85,8 @@ module PhlexyUI
91
85
  end.join(" ")
92
86
  end
93
87
 
94
- def with_responsive_prefix(string, responsive_prefix = nil)
95
- string.split.map do |word|
96
- if responsive_prefix
97
- "#{responsive_prefix}:#{word}"
98
- else
99
- word
100
- end
101
- end.join(" ")
88
+ def with_responsive_prefix(string, prefix)
89
+ string.to_s.split.map { |word| "#{prefix}:#{word}" }.join(" ")
102
90
  end
103
91
  end
104
92
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module PhlexyUI
4
- VERSION = "0.1.15"
4
+ VERSION = "0.1.18"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: phlexy_ui
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.15
4
+ version: 0.1.18
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Alejandro Aguilar Ramos