Twm.Parser.ClassName (Twm v0.1.0)
View SourceProvides 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
@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
@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
@spec parse_class_name(String.t(), Twm.Context.ClassParsingContext.t()) :: Twm.Types.parsed_class_name()
Parses a class name using the provided context.
Parameters
class_name
- The class name string to parsecontext
- The Context struct containing parsing configuration
Returns
- A map containing the parsed components of the class name
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