IgniterCss.Parsers.Formatter (igniter_css v1.0.0)

Copy Markdown View Source

CSS formatting.

If igniter_js is present in the running application, its Biome-backed CSS formatter is used, since that is a full formatter with style options. Otherwise this falls back to IgniterCss.Transform.beautify/2, a simpler pretty-printer that keeps every comment and needs no extra dependency.

The choice is made at run time, so adding igniter_js to your project is enough — igniter_css does not need recompiling, and it does not declare igniter_js as a dependency (which would pin your rustler version).

Formatting rewrites the whole file. It is never used by the codemods in IgniterCss — see the note in IgniterCss.Transform.

Summary

Functions

format(file_path_or_content, type \\ :content)

@spec format(String.t(), :content | :path) ::
  {:ok, atom(), String.t()} | {:error, atom(), String.t()}

Format a stylesheet.

Examples

iex> {:ok, _, css} = IgniterCss.Parsers.Formatter.format(".a{color:red}")
iex> css
".a {\n  color: red;\n}\n"

is_formatted(file_path_or_content, type \\ :content)

@spec is_formatted(String.t(), :content | :path) ::
  {:ok, atom(), boolean()} | {:error, atom(), boolean() | String.t()}

Is this stylesheet already formatted?

Examples

iex> IgniterCss.Parsers.Formatter.is_formatted(".a {\n  color: red;\n}\n")
{:ok, :is_formatted, true}