PhoenixKitDocumentCreator.Variable (PhoenixKitDocumentCreator v0.3.0)

Copy Markdown View Source

Variable definitions for document templates.

Variables are {{ variable_name }} placeholders in Google Docs templates that get substituted with actual values via the Google Docs replaceAllText API.

Summary

Functions

Builds Variable structs from a forked detection map. Text variables come first (sorted), then image variables (sorted by name).

Extracts image variable definitions from {{ image: name }} / {{ images: name }} placeholders.

Extracts text variable names from {{ name }} placeholders.

Convenience entry point that runs both detectors and returns a forked map.

Guesses the variable type from its name.

Converts an underscore_name to a human-readable label.

Types

t()

@type t() :: %PhoenixKitDocumentCreator.Variable{
  config: map(),
  default: String.t() | nil,
  label: String.t(),
  name: String.t(),
  required: boolean(),
  type: variable_type()
}

variable_type()

@type variable_type() :: :text | :date | :currency | :multiline | :image | :image_list

Functions

build_definitions(map)

@spec build_definitions(%{
  text: [String.t()],
  image: [%{name: String.t(), kind: :image | :image_list}]
}) ::
  [t()]

Builds Variable structs from a forked detection map. Text variables come first (sorted), then image variables (sorted by name).

extract_image_variables(text)

@spec extract_image_variables(term()) :: [
  %{name: String.t(), kind: :image | :image_list}
]

Extracts image variable definitions from {{ image: name }} / {{ images: name }} placeholders.

Returns a list of %{name: String.t(), kind: :image | :image_list} maps, deduplicated by name, sorted by name.

Note: if both {{ image: foo }} and {{ images: foo }} appear with the same name, the first occurrence (by document order) wins.

extract_string_variables(text)

@spec extract_string_variables(term()) :: [String.t()]

Extracts text variable names from {{ name }} placeholders.

Deliberately ignores {{ image: name }} and {{ images: name }} via a negative lookahead — those are handled by extract_image_variables/1.

Returns a sorted list of unique names.

extract_variables(text)

@spec extract_variables(term()) :: %{
  text: [String.t()],
  image: [%{name: String.t(), kind: :image | :image_list}]
}

Convenience entry point that runs both detectors and returns a forked map.

Returns %{text: [String.t()], image: [%{name, kind}]}.

guess_type(name)

@spec guess_type(String.t()) :: variable_type()

Guesses the variable type from its name.

humanize(name)

@spec humanize(String.t()) :: String.t()

Converts an underscore_name to a human-readable label.