Routex.Utils (Routex v1.3.0-rc.1)

View Source

Provides an interface to functions which can be used in extensions.

Summary

Functions

Prints an alert. Should be used when printing critical alerts in the terminal during compile time.

Returns the module to use for LiveView assignments

Backward compatible version of Code.ensure_compiled!/1

Test env aware variant of Module.get_attribute. Delegates to Module.get_attribute/3 in non-test environments. In test environment it returns the result of Module.get_attribute/3 or an empty list when the module is already compiled.

Returns the branch leaf from assigns.

Returns the AST to get the current branch leaf from process dict or from assigns, conn or socket based on the available variables in the caller module.

Prints an indented text. Should be used when printing messages in the terminal during compile time.

Helps setting the branch in the process dictionary.

Functions

alert(title \\ "Critical", input)

Prints an alert. Should be used when printing critical alerts in the terminal during compile time.

assign_module()

@spec assign_module() :: module()

Returns the module to use for LiveView assignments

ensure_compiled!(mod)

@spec ensure_compiled!(module()) :: module()

Backward compatible version of Code.ensure_compiled!/1

get_attribute(module, key, default \\ nil)

Test env aware variant of Module.get_attribute. Delegates to Module.get_attribute/3 in non-test environments. In test environment it returns the result of Module.get_attribute/3 or an empty list when the module is already compiled.

get_branch_leaf(branch)

@spec get_branch_leaf(
  Routex.Types.route()
  | map()
  | Plug.Conn.t()
  | Phoenix.Socket.t()
  | [integer(), ...]
) :: integer()

get_branch_leaf_from_assigns(assigns, helper_mod, call_mod)

@spec get_branch_leaf_from_assigns(map(), module(), module()) :: integer()

Returns the branch leaf from assigns.

get_helper_ast(caller)

@spec get_helper_ast(caller :: Routex.Types.env()) :: Routex.Types.ast()

Returns the AST to get the current branch leaf from process dict or from assigns, conn or socket based on the available variables in the caller module.

print(module \\ nil, input)

@spec print(module(), input :: iodata()) :: :ok

Prints an indented text. Should be used when printing messages in the terminal during compile time.

process_put_branch(branch)

@spec process_put_branch(branch :: [integer(), ...]) :: integer()
@spec process_put_branch(branch :: integer()) :: integer()

Helps setting the branch in the process dictionary.

Example: As dispatch target

dispatch_targets: [{Routex.Utils, :process_put_branch, [[:attrs, :__branch__]]}]