phlexy_ui 0.1.18 → 0.1.20

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: e28571932626bbfb52238b529c6dfe67ba038b32c2c735377667fa0005974295
4
- data.tar.gz: 820d96f4249069a762071132fcbe977bd78b00b54aa9e86b4f44622459c73628
3
+ metadata.gz: e92e0e137db4f235a6271b85a4916c64d725a6201af324e31aae6774e52cfdc9
4
+ data.tar.gz: 4005ccdeece88c2ac24bbefff65fc36a3e9d14473028e04c9cadd6a55aa343e2
5
5
  SHA512:
6
- metadata.gz: 70be19b85cf1ce3d9eb6f0837f207399830901e3dd3d8556e7881eb612c4cf6c99b022609743d51d6fa58ab08a18e919806d211490a05aa5f5a52591f474db41
7
- data.tar.gz: d1e10d0c19ca19d07159e60a98cd3a34669cf368166231ba9ed87b3dd3b8109bba0c2f8637df5a7fdd5f02353a606738f6d873c9957327a21f346d5b28398c05
6
+ metadata.gz: 4cf059089b3566b9647f41b6fde7c227f34ae08d3b1d852afe9781c058ef9f2f684219871f450f9bf27592f0c2909cd9b274e7355d4332d65937b3f863966e8f
7
+ data.tar.gz: c69976c4a84ce88633bbcd8943f706af196fb5f45407bb5194dccd4830fd28de0e46bedba19b794171df89f11707e3765b20aa27ecc8652fbfdd07be5ad5ef60
@@ -1,28 +1,63 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module PhlexyUI
4
+ # @private
5
+ #
6
+ # Converts component modifiers and options into HTML attributes.
7
+ # This is an internal class used by Base components.
8
+ #
9
+ # Internal Usage:
10
+ # # Component defines an attributes map
11
+ # ATTRIBUTES_MAP = { open: { checked: true }, closed: true }
12
+ #
13
+ # # Attributes can come from modifiers or options:
14
+ # # tab(:open) #=> { checked: true }
15
+ # # tab(open: true) #=> { checked: true }
16
+ # # tab(open: false) #=> {}
17
+ # # tab(:closed) #=> { closed: true }
18
+ # # tab(closed: true) #=> { closed: true }
19
+ # # tab(closed: false) #=> {}
2
20
  class AttributeSet
3
- def initialize(base_modifiers, attributes_map)
21
+ def initialize(base_modifiers, options, attributes_map)
4
22
  @base_modifiers = base_modifiers
23
+ @options = options
5
24
  @attributes_map = attributes_map
6
25
  end
7
26
 
8
27
  def to_h
9
- attributes_modifiers.each_with_object({}) do |modifier, final_attributes_hash|
10
- value = attributes_map[modifier]
11
-
12
- if value.is_a?(Hash)
13
- final_attributes_hash.merge!(value)
14
- elsif value
15
- final_attributes_hash[modifier] = value
16
- end
28
+ result = {}
29
+
30
+ # Process modifiers first
31
+ base_modifiers.each do |modifier|
32
+ next unless attributes_map.key?(modifier)
33
+ next if options.key?(modifier)
34
+
35
+ process_attribute(modifier, true, result)
17
36
  end
37
+
38
+ # Then process options (overriding modifiers)
39
+ options.each do |key, value|
40
+ next unless attributes_map.key?(key)
41
+ next unless value
42
+
43
+ process_attribute(key, value, result)
44
+ end
45
+
46
+ result
18
47
  end
19
48
 
20
49
  private
21
50
 
22
- attr_reader :base_modifiers, :attributes_map
51
+ attr_reader :base_modifiers, :options, :attributes_map
23
52
 
24
- def attributes_modifiers
25
- base_modifiers.select { |modifier| attributes_map.key?(modifier) }
53
+ def process_attribute(key, value, result)
54
+ mapped_value = attributes_map[key]
55
+
56
+ if mapped_value.is_a?(Hash)
57
+ result.merge!(mapped_value)
58
+ else
59
+ result[key] = mapped_value
60
+ end
26
61
  end
27
62
  end
28
63
  end
@@ -48,8 +48,8 @@ module PhlexyUI
48
48
  end
49
49
  end
50
50
 
51
- def generate_attributes(base_modifiers, attributes_map)
52
- AttributeSet.new(base_modifiers, attributes_map).to_h
51
+ def generate_attributes(base_modifiers, options, attributes_map)
52
+ AttributeSet.new(base_modifiers, options, attributes_map).to_h
53
53
  end
54
54
 
55
55
  def render_as(*, as:, **, &)
@@ -3,7 +3,7 @@
3
3
  module PhlexyUI
4
4
  class Checkbox < Base
5
5
  def view_template(&)
6
- attributes = generate_attributes(base_modifiers, ATTRIBUTES_MAP)
6
+ attributes = generate_attributes(base_modifiers, options, ATTRIBUTES_MAP)
7
7
 
8
8
  generate_classes!(
9
9
  component_html_class: :checkbox,
@@ -11,7 +11,13 @@ module PhlexyUI
11
11
  base_modifiers:,
12
12
  options:
13
13
  ).then do |classes|
14
- input(type: :checkbox, class: classes, **options, **attributes, &)
14
+ input(
15
+ type: :checkbox,
16
+ class: classes,
17
+ **options.except(*ATTRIBUTES_MAP.keys),
18
+ **attributes,
19
+ &
20
+ )
15
21
  end
16
22
  end
17
23
 
@@ -11,7 +11,7 @@ module PhlexyUI
11
11
  end
12
12
 
13
13
  def view_template(&)
14
- attributes = generate_attributes(base_modifiers, ATTRIBUTES_MAP)
14
+ attributes = generate_attributes(base_modifiers, options, ATTRIBUTES_MAP)
15
15
 
16
16
  generate_classes!(
17
17
  base_modifiers:,
@@ -15,6 +15,7 @@ module PhlexyUI
15
15
 
16
16
  attributes = generate_attributes(
17
17
  base_modifiers,
18
+ options,
18
19
  ATTRIBUTES_MAP
19
20
  )
20
21
 
@@ -31,7 +32,7 @@ module PhlexyUI
31
32
  role: :tab,
32
33
  aria_label: title,
33
34
  **attributes,
34
- **options
35
+ **options.except(*ATTRIBUTES_MAP.keys)
35
36
  )
36
37
  end
37
38
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module PhlexyUI
4
- VERSION = "0.1.18"
4
+ VERSION = "0.1.20"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: phlexy_ui
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.18
4
+ version: 0.1.20
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Alejandro Aguilar Ramos
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-10-26 00:00:00.000000000 Z
11
+ date: 2024-11-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: phlex