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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1a1603e5f6aca91335bcd511801b9bf397d9dfc1b003f96113991639b5a36133
4
- data.tar.gz: 3ec0488c7996705017a7d33cf53a0b1828557b602efbf312d271f5e6b062f99e
3
+ metadata.gz: c951cd5a9e74ab6642a9181b01235a4a5a63b39015fd05cf5c41ab0157bc6106
4
+ data.tar.gz: ab129d21a86612912a83f460cd49424b4005ac95fe6f7c8c6471f3f5309a6640
5
5
  SHA512:
6
- metadata.gz: 7694f0a5189a3f0fb4bfe1eac88edc7ef971ab6d48c21d280eb26d7bbd9d0048728effe37f89c14ec770296def739a12ac2c4d65ecef97502dba9924f3226765
7
- data.tar.gz: f156d490b18bf1a1db8010064e0d2fd83887b7928faf24558290844b27189e40aa23132adf8984e9f7481348702df825cd616bba6c4b956884c6c170175c74af
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.
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Philiprehberger
4
4
  module HtmlBuilder
5
- VERSION = '0.4.0'
5
+ VERSION = '0.5.0'
6
6
  end
7
7
  end
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.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-15 00:00:00.000000000 Z
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.