Aurora.Uix.Layout.Helpers (Aurora UIX v0.1.4-rc.1)

Copy Markdown

Helper utilities for Aurora.Uix UI DSL transformations.

Serves as the core processing engine for DSL block transformations, component registration, and field metadata extraction. Handles the conversion of macro-based UI definitions into standardized component structures suitable for template generation.

Key Features

  • DSL block extraction and normalization
  • Component registration and tree path creation
  • Field parser resolution for different connectors
  • Module attribute management for layouts

Key Constraints

  • Requires valid fields parser module configuration
  • Module attributes must exist before storage operations
  • Field specifications must be atoms or keyword tuples

Summary

Functions

Creates a macro expression to store layout tree paths in the module attributes.

Creates a macro expression to store layout options in the module attributes.

Extracts the :do block from options while preserving the rest.

Generates a unique resource identifier for embedded fields.

Resolves fields parser implementation module based on connector type.

Normalizes quoted blocks into a list of quoted expressions.

Stores manually configured layout options in the module attributes.

Stores manually configured layout tree paths in the module attributes.

Transforms DSL macro calls into standardized component entries.

Functions

create_layout(block, env)

@spec create_layout(term(), Macro.Env.t()) :: Macro.t()

Creates a macro expression to store layout tree paths in the module attributes.

Parameters

  • block (term()) - The block containing layout definitions.
  • env (Macro.Env.t()) - The macro environment.

Returns

Macro.t() - A quoted expression that, when executed, stores the tree paths.

create_layout_opts(opts)

@spec create_layout_opts(keyword()) :: Macro.t()

Creates a macro expression to store layout options in the module attributes.

Parameters

  • opts (keyword()) - The layout options to be stored.

Returns

Macro.t() - A quoted expression that, when executed, stores the options.

extract_block_options(opts, block \\ nil)

@spec extract_block_options(keyword() | list(), term()) :: {term(), keyword()}

Extracts the :do block from options while preserving the rest.

Handles multiple input patterns for block extraction, supporting both keyword lists with a :do key and explicit block parameters.

Parameters

  • opts (keyword() | list()) - An options list that may contain a :do key.

  • block (term()) - An optional explicit block value, which defaults to nil.

Returns

{term(), keyword()} - A tuple containing the extracted block and the remaining options.

field_embedded_resource(parent_resource_name, field)

@spec field_embedded_resource(atom(), map() | atom()) :: atom()

Generates a unique resource identifier for embedded fields.

Parameters

  • parent_resource_name (atom()) - The name of the parent resource.
  • field (map() | atom()) - The embedded field %Ecto.Embedded{} or the field name.

Returns

atom() - A unique identifier for the embedded resource.

get_fields_parser_module(type)

@spec get_fields_parser_module(atom()) :: module()

Resolves fields parser implementation module based on connector type.

Uses compile-time configuration map to look up the appropriate module. The type must match a key in @crud_integration_modules or an error is raised.

Parameters

  • type (atom()) - The connector type (:ash or :ctx).

Returns

module() - The fields parser implementation module.

Raises

RuntimeError - If type is nil or not found in configuration.

prepare_block(block)

@spec prepare_block(Macro.t()) :: [Macro.t()]

Normalizes quoted blocks into a list of quoted expressions.

Handles both single expressions and block expressions ({:__block__, _, _}), ensuring a consistent output format for template generation.

Parameters

  • block (Macro.t()) - The input block to be normalized.

Returns

list(Macro.t()) - A list of normalized quoted expressions.

put_manual_opts(module, define_by_module_opts, ui_defined)

@spec put_manual_opts(module(), list(), list()) :: :ok

Stores manually configured layout options in the module attributes.

Merges options defined via auix_create_ui/2 with any existing options and stores them in the @auix_layout_opts attribute.

Parameters

  • module (module()) - The module where the attributes are stored.
  • define_by_module_opts (list()) - The list of options already defined in the module.
  • ui_defined (list()) - The list of new options to be added.

Returns

:ok - Indicates that the options have been stored.

put_manual_tree_paths(module, defined_by_module_attribute, ui_defined)

@spec put_manual_tree_paths(module(), list(), list()) :: :ok

Stores manually configured layout tree paths in the module attributes.

Merges new layout tree paths with existing ones and stores them in the @auix_layout_trees attribute, avoiding duplicates.

Parameters

  • module (module()) - The module where the attributes are stored.
  • defined_by_module_attribute (list()) - The list of tree paths already defined.
  • ui_defined (list()) - The list of new tree paths to be added.

Returns

:ok - Indicates that the tree paths have been stored.

register_dsl_entry(tag, name, config, opts, do_block, env)

@spec register_dsl_entry(
  atom(),
  atom(),
  keyword() | tuple() | nil,
  keyword(),
  Macro.t(),
  Macro.Env.t()
) :: Macro.t()

Transforms DSL macro calls into standardized component entries.

Creates a component map with all necessary information for rendering, including tag type, configuration, options, and nested elements.

Parameters

  • tag (atom()) - The component type identifier (e.g., :form, :field).
  • name (atom()) - The component name for identification.
  • config (keyword() | tuple() | nil) - Static configuration or field definitions.

  • opts (keyword()) - Component options and attributes.
  • do_block (Macro.t()) - Nested component definitions and content.
  • env (Macro.Env.t()) - The macro environment for code generation.

Returns

Macro.t() - A quoted expression that evaluates to a component map.