MishkaChelekom.SimpleCSSUtilities (Mishka Chelekom v0.0.8)

View Source

Pure Elixir CSS parser for handling imports and CSS manipulation. Supports Tailwind CSS 4.x directives and import management.

Summary

Functions

Adds a CSS import to the content if it doesn't already exist.

Adds import and theme to CSS content. Returns the updated CSS content with the import statement and theme.

Ensures theme content exists in the CSS. If @theme already exists, it replaces it. Otherwise, appends it.

Checks if a specific import already exists in the CSS content. Handles various import formats including Tailwind 4 syntax.

Inserts an import statement at the appropriate location in CSS content. Respects Tailwind 4 directive ordering.

Reads theme content from a file path. Returns {:ok, content} or {:error, reason}.

Validates CSS content for proper Tailwind 4 structure.

Functions

add_import(css_content, import_path, url_wrap \\ false)

Adds a CSS import to the content if it doesn't already exist.

Examples

iex> MishkaChelekom.SimpleCSSUtilities.add_import("@import \"tailwindcss\";", "../vendor/mishka.css")
{:ok, :added, "@import \"tailwindcss\";\n@import \"../vendor/mishka.css\";\n"}

iex> content = "@import \"../vendor/mishka.css\";"
iex> MishkaChelekom.SimpleCSSUtilities.add_import(content, "../vendor/mishka.css")
{:ok, :exists, "@import \"../vendor/mishka.css\";"}

add_import_and_theme(css_content, import_path, theme_content)

Adds import and theme to CSS content. Returns the updated CSS content with the import statement and theme.

Examples

iex> css_content = "@import 'tailwindcss';"
iex> theme_content = "@theme { --color-primary: blue; }"
iex> {:ok, updated} = MishkaChelekom.SimpleCSSUtilities.add_import_and_theme(css_content, "../vendor/mishka.css", theme_content)
{:ok, "@import 'tailwindcss';

@import "../vendor/mishka.css";

@theme { --color-primary: blue; } "}

ensure_theme_exists(css_content, theme_content)

Ensures theme content exists in the CSS. If @theme already exists, it replaces it. Otherwise, appends it.

Examples

iex> css_content = "@import 'tailwindcss';"
iex> theme_content = "@theme { --color-primary: blue; }"
iex> MishkaChelekom.SimpleCSSUtilities.ensure_theme_exists(css_content, theme_content)
"@import 'tailwindcss';

@theme { --color-primary: blue; } "

import_already_exists?(css_content, import_path)

Checks if a specific import already exists in the CSS content. Handles various import formats including Tailwind 4 syntax.

insert_import(css_content, import_path)

Inserts an import statement at the appropriate location in CSS content. Respects Tailwind 4 directive ordering.

read_theme_content(theme_path)

Reads theme content from a file path. Returns {:ok, content} or {:error, reason}.

Examples

iex> MishkaChelekom.SimpleCSSUtilities.read_theme_content("path/to/theme.css")
{:ok, "@theme { --color-primary: blue; }"}

validate_tailwind_structure(css_content)

Validates CSS content for proper Tailwind 4 structure.