Sablon.Registry (sablon v0.4.3)

Copy Markdown View Source

Global registries for the pluggable parts of sablon.

The Ruby gem keeps these on class level (Sablon::Template.processors, Sablon::Processor::Document.field_handlers, Sablon::Content.types and Sablon::DOM.handlers). They are all ordered lookups where the first match wins, so every registry is stored as an ordered list.

Summary

Functions

Returns a specification to start this module under a supervisor.

Looks up a content type module by id.

All registered content types as {id, module} pairs, in registration order.

The fallback field handler, if one is registered.

The DOM handler for entry_name, or nil when the entry needs no special handling.

All registered field handlers, in registration order.

Returns the processors registered for the first pattern matching entry_name.

Registers a content type module under its id/0.

Registers a DOM handler for zip entries matching pattern.

Registers a merge field handler.

Registers a processor for every zip entry whose name matches pattern.

Removes a content type, either by its id or by the module itself.

Removes a field handler, returning it.

Replaces an existing field handler.

Restores the built-in registrations, discarding every customisation.

Functions

child_spec(arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

content_type(id)

@spec content_type(atom()) :: module() | nil

Looks up a content type module by id.

content_types()

@spec content_types() :: [{atom(), module()}]

All registered content types as {id, module} pairs, in registration order.

default_field_handler()

@spec default_field_handler() :: module() | nil

The fallback field handler, if one is registered.

dom_handler(entry_name)

@spec dom_handler(binary()) :: module() | nil

The DOM handler for entry_name, or nil when the entry needs no special handling.

field_handlers()

@spec field_handlers() :: [module()]

All registered field handlers, in registration order.

processors_for(entry_name)

@spec processors_for(binary()) :: [module()]

Returns the processors registered for the first pattern matching entry_name.

register_content_type(module)

@spec register_content_type(module()) :: :ok

Registers a content type module under its id/0.

register_dom_handler(pattern, module)

@spec register_dom_handler(Regex.t(), module()) :: :ok

Registers a DOM handler for zip entries matching pattern.

register_field_handler(name, handler)

@spec register_field_handler(atom(), module()) :: :ok

Registers a merge field handler.

The special name :default registers the fallback handler used when no other handler claims a field. Registering an existing name raises; use replace_field_handler/2 instead.

register_processor(pattern, module, opts \\ [])

@spec register_processor(Regex.t(), module(), keyword()) :: :ok

Registers a processor for every zip entry whose name matches pattern.

Multiple processors can share a pattern; pass replace_all: true to drop the ones already registered for it.

remove_content_type(id_or_module)

@spec remove_content_type(atom() | module()) :: :ok

Removes a content type, either by its id or by the module itself.

remove_field_handler(name)

@spec remove_field_handler(atom()) :: module() | nil

Removes a field handler, returning it.

replace_field_handler(name, handler)

@spec replace_field_handler(atom(), module()) :: :ok

Replaces an existing field handler.

reset()

@spec reset() :: :ok

Restores the built-in registrations, discarding every customisation.