has_dom_attrs 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.ruby-version +1 -1
- data/CHANGELOG.md +8 -0
- data/README.md +5 -4
- data/lib/has_dom_attrs/version.rb +1 -1
- data/lib/has_dom_attrs.rb +14 -2
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3b032dc497dd42642b1d7c421d320a00c8b0fb3c3001bf3a89a24729a3fcf24f
|
4
|
+
data.tar.gz: fa78eb0aaf54e8e6c6ae9d2f29dcb1b047c03521bdbad17245860b28d2ea3e82
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 864d0080a6c147167eb701d97dd62007b06146d9c4f227696a7b9a61d808ff06bd5ba236d3eea9cb13323adda7ab039b77a7f7df0caa8c765347a6272cbd0ef8
|
7
|
+
data.tar.gz: f9ac611544b7a26fdb2fa32d771fab288fc5c44a7ab2a66f45724c490b0bda784f891e007c5d3ad9d0e1cefc3b3ba3084ea0a8aa42494248f4e0f1ef5c9c1303
|
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
3.
|
1
|
+
3.3.4
|
data/CHANGELOG.md
ADDED
data/README.md
CHANGED
@@ -54,7 +54,7 @@ component.dom_attrs
|
|
54
54
|
# => { open: "true" }
|
55
55
|
```
|
56
56
|
|
57
|
-
Likewise you can set classes, data, and aria attributes:
|
57
|
+
Likewise you can set classes, data, style, and aria attributes:
|
58
58
|
|
59
59
|
```ruby
|
60
60
|
class ModalComponent
|
@@ -62,8 +62,9 @@ class ModalComponent
|
|
62
62
|
|
63
63
|
has_dom_attr :open
|
64
64
|
has_dom_class -> { "modal--width_#{width}" }
|
65
|
-
has_dom_aria :
|
65
|
+
has_dom_aria :modal, if: :open
|
66
66
|
has_dom_data :width
|
67
|
+
has_dom_style :font_size, -> { "12px" }
|
67
68
|
|
68
69
|
attr_reader :open
|
69
70
|
|
@@ -77,7 +78,7 @@ end
|
|
77
78
|
```ruby
|
78
79
|
component = ModalComponent.new(open: true, width: :l)
|
79
80
|
component.dom_attrs
|
80
|
-
# => { open: "true",
|
81
|
+
# => { open: "true", aria: { modal: true }, class: "modal--width_l", data: { width: "l" }, style: "font-size: 12px; }
|
81
82
|
```
|
82
83
|
|
83
84
|
## Development
|
@@ -88,4 +89,4 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
|
|
88
89
|
|
89
90
|
## Contributing
|
90
91
|
|
91
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/
|
92
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/tomasc/has_dom_attrs.
|
data/lib/has_dom_attrs.rb
CHANGED
@@ -55,6 +55,10 @@ module HasDomAttrs
|
|
55
55
|
)
|
56
56
|
end
|
57
57
|
|
58
|
+
def has_dom_style(name, value = nil, **options)
|
59
|
+
prepend___has_dom___method(:dom_style, name, value, **options)
|
60
|
+
end
|
61
|
+
|
58
62
|
private
|
59
63
|
def prepend___has_dom___method(method_name, name, value = nil, **options)
|
60
64
|
prepend(
|
@@ -92,7 +96,7 @@ module HasDomAttrs
|
|
92
96
|
aria: dom_aria,
|
93
97
|
class: dom_classes,
|
94
98
|
data: dom_data,
|
95
|
-
style: dom_style
|
99
|
+
style: dom_style.to_s
|
96
100
|
}.reject { |_, v| v.nil? || v.empty? }
|
97
101
|
.deep_stringify_keys
|
98
102
|
.deep_transform_keys(&:dasherize)
|
@@ -111,6 +115,14 @@ module HasDomAttrs
|
|
111
115
|
end
|
112
116
|
|
113
117
|
def dom_style
|
114
|
-
|
118
|
+
DomStyle.new({})
|
119
|
+
end
|
120
|
+
|
121
|
+
class DomStyle < SimpleDelegator
|
122
|
+
def to_s
|
123
|
+
__getobj__.reject { |_, value| value.nil? }
|
124
|
+
.map { |key, value| "#{key.to_s.dasherize}: #{value};" }
|
125
|
+
.join(" ")
|
126
|
+
end
|
115
127
|
end
|
116
128
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: has_dom_attrs
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tomas Celizna
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: exe
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2024-07-25 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport
|
@@ -105,6 +105,7 @@ extra_rdoc_files: []
|
|
105
105
|
files:
|
106
106
|
- ".rubocop.yml"
|
107
107
|
- ".ruby-version"
|
108
|
+
- CHANGELOG.md
|
108
109
|
- Gemfile
|
109
110
|
- LICENSE
|
110
111
|
- README.md
|
@@ -135,7 +136,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
135
136
|
- !ruby/object:Gem::Version
|
136
137
|
version: '0'
|
137
138
|
requirements: []
|
138
|
-
rubygems_version: 3.
|
139
|
+
rubygems_version: 3.5.11
|
139
140
|
signing_key:
|
140
141
|
specification_version: 4
|
141
142
|
summary: Helper methods for dealing with html element attributes.
|