philiprehberger-html_builder 0.7.0 → 0.8.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 +6 -0
- data/README.md +22 -0
- data/lib/philiprehberger/html_builder/builder.rb +22 -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: ae55b58a30868dfa5bc7afd1f3300723c88c8f05e97470571a02619e07dd3dfd
|
|
4
|
+
data.tar.gz: 39f947b3d37ac2a914da3fa42f99dd9a3fddd9d43b09498d548b03eae269b694
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: e4147ae709bc12f9c0d422169e2a8183bc90a92d3ae9b19cda6c62ad7fa927923b436d0a68f1c496eee6de843d9585a26a60786fee3611c3bcf8c765cf0365bd
|
|
7
|
+
data.tar.gz: 37cbec88f3da3293458bdbd8c42270c44d7f6f1b6f1e4b7052154968df53de570f9921dd27f9dde0a4221c56cf1ade5902168c2b98bd7af1f32327134b0b08f2
|
data/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [0.8.0] - 2026-05-20
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
- `Builder#capture { ... }` — render a block in an isolated scope and return the HTML as a string without appending to the current document. Inherits previously defined components, so component reuse works inside captured fragments. Pairs naturally with `Builder#raw` for inserting the captured HTML into the document.
|
|
14
|
+
- Card image reference in the README for registry-side rendering
|
|
15
|
+
|
|
10
16
|
## [0.7.0] - 2026-04-26
|
|
11
17
|
|
|
12
18
|
### Added
|
data/README.md
CHANGED
|
@@ -4,6 +4,8 @@
|
|
|
4
4
|
[](https://rubygems.org/gems/philiprehberger-html_builder)
|
|
5
5
|
[](https://github.com/philiprehberger/rb-html-builder/commits/main)
|
|
6
6
|
|
|
7
|
+

|
|
8
|
+
|
|
7
9
|
Programmatic HTML builder with tag DSL, auto-escaping, form helpers, components, and output formatting
|
|
8
10
|
|
|
9
11
|
## Requirements
|
|
@@ -198,6 +200,25 @@ end
|
|
|
198
200
|
# => <div class="btn btn-lg active">Click me</div>
|
|
199
201
|
```
|
|
200
202
|
|
|
203
|
+
### Capturing Fragments
|
|
204
|
+
|
|
205
|
+
Render a block in a separate scope and capture the HTML as a string instead of appending it to the document. Useful when the same fragment is needed in more than one place or as a value:
|
|
206
|
+
|
|
207
|
+
```ruby
|
|
208
|
+
Philiprehberger::HtmlBuilder.build do
|
|
209
|
+
badge = capture { strong 'NEW', class: 'badge' }
|
|
210
|
+
article do
|
|
211
|
+
h2 'Headline'
|
|
212
|
+
raw badge
|
|
213
|
+
p 'Body text'
|
|
214
|
+
raw badge
|
|
215
|
+
end
|
|
216
|
+
end
|
|
217
|
+
# => <article><h2>Headline</h2><strong class="badge">NEW</strong><p>Body text</p><strong class="badge">NEW</strong></article>
|
|
218
|
+
```
|
|
219
|
+
|
|
220
|
+
`capture` inherits any components defined on the parent builder, so component reuse works inside captured fragments.
|
|
221
|
+
|
|
201
222
|
### Fragment Caching
|
|
202
223
|
|
|
203
224
|
Cache rendered block results by key. On subsequent calls with the same key, the cached HTML is returned without re-executing the block:
|
|
@@ -349,6 +370,7 @@ Philiprehberger::HtmlBuilder.merge(header, body, footer)
|
|
|
349
370
|
| `Builder#merge_attrs(*hashes)` | Merge attribute hashes, concatenating `:class` (space) and `:style` (`'; '`) values |
|
|
350
371
|
| `Builder#aria(**pairs)` | Build an ARIA attribute hash from snake_case keys (rendered as `aria-kebab-case`); omits nil values |
|
|
351
372
|
| `Builder#cache(key) { ... }` | Cache rendered block output by key; return cached HTML on repeat calls |
|
|
373
|
+
| `Builder#capture { ... }` | Render the block in an isolated scope and return its HTML string (no append) |
|
|
352
374
|
| `Escape.html(value)` | Escape HTML special characters in a string |
|
|
353
375
|
|
|
354
376
|
## Development
|
|
@@ -308,6 +308,28 @@ module Philiprehberger
|
|
|
308
308
|
result
|
|
309
309
|
end
|
|
310
310
|
|
|
311
|
+
# Render a block in an isolated builder scope and return the HTML string
|
|
312
|
+
# without appending anything to the current document.
|
|
313
|
+
#
|
|
314
|
+
# Useful for template helpers that need to compute a fragment once and
|
|
315
|
+
# then insert it in multiple places (e.g. via {#raw}) or pass it as a
|
|
316
|
+
# string attribute (e.g. ``title:`` containing a small piece of escaped
|
|
317
|
+
# markup) — none of which can be expressed with the regular tag DSL
|
|
318
|
+
# because every tag method side-effects into the current scope.
|
|
319
|
+
#
|
|
320
|
+
# @yield block evaluated against a fresh builder; the same DSL methods
|
|
321
|
+
# (tags, `text`, `raw`, components, etc.) are available
|
|
322
|
+
# @return [String] the captured HTML (minified)
|
|
323
|
+
# @raise [Error] if no block is given
|
|
324
|
+
def capture(&block)
|
|
325
|
+
raise Error, 'a block is required for capture' unless block
|
|
326
|
+
|
|
327
|
+
nested = Builder.new
|
|
328
|
+
@components.each { |name, b| nested.instance_variable_get(:@components)[name] = b }
|
|
329
|
+
nested.instance_eval(&block)
|
|
330
|
+
nested.to_html
|
|
331
|
+
end
|
|
332
|
+
|
|
311
333
|
# Cache a rendered block result by key
|
|
312
334
|
#
|
|
313
335
|
# On the first call with a given key, the block is executed, its rendered
|
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.8.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-
|
|
11
|
+
date: 2026-05-20 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.
|