Aurora.Uix.Template behaviour (Aurora UIX v0.1.0)

Defines the behaviour for Aurora.Uix template modules.

A template module is responsible for generating the UI components and handler code for a resource. Any module that acts as a template must adopt this behaviour.

Key Features

  • Code Generation: Dynamically generates handler code for different layouts.
  • Customizable Components: Allows for specifying a default core components module.

Key Constraints

  • Any module acting as a template must adopt this behaviour.

The configured template module can be retrieved using uix_template/0.

Summary

Callbacks

Returns the default core components module.

Generates the handling code for the given layout type.

Returns the list of layout tags supported by the template.

Functions

Validates and returns the configured UIX template module.

Callbacks

default_core_components_module()

@callback default_core_components_module() :: module()

Returns the default core components module.

Returns

  • module() - The module containing core UI components.

default_theme_name()

@callback default_theme_name() :: atom()

generate_module(parsed_opts)

@callback generate_module(parsed_opts :: map()) :: Macro.t()

Generates the handling code for the given layout type.

Parameters

  • parsed_opts (map()) - Customization options for code generation.

Returns

  • Macro.t() - The generated module code.

layout_tags()

@callback layout_tags() :: [atom()]

Returns the list of layout tags supported by the template.

Returns

  • list(atom()) - A list of atoms representing the supported layout tags.

Functions

uix_template()

@spec uix_template() :: module()

Validates and returns the configured UIX template module.

This function retrieves the template module from the application environment, validates it against the Aurora.Uix.Template behaviour, and returns it.

Returns

  • module() - The validated template module.

Examples

# Assuming the default template is configured
Aurora.Uix.Template.uix_template()
# => Aurora.Uix.Templates.Basic

If a module that does not implement the behaviour is configured, it will raise an error.

# Assuming `MyInvalidTemplate` does not implement the behaviour
Application.put_env(:aurora_uix, :template, MyInvalidTemplate)
# Aurora.Uix.Template.uix_template()
# ** (ArgumentError) MyInvalidTemplate must adopt the Aurora.Uix.Template behaviour.