Commit f5f216a
committed
Implement PlaceholderFormatter for template interpolation
I wanted to create a way to build dynamic, context-aware messages, similar to
what we currently have in the Validation component. My long-term goal is to
decouple string formatting from Validation and centralize it here in
StringFormatter. This commit introduces the `PlaceholderFormatter`, which
brings a familiar `{{placeholder}}` syntax to our toolkit.
Recognizing that creating a new object for every unique template can be
cumbersome, I have introduced the `formatWith()` method. This allows for
additional data injection at call-time. However, to maintain predictability,
I’ve established a clear hierarchy: parameters provided in the constructor are
treated as the "primary" configuration and will always take precedence over
call-time parameters. This ensures that a pre-configured formatter behaves
consistently even when used in a dynamic context.
By moving this logic here, we lay the groundwork for a more modular system
where formatting is a first-class citizen rather than a utility hidden
inside other components.
Assisted-by: Claude Code (Opus 4.5)1 parent 448b55e commit f5f216a
5 files changed
Lines changed: 1042 additions & 5 deletions
File tree
- docs
- src
- tests/Unit
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
19 | | - | |
20 | | - | |
21 | | - | |
22 | | - | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
23 | 24 | | |
24 | 25 | | |
25 | 26 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
7 | | - | |
| 7 | + | |
| 8 | + | |
8 | 9 | | |
9 | 10 | | |
10 | 11 | | |
| |||
0 commit comments