Framework.AppSpec (Framework v0.5.0)

View Source

AppSpec DSL for defining verified routes and message security.

Provides the single UI contract: pages, routes, parameter schemas, visibility predicates, and compiled artifacts that enforce type-safe navigation and authorization as pure predicates.

Example Usage

defmodule MyApp.AppSpec do
  use Framework.AppSpec

  page :dashboard do
    path "/dashboard"
    title "Dashboard"

    params do
      # none
    end

    visible_if ctx do
      ctx.authenticated? and :member in ctx.roles
    end

    render with: MyApp.Pages.Dashboard
    menu group: :main, icon: :home, order: 10
  end
end

Summary

Functions

Defines breadcrumb path.

Creates unified path builder with query parameter support. Consolidates all path building logic to eliminate duplication.

Runtime path builder - unified implementation for all path construction.

Creates runtime path function using unified logic.

Evaluates AST values like sigil_w to actual values.

Extracts data from page AST block.

Extracts parameter schema from params block AST.

Extracts parameter segment names from path pattern.

Generates breadcrumbs index mapping pages to their breadcrumb paths.

Generates menus index grouped by menu group and sorted by order.

Generates route helper functions.

Gets the base URL from configuration.

Defines menu metadata.

Defines optional parameters.

Defines a page with path, parameters, visibility, and metadata.

Access parameter values in visible_if predicates.

Defines parameters for a page route.

Defines the path for a page.

Processes a page definition AST to extract path, parameters, and metadata.

Defines render delegate.

Defines parameter requirements.

Defines the title for a page.

Validates parameters for a page using its parameter schema.

Validates a single parameter value according to its type and requirements.

Defines visibility predicate for a page (pure function).

Functions

build_unified_path_ast(path)

Creates unified path builder with query parameter support. Consolidates all path building logic to eliminate duplication.

build_unified_path_runtime(path, segments, params)

Runtime path builder - unified implementation for all path construction.

create_path_function(path)

Creates runtime path function using unified logic.

evaluate_values_ast(values)

Evaluates AST values like sigil_w to actual values.

extract_page_data(single_clause)

Extracts data from page AST block.

extract_param_schema(single_clause)

Extracts parameter schema from params block AST.

extract_path_segments(path_pattern)

Extracts parameter segment names from path pattern.

generate_breadcrumbs_index(page_processors)

Generates breadcrumbs index mapping pages to their breadcrumb paths.

Returns a map of %{page_name => [breadcrumb_pages]}

generate_menus_index(page_processors)

Generates menus index grouped by menu group and sorted by order.

Returns a map of %{group => [%{name, title, path, icon, order}]}

generate_route_helpers(page_processors)

Generates route helper functions.

get_base_url()

Gets the base URL from configuration.

optional(name, type, opts \\ [])

(macro)

Defines optional parameters.

page(name, list)

(macro)

Defines a page with path, parameters, visibility, and metadata.

param(name)

(macro)

Access parameter values in visible_if predicates.

This function is available within visible_if blocks to access typed parameters for authorization decisions.

params(list)

(macro)

Defines parameters for a page route.

path(path_string)

(macro)

Defines the path for a page.

process_page_definition(name, page_ast)

Processes a page definition AST to extract path, parameters, and metadata.

render(opts)

(macro)

Defines render delegate.

required(name, type, opts \\ [])

(macro)

Defines parameter requirements.

title(title_string)

(macro)

Defines the title for a page.

validate_page_params(param_schema, raw_params)

Validates parameters for a page using its parameter schema.

validate_page_params(param_schema, raw_params, page_name)

validate_param_value(raw_value, type, required, opts)

Validates a single parameter value according to its type and requirements.

visible_if(ctx_var, list)

(macro)

Defines visibility predicate for a page (pure function).