AshReports.Layout.IR (ash_reports v0.1.0)

Intermediate Representation (IR) for layout containers.

This module defines the core IR type structures that represent layout containers (Grid, Table, Stack) in a normalized format suitable for all renderers. The IR handles cell positioning calculations, spanning logic, and provides a consistent data structure for Typst, HTML, and JSON output.

Usage

# Create a grid IR
grid_ir = %AshReports.Layout.IR{
  type: :grid,
  properties: %{columns: ["1fr", "2fr"], rows: ["auto"]},
  children: [cell_ir1, cell_ir2],
  lines: []
}

Types

The IR supports three layout types:

  • :grid - CSS Grid-like layout with explicit columns/rows
  • :table - Table with headers/footers
  • :stack - Flexbox-like stack layout

Summary

Functions

Adds a child to the layout IR.

Adds a footer to the layout IR (for tables).

Adds a header to the layout IR (for tables).

Adds a line to the layout IR.

Gets a property from the layout IR.

Creates a grid IR with the given properties.

Creates a new LayoutIR struct with the given type and options.

Sets a property on the layout IR.

Creates a stack IR with the given properties.

Creates a table IR with the given properties.

Types

child()

layout_type()

@type layout_type() :: :grid | :table | :stack

t()

@type t() :: %AshReports.Layout.IR{
  children: [child()],
  footers: [AshReports.Layout.IR.Footer.t()],
  headers: [AshReports.Layout.IR.Header.t()],
  lines: [AshReports.Layout.IR.Line.t()],
  properties: map(),
  type: layout_type()
}

Functions

add_child(ir, child)

@spec add_child(t(), child()) :: t()

Adds a child to the layout IR.

add_footer(ir, footer)

@spec add_footer(t(), AshReports.Layout.IR.Footer.t()) :: t()

Adds a footer to the layout IR (for tables).

add_header(ir, header)

@spec add_header(t(), AshReports.Layout.IR.Header.t()) :: t()

Adds a header to the layout IR (for tables).

add_line(ir, line)

@spec add_line(t(), AshReports.Layout.IR.Line.t()) :: t()

Adds a line to the layout IR.

get_property(ir, key, default \\ nil)

@spec get_property(t(), atom(), any()) :: any()

Gets a property from the layout IR.

grid(opts \\ [])

@spec grid(Keyword.t()) :: t()

Creates a grid IR with the given properties.

new(type, opts \\ [])

@spec new(layout_type(), Keyword.t()) :: t()

Creates a new LayoutIR struct with the given type and options.

Options

  • :properties - Map of normalized property values
  • :children - List of CellIR, RowIR, or ContentIR
  • :lines - List of LineIR for hline/vline
  • :headers - List of HeaderIR (for tables)
  • :footers - List of FooterIR (for tables)

Examples

iex> AshReports.Layout.IR.new(:grid, properties: %{columns: ["1fr", "1fr"]})
%AshReports.Layout.IR{type: :grid, properties: %{columns: ["1fr", "1fr"]}, ...}

put_property(ir, key, value)

@spec put_property(t(), atom(), any()) :: t()

Sets a property on the layout IR.

stack(opts \\ [])

@spec stack(Keyword.t()) :: t()

Creates a stack IR with the given properties.

table(opts \\ [])

@spec table(Keyword.t()) :: t()

Creates a table IR with the given properties.