Skip to content

Add configurable placeholder delimiters#133

Open
okriuchykhin wants to merge 1 commit into
sandrods:masterfrom
okriuchykhin:configurable_delimeters
Open

Add configurable placeholder delimiters#133
okriuchykhin wants to merge 1 commit into
sandrods:masterfrom
okriuchykhin:configurable_delimeters

Conversation

@okriuchykhin

Copy link
Copy Markdown

Lets users choose the delimiter style used to wrap field names in templates, instead of being locked to [NAME].

Why

The [ ] delimiter is hardcoded, which clashes with templates that legitimately contain square brackets and rules out the {{ }} style many users expect from other templating tools. This makes the delimiter a configuration choice while keeping the default unchanged.

What

  • New ODFReport.delimiters= setting accepting a preset (:square, :curly) or a custom two-element pair, e.g. ["((", "))"]. Default stays :square, so existing templates are unaffected.
  • ODFReport.with_delimiters(value) { ... } block helper to scope a choice to a single render and restore the previous value afterward.
  • Validation rejects malformed pairs and any delimiter containing the XML metacharacters < > &, since those are escaped in the document and would silently never match.
  • All placeholder types (fields, texts, images) pick this up automatically, since they resolve through Field#to_placeholder.

Notes

  • Placeholder names are still upper-cased, so under :curly the token for add_field(:name) is {{NAME}}.
  • The setting is process-global; documented as not thread-safe for concurrently rendering reports that need different delimiters.

Tests / docs

  • Added test/configurable_delimiters_test.rb covering the default, each preset, a custom pair, block scoping with restore, and the validation cases.
  • Added a "Configurable delimiters" section to the README.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant