PostCSS for Elixir

Hex.pmDocumentation

An Elixir implementation of the popular PostCSS library, providing CSS parsing, AST manipulation, and stringification capabilities.

Features

Installation

Add postcss to your list of dependencies in mix.exs:

def deps do
  [
    {:postcss, "~> 0.1.3"}
  ]
end

Usage

Basic Parsing and Stringification

# Parse CSS string
css = """
.foo {
  color: red;
  margin: 10px;
}
"""

root = PostCSS.parse(css)

# Convert back to string
PostCSS.stringify(root)

Creating Nodes Programmatically

# Create a declaration
decl = PostCSS.decl("color", "blue")

# Create a rule with declarations
rule = PostCSS.rule(".my-class", [decl])

# Create a root with rules
root = PostCSS.root([rule])

# Generate CSS
PostCSS.stringify(root)
# => ".my-class {\n  color: blue;\n}"

Working with At-Rules

# Create an at-rule
media = PostCSS.at_rule("media", "screen and (max-width: 600px)", [
  PostCSS.rule(".responsive", [
    PostCSS.decl("display", "none")
  ])
])

root = PostCSS.root([media])
PostCSS.stringify(root)

Adding Comments

comment = PostCSS.comment("This is a comment")
rule = PostCSS.rule(".foo", [comment, PostCSS.decl("color", "red")])

API Documentation

The main API consists of:

Node Types

The library supports all major CSS node types:

Development

# Install dependencies
mix deps.get

# Run tests
mix test

# Generate documentation
mix docs

# Check formatting
mix format --check-formatted

Contributing

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -am 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

License

This project is licensed under the Apache 2.0 License - see the LICENSE file for details.

Acknowledgments