philiprehberger-html_builder 0.4.0 → 0.5.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 +5 -0
- data/README.md +22 -0
- data/lib/philiprehberger/html_builder/builder.rb +20 -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: c951cd5a9e74ab6642a9181b01235a4a5a63b39015fd05cf5c41ab0157bc6106
|
|
4
|
+
data.tar.gz: ab129d21a86612912a83f460cd49424b4005ac95fe6f7c8c6471f3f5309a6640
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: c6ceba75c99ca6620ba8434521b02703cb42d0113f662fe0789928dec1b1e38f4e3057c4fd44495eefd30bd53d08127d6b95daa470e4d67bf15ed56f61e085a9
|
|
7
|
+
data.tar.gz: c70fd51be8e402a223a7a1114a0f0950dd66267f2cf20506a1437a32905ba3185634a980fa314fd9785c985600a947890e05768b35dccdaabdbb40a395cb0191
|
data/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [0.5.0] - 2026-04-15
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
- `list(items, ordered: false, **attrs, &block)` helper for building `<ul>` or `<ol>` lists from an array of items with optional custom rendering via block
|
|
14
|
+
|
|
10
15
|
## [0.4.0] - 2026-04-15
|
|
11
16
|
|
|
12
17
|
### Added
|
data/README.md
CHANGED
|
@@ -142,6 +142,27 @@ Philiprehberger::HtmlBuilder.build do
|
|
|
142
142
|
end
|
|
143
143
|
```
|
|
144
144
|
|
|
145
|
+
### Lists
|
|
146
|
+
|
|
147
|
+
Build `<ul>` or `<ol>` lists from an array of items. Items are text-escaped by default. Pass `ordered: true` for an ordered list. Use a block for custom rendering of each item:
|
|
148
|
+
|
|
149
|
+
```ruby
|
|
150
|
+
Philiprehberger::HtmlBuilder.build do
|
|
151
|
+
list(%w[Apple Banana Cherry])
|
|
152
|
+
end
|
|
153
|
+
# => '<ul><li>Apple</li><li>Banana</li><li>Cherry</li></ul>'
|
|
154
|
+
|
|
155
|
+
Philiprehberger::HtmlBuilder.build do
|
|
156
|
+
list(%w[First Second], ordered: true, class: 'steps')
|
|
157
|
+
end
|
|
158
|
+
# => '<ol class="steps"><li>First</li><li>Second</li></ol>'
|
|
159
|
+
|
|
160
|
+
Philiprehberger::HtmlBuilder.build do
|
|
161
|
+
list(%w[Alice Bob]) { |name| strong name }
|
|
162
|
+
end
|
|
163
|
+
# => '<ul><li><strong>Alice</strong></li><li><strong>Bob</strong></li></ul>'
|
|
164
|
+
```
|
|
165
|
+
|
|
145
166
|
### CSS Class Helpers
|
|
146
167
|
|
|
147
168
|
Build conditional CSS class strings from mixed arguments. Strings are included as-is, hash keys are included when their value is truthy:
|
|
@@ -274,6 +295,7 @@ Philiprehberger::HtmlBuilder.merge(header, body, footer)
|
|
|
274
295
|
| `Builder#textarea_field(name, content, label_text:, **attrs)` | Build a label + textarea |
|
|
275
296
|
| `Builder#hidden_field(name, value)` | Generate a hidden input element |
|
|
276
297
|
| `Builder#submit(text, **attrs)` | Generate a submit button (default text "Submit") |
|
|
298
|
+
| `Builder#list(items, ordered:, **attrs, &block)` | Build a `<ul>` or `<ol>` from an array of items |
|
|
277
299
|
| `Builder#class_names(*args)` | Build a conditional CSS class string from strings and hashes |
|
|
278
300
|
| `Builder#cache(key) { ... }` | Cache rendered block output by key; return cached HTML on repeat calls |
|
|
279
301
|
| `Escape.html(value)` | Escape HTML special characters in a string |
|
|
@@ -216,6 +216,26 @@ module Philiprehberger
|
|
|
216
216
|
button(text, type: 'submit', **attrs)
|
|
217
217
|
end
|
|
218
218
|
|
|
219
|
+
# Build a list (ul or ol) from an array of items
|
|
220
|
+
#
|
|
221
|
+
# @param items [Array] the list items
|
|
222
|
+
# @param ordered [Boolean] use ol instead of ul (default false)
|
|
223
|
+
# @param attrs [Hash] additional attributes for the list element
|
|
224
|
+
# @yield [item] optional block for custom rendering of each item
|
|
225
|
+
# @return [Node]
|
|
226
|
+
def list(items, ordered: false, **attrs, &block)
|
|
227
|
+
tag_name = ordered ? :ol : :ul
|
|
228
|
+
send(tag_name, **attrs) do
|
|
229
|
+
items.each do |item|
|
|
230
|
+
if block
|
|
231
|
+
li { block.call(item) }
|
|
232
|
+
else
|
|
233
|
+
li item.to_s
|
|
234
|
+
end
|
|
235
|
+
end
|
|
236
|
+
end
|
|
237
|
+
end
|
|
238
|
+
|
|
219
239
|
# Build a space-joined CSS class string from mixed arguments
|
|
220
240
|
#
|
|
221
241
|
# Strings are included as-is. Hash keys are included when their value is truthy.
|
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.5.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-04-
|
|
11
|
+
date: 2026-04-16 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.
|