sobolevn / Ecto_autoslug_field
Licence: mit
Automatically create slugs for Ecto schemas.
Stars: ✭ 129
Programming Languages
elixir
2628 projects
Labels
Projects that are alternatives of or similar to Ecto autoslug field
Accent
The first developer-oriented translation tool. True asynchronous flow between translators and your team.
Stars: ✭ 721 (+458.91%)
Mutual labels: ecto
Ecto morph
morph your Ecto capabilities into the s t r a t o s p h e r e !
Stars: ✭ 72 (-44.19%)
Mutual labels: ecto
Elixir Cowboy React Spa
Example application that shows how to use Cowboy 2.0 in conjunction with React and Redux to create data driven Single Page Applications
Stars: ✭ 112 (-13.18%)
Mutual labels: ecto
Esx
A client for the Elasticsearch with Ecto, written in Elixir
Stars: ✭ 25 (-80.62%)
Mutual labels: ecto
Filterable
Filtering from incoming params in Elixir/Ecto/Phoenix with easy to use DSL.
Stars: ✭ 83 (-35.66%)
Mutual labels: ecto
Elixir Boilerplate
⚗ The stable base upon which we build our Elixir projects at Mirego.
Stars: ✭ 627 (+386.05%)
Mutual labels: ecto
Kronky
Kronky bridges the gap between Ecto and Absinthe GraphQL by listing validation messages in a mutation payload.
Stars: ✭ 112 (-13.18%)
Mutual labels: ecto
Disco
Simple, opinionated yet flexible library to build CQRS/ES driven systems 🕺
Stars: ✭ 31 (-75.97%)
Mutual labels: ecto
Ecto materialized path
Tree structure & hierarchy for ecto models
Stars: ✭ 45 (-65.12%)
Mutual labels: ecto
Query
Query adds tools to aid the use of Ecto in web settings.
Stars: ✭ 23 (-82.17%)
Mutual labels: ecto
Nebulex
In-memory and distributed caching toolkit for Elixir.
Stars: ✭ 662 (+413.18%)
Mutual labels: ecto
Phoenix live dashboard
Realtime dashboard with metrics, request logging, plus storage, OS and VM insights
Stars: ✭ 1,657 (+1184.5%)
Mutual labels: ecto
EctoAutoslugField
ecto_autoslug_field
is a reusable Ecto
library which can automatically create slugs from other fields. We use slugger
as a default slug-engine.
We only depend on the ecto
package (we do not deal with ecto_sql
at all).
We support ecto >= 2.1 and ecto < 4
!
See this blog post for more information.
Installation
def deps do
[
{:ecto_autoslug_field, "~> 2.0"}
]
end
Options
There are several options to configure.
Required:
-
:to
- represents the slug field name where to save value to
Optional:
-
:from
- represents the source fields from which to build slug, if this option is not set you have to overrideget_sources/2
function -
:always_change
- if this option is set slug will be recreated from the given sources each timemaybe_generate_slug
function is called
Functions
-
get_sources/2
- this function is used to get sources for the slug, docs. -
build_slug/2
- this function is a place to modify the result slug, docs.
Examples
The simplest example:
defmodule EctoSlugs.Blog.Article.TitleSlug do
use EctoAutoslugField.Slug, from: :title, to: :slug
end
defmodule EctoSlugs.Blog.Article do
use Ecto.Schema
import Ecto.Changeset
alias EctoSlugs.Blog.Article
alias EctoSlugs.Blog.Article.TitleSlug
schema "blog_articles" do
field :breaking, :boolean, default: false
field :content, :string
field :title, :string
field :slug, TitleSlug.Type
timestamps()
end
def changeset(%Article{} = article, attrs) do
article
|> cast(attrs, [:title, :content, :breaking])
|> validate_required([:title, :content])
|> unique_constraint(:title)
|> TitleSlug.maybe_generate_slug
|> TitleSlug.unique_constraint
end
end
See this tutorial for some more examples.
Changelog
See CHANGELOG.md.
License
MIT. Please see LICENSE for licensing details.
Note that the project description data, including the texts, logos, images, and/or trademarks,
for each open source project belongs to its rightful owner.
If you wish to add or remove any projects, please contact us at [email protected].