class

Azu::Helpers::Registry

Inherits Reference < Object

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

applied_to?(crinja : Crinja) : Bool

Check if a specific Crinja instance has had helpers applied.

Source
apply_to(crinja : Crinja) : Nil

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)
Source
filter_count

Get count of registered filters.

Source
filters

Get all registered filters.

Source
function_count

Get count of registered functions.

Source
functions

Get all registered functions.

Source
global_count

Get count of registered globals.

Source
globals

Get all registered globals.

Source
has_filter?(name : Symbol) : Bool

Check if a filter is registered.

Source
has_function?(name : Symbol) : Bool

Check if a function is registered.

Source
has_global?(name : Symbol) : Bool

Check if a global is registered.

Source
has_test?(name : Symbol) : Bool

Check if a test is registered.

Source
register_filter(name : Symbol, filter : Crinja::Callable) : Nil

Register a filter by name.

filter = Crinja.filter(:upcase) { target.to_s.upcase }
Registry.register_filter(:upcase, filter)
Source
register_function(name : Symbol, function : Crinja::Callable) : Nil

Register a function by name.

func = Crinja.function(:now) { Time.utc.to_s }
Registry.register_function(:now, func)
Source
register_global(name : Symbol, value) : Nil

Register a global variable.

Registry.register_global(:app_name, "My App")
Source
register_test(name : Symbol, test : Crinja::Callable) : Nil

Register a test by name.

test = Crinja.test(:blank) { target.to_s.blank? }
Registry.register_test(:blank, test)
Source
reset!

Reset all registered helpers.

Useful for testing to ensure a clean slate.

Registry.reset!
Source
test_count

Get count of registered tests.

Source
tests

Get all registered tests.

Source