Azu::Helpers::Registry
Thread-safe registry for template helpers.
The Registry stores all registered filters, functions, globals, and tests, then applies them to the Crinja environment when templates are rendered.
Thread Safety
All operations are protected by a mutex to ensure thread-safe registration from multiple fibers during application startup.
Usage
Helpers are typically registered via the DSL macros in Azu::Helpers,
but can also be registered directly:
filter = Crinja.filter(:my_filter) { target.to_s.upcase }
Azu::Helpers::Registry.register_filter(:my_filter, filter)
Class methods
Check if a specific Crinja instance has had helpers applied.
Apply all registered helpers to a Crinja environment.
This method is idempotent - calling it multiple times on the same Crinja instance will only apply helpers once.
crinja = Crinja.new
Registry.apply_to(crinja)
Register a filter by name.
filter = Crinja.filter(:upcase) { target.to_s.upcase }
Registry.register_filter(:upcase, filter)
Register a function by name.
func = Crinja.function(:now) { Time.utc.to_s }
Registry.register_function(:now, func)
Register a global variable.
Registry.register_global(:app_name, "My App")
Register a test by name.
test = Crinja.test(:blank) { target.to_s.blank? }
Registry.register_test(:blank, test)
Reset all registered helpers.
Useful for testing to ensure a clean slate.
Registry.reset!