# Plato
A declarative CMS for Elixir. Define your content schemas with a DSL and get an automatically generated web UI with zero configuration.
## Features
- 🎨 **Declarative Schema Definition** - Define content types with a simple DSL
- 🚀 **Zero Configuration** - Automatic database migrations and UI generation
- 📦 **Self-Contained** - Brings its own styled web interface
- 🔌 **Mountable** - Works at any path in your Phoenix application
- 💾 **SQLite by Default** - No database setup required
## Installation
Add `plato` to your list of dependencies in `mix.exs`:
```elixir
def deps do
[
{:plato, "~> 0.1.0"}
]
end
```
## Quick Start
### 1. Define Your Schemas
Create a module to define your content schemas:
```elixir
defmodule MyApp.Content do
use Plato.DSL
schema "Homepage" do
field :title, :text, required: true
field :subtitle, :text
field :show_newsletter, :boolean
end
schema "BlogPost" do
field :title, :text, required: true
field :author, :text, required: true
field :body, :text, required: true
field :published, :boolean
end
end
```
### 2. Mount the CMS in Your Router
```elixir
defmodule MyAppWeb.Router do
use Phoenix.Router
# Your existing routes...
scope "/" do
pipe_through :browser
get "/", MyAppWeb.PageController, :index
end
# Mount Plato CMS at /cms
scope "/cms" do
pipe_through :browser
forward "/", Plato.Web.Router
end
end
```
### 3. Configure Static Assets
Add Plato's static assets to your endpoint:
```elixir
defmodule MyAppWeb.Endpoint do
use Phoenix.Endpoint, otp_app: :my_app
# Serve static files from Plato
plug Plug.Static,
at: "/assets",
from: {:plato, "priv/static/assets"},
gzip: false
# ... rest of your endpoint config
end
```
### 4. Set Up Asset Compilation (Optional)
If you want to customize Plato's styles, add the watchers to your config:
```elixir
# config/dev.exs
config :my_app, MyAppWeb.Endpoint,
watchers: [
tailwind: {Tailwind, :install_and_run, [:plato, ~w(--watch)]}
]
```
That's it! Start your server and visit `/cms` to see your CMS in action.
## Configuration
### Database
By default, Plato uses SQLite. You can configure the database path:
```elixir
# config/config.exs
config :plato, Plato.Repo,
database: "path/to/plato.db",
pool_size: 5
```
Or use an environment variable:
```bash
export PLATO_DATABASE_PATH=/var/db/plato.db
```
### Field Types
Plato supports the following field types:
- `:text` - Text content (strings)
- `:number` - Numeric values (integers or floats)
- `:boolean` - True/false values
## API Usage
### Creating Content
```elixir
{:ok, homepage} = Plato.Content.create("Homepage", %{
title: "Welcome",
subtitle: "To my site",
show_newsletter: true
})
```
### Listing Content
```elixir
entries = Plato.Content.list("Homepage")
```
### Getting Content by ID
```elixir
{:ok, homepage} = Plato.Content.get("Homepage", 1)
```
### Counting Entries
```elixir
count = Plato.Content.count("Homepage")
```
## Development
### Running Tests
```bash
cd apps/plato
mix test
```
### Building Documentation
```bash
mix docs
```
## License
MIT License - see LICENSE file for details.