PhoenixKitDocumentCreator.Variable (PhoenixKitDocumentCreator v0.2.8)

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 list of variable names, guessing types from names.

Extracts variable names from text by scanning for {{ variable_name }} patterns.

Guesses the variable type from its name.

Converts an underscore_name to a human-readable label.

Types

t()

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

variable_type()

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

Functions

build_definitions(names)

@spec build_definitions([String.t()]) :: [t()]

Builds Variable structs from a list of variable names, guessing types from names.

extract_variables(text)

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

Extracts variable names from text by scanning for {{ variable_name }} patterns.

Returns a sorted list of unique variable names (strings).

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.