IgniterCss.Codemods (igniter_css v1.0.0)

Copy Markdown View Source

Igniter-facing wrappers: they take and return an Igniter struct, so callers get Igniter's normal diff preview and confirmation flow for free.

Available only when igniter is a dependency. Without it, every function here returns {:error, :igniter_not_available}; use IgniterCss directly instead.

Comment ownership on delete

When a codemod removes a declaration or a rule, these comments go with it:

  • a comment trailing on the same line;
  • a comment on its own line directly above, with no blank line between.

These are kept:

  • a comment separated from the target by a blank line;
  • a comment that reads as a section header — one spanning several lines, or containing a rule of three or more repeated = - * # ~ _ characters, e.g. /* ===== Layout ===== */.

Example

def install(igniter, _opts) do
  igniter
  |> IgniterCss.Codemods.ensure_at_rule("assets/css/app.css", ~s|@plugin "daisyui";|)
  |> IgniterCss.Codemods.ensure_rule("assets/css/app.css", ".hide-scrollbar")
  |> IgniterCss.Codemods.set_declaration(
    "assets/css/app.css", ".hide-scrollbar", "scrollbar-width", "none"
  )
end

Each step is idempotent, so re-running the installer produces no diff.

Summary

Functions

add_import(igniter, path, url, media \\ nil, opts \\ [])

See IgniterCss.add_import/4.

add_vendor_prefixes(igniter, path, property, prefixes, opts \\ [])

See IgniterCss.add_vendor_prefixes/4.

append_raw_to_rule(igniter, path, selector, raw, opts \\ [])

See IgniterCss.append_raw_to_rule/4.

ensure_at_rule(igniter, path, line, opts \\ [])

See IgniterCss.ensure_at_rule/3.

ensure_at_rule_block(igniter, path, name, matching \\ nil, declarations, opts \\ [])

See IgniterCss.ensure_at_rule_block/5.

ensure_rule(igniter, path, selector, declarations \\ "", opts \\ [])

See IgniterCss.ensure_rule/4.

remove_at_rule(igniter, path, name, matching \\ nil, opts \\ [])

See IgniterCss.remove_at_rule/4.

remove_declaration(igniter, path, selector, property, opts \\ [])

See IgniterCss.remove_declaration/4.

remove_import(igniter, path, url, opts \\ [])

See IgniterCss.remove_import/3.

remove_rule(igniter, path, selector, opts \\ [])

See IgniterCss.remove_rule/3.

set_declaration(igniter, path, selector, property, value, opts \\ [])

See IgniterCss.set_declaration/5.