Twm.Config (Twm v0.1.0)

View Source

Configuration management for Twm.

This module provides functions for getting and extending the configuration for the Twm library.

Summary

Types

t()

Configuration for the Twm library.

Functions

Extends the default configuration with custom options.

Returns the default configuration for Twm.

Validates a configuration keyword list.

Types

t()

@type t() :: %Twm.Config{
  cache_name: String.t() | atom() | nil,
  cache_size: non_neg_integer(),
  class_groups: keyword(),
  conflicting_class_group_modifiers: term(),
  conflicting_class_groups: keyword(),
  experimental_parse_class_name: (keyword() -> Twm.Types.parsed_class_name()),
  order_sensitive_modifiers: term(),
  prefix: String.t() | nil,
  theme: keyword()
}

Configuration for the Twm library.

  • :cache_name - Name of the LRU cache (if enabled)
  • :prefix - Optional prefix for Tailwind classes
  • :theme - Theme configuration
  • :class_groups - Class group definitions
  • :conflicting_class_groups - Groups of class names that conflict with each other
  • :cache_size - Size of the LRU cache (if enabled)
  • :experimental_parse_class_name - Optional experimental class name parser function

Functions

extend(options \\ [])

@spec extend(keyword()) :: t()

Extends the default configuration with custom options.

Options

  • :cache_size - The size of the LRU cache
  • :prefix - The prefix for Tailwind classes
  • :override - Configuration values to override (takes precedence over default values)
  • :extend - Configuration values to extend (merges with default values)

Examples

iex> config = Twm.Config.extend(cache_size: 1000)
iex> config[:cache_size]
1000

iex> config = Twm.Config.extend(override: [class_groups: [display: ["custom-display"]]])
iex> config[:class_groups][:display]
["custom-display"]

iex> config = Twm.Config.extend(extend: [class_groups: [custom_group: ["custom-class"]]])
iex> config[:class_groups][:custom_group]
["custom-class"]

extend(config, extend_fn)

@spec extend(t(), fun()) :: t()

get_default()

@spec get_default() :: t()

Returns the default configuration for Twm.

Examples

iex> config = Twm.Config.get_default()
iex> config[:cache_size]
500

new(config)

@spec new(keyword()) :: t()

validate(config)

@spec validate(keyword()) :: {:ok, keyword()} | {:error, String.t()}

Validates a configuration keyword list.

Checks if all required keys are present and the values have the correct types.

Examples

iex> Twm.Config.validate(Twm.Config.get_default())
{:ok, [...]}

iex> Twm.Config.validate([])
{:error, "Missing required configuration keys: cache_size, theme, class_groups, conflicting_class_groups"}