Twm.Parser.ClassName (Twm v0.1.0)

View Source

Provides functionality for parsing Tailwind CSS class names into their components.

This module is responsible for breaking down class names into their modifiers, base class name, and handling special cases like the important modifier.

Summary

Functions

Creates a context for parsing class names based on the provided configuration.

Parse a class name into its constituent parts.

Parses a class name using the provided context.

Removes the important modifier from a class name.

Functions

create_parse_class_name(config)

@spec create_parse_class_name(Twm.Config.t()) :: Twm.Context.ClassParsingContext.t()

Creates a context for parsing class names based on the provided configuration.

Parameters

  • config - A keyword list containing configuration options like prefix and experimental parser

Returns

  • A Context struct containing the parsing configuration

do_parse_class_name(class_name)

@spec do_parse_class_name(String.t()) :: Twm.Types.parsed_class_name()

Parse a class name into its constituent parts.

Inspired by splitAtTopLevelOnly used in Tailwind CSS. See: https://github.com/tailwindlabs/tailwindcss/blob/v3.2.2/src/util/splitAtTopLevelOnly.js

Parameters

  • class_name - The class name string to parse

Returns

  • A map containing the parsed components of the class name

parse_class_name(class_name, context)

Parses a class name using the provided context.

Parameters

  • class_name - The class name string to parse
  • context - The Context struct containing parsing configuration

Returns

  • A map containing the parsed components of the class name

strip_important_modifier(base_class_name)

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

Removes the important modifier from a class name.

In Tailwind CSS, the important modifier can be at the end of the class name, or at the beginning in v3.

Parameters

  • base_class_name - The class name to process

Returns

  • The class name without the important modifier