philiprehberger-html_builder 0.8.0 → 0.9.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 +4 -4
- data/CHANGELOG.md +8 -0
- data/README.md +7 -1
- data/lib/philiprehberger/html_builder/builder.rb +19 -0
- data/lib/philiprehberger/html_builder/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 56b6f4a4c8e09045d724f5f67b3f8cec1e87fc2daddd397e04604cf13bcd33d8
|
|
4
|
+
data.tar.gz: 1b820c958ea1cafe11fa4aa415fb76b17aebef39aa611b6f100dedcdf01f2411
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: '0398ad1acd04f45d1e28dc890a8436e01d42b9ed4e9bab2f0ee6d8e278d505016f74bee609c8743a0f8e3d69c111b3e03c83e9e2779bcb7437a51f7167183e1a'
|
|
7
|
+
data.tar.gz: 693dbcc9294f41267f54e66ef5c9a082f24c1a222d4db7d3c648623a392cf8ca6e6a80ac7fea0c944eb080c87ef598fba5b1292829ac4cc6825495bbbe54f1c3
|
data/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [0.9.0] - 2026-05-30
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
- `HtmlBuilder.data(**attrs)` helper to build `data-*` attribute hashes, mirroring the existing `aria` helper
|
|
14
|
+
|
|
15
|
+
### Fixed
|
|
16
|
+
- Bug report issue template now includes a required `gem-version` field and marks `ruby-version` as required, matching the standard template
|
|
17
|
+
|
|
10
18
|
## [0.8.0] - 2026-05-20
|
|
11
19
|
|
|
12
20
|
### Added
|
data/README.md
CHANGED
|
@@ -183,9 +183,14 @@ Philiprehberger::HtmlBuilder.build do
|
|
|
183
183
|
aria(label: 'Save', expanded: false, describedby: nil)
|
|
184
184
|
end
|
|
185
185
|
# => { 'aria-label' => 'Save', 'aria-expanded' => 'false' }
|
|
186
|
+
|
|
187
|
+
Philiprehberger::HtmlBuilder.build do
|
|
188
|
+
data(controller: 'menu', modal_target: 'dialog', open: true)
|
|
189
|
+
end
|
|
190
|
+
# => { 'data-controller' => 'menu', 'data-modal-target' => 'dialog', 'data-open' => 'true' }
|
|
186
191
|
```
|
|
187
192
|
|
|
188
|
-
`merge_attrs` joins `:class` values with a single space and `:style` values with `'; '`. Other keys follow last-write-wins, and input hashes are not mutated. `aria` converts snake_case keys to `aria-kebab-case` string keys, stringifies values, and omits keys whose value is `nil`.
|
|
193
|
+
`merge_attrs` joins `:class` values with a single space and `:style` values with `'; '`. Other keys follow last-write-wins, and input hashes are not mutated. `aria` converts snake_case keys to `aria-kebab-case` string keys, stringifies values, and omits keys whose value is `nil`. `data` mirrors `aria` for the `data-*` attribute namespace.
|
|
189
194
|
|
|
190
195
|
### CSS Class Helpers
|
|
191
196
|
|
|
@@ -369,6 +374,7 @@ Philiprehberger::HtmlBuilder.merge(header, body, footer)
|
|
|
369
374
|
| `Builder#class_names(*args)` | Build a conditional CSS class string from strings and hashes |
|
|
370
375
|
| `Builder#merge_attrs(*hashes)` | Merge attribute hashes, concatenating `:class` (space) and `:style` (`'; '`) values |
|
|
371
376
|
| `Builder#aria(**pairs)` | Build an ARIA attribute hash from snake_case keys (rendered as `aria-kebab-case`); omits nil values |
|
|
377
|
+
| `Builder#data(**attrs)` | Build a `data-*` attribute hash from snake_case keys (rendered as `data-kebab-case`); omits nil values |
|
|
372
378
|
| `Builder#cache(key) { ... }` | Cache rendered block output by key; return cached HTML on repeat calls |
|
|
373
379
|
| `Builder#capture { ... }` | Render the block in an isolated scope and return its HTML string (no append) |
|
|
374
380
|
| `Escape.html(value)` | Escape HTML special characters in a string |
|
|
@@ -308,6 +308,25 @@ module Philiprehberger
|
|
|
308
308
|
result
|
|
309
309
|
end
|
|
310
310
|
|
|
311
|
+
# Build a `data-*` attribute hash from keyword pairs
|
|
312
|
+
#
|
|
313
|
+
# snake_case keys are converted to `data-kebab-case` string keys. Values are
|
|
314
|
+
# converted to strings. Keys whose value is `nil` are omitted from the result.
|
|
315
|
+
# String keys are passed through with a `data-` prefix and underscores
|
|
316
|
+
# converted to dashes (e.g. `"modal-target"` becomes `"data-modal-target"`).
|
|
317
|
+
#
|
|
318
|
+
# @param attrs [Hash] keyword pairs to convert into `data-*` attributes
|
|
319
|
+
# @return [Hash<String, String>] hash with `"data-*"` string keys and string values
|
|
320
|
+
def data(**attrs)
|
|
321
|
+
result = {}
|
|
322
|
+
attrs.each do |key, value|
|
|
323
|
+
next if value.nil?
|
|
324
|
+
|
|
325
|
+
result["data-#{key.to_s.tr('_', '-')}"] = value.to_s
|
|
326
|
+
end
|
|
327
|
+
result
|
|
328
|
+
end
|
|
329
|
+
|
|
311
330
|
# Render a block in an isolated builder scope and return the HTML string
|
|
312
331
|
# without appending anything to the current document.
|
|
313
332
|
#
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: philiprehberger-html_builder
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.9.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Philip Rehberger
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-05-
|
|
11
|
+
date: 2026-05-31 00:00:00.000000000 Z
|
|
12
12
|
dependencies: []
|
|
13
13
|
description: Build HTML programmatically using a clean tag DSL with nested blocks,
|
|
14
14
|
automatic content escaping, void element support, and attribute hashes.
|