All Projects → wemake-services → ecto_autoslug_field

wemake-services / ecto_autoslug_field

Licence: MIT License
Automatically create slugs for Ecto schemas.

Programming Languages

elixir
2628 projects

Projects that are alternatives of or similar to ecto autoslug field

elixir-revisionair ecto
A Revisionair adapter based on Ecto. Allows you to persist and keep track of revisions of your data structures in any of Ecto's supported databases.
Stars: ✭ 18 (-86.96%)
Mutual labels:  ecto, elixir-library
fat ecto
Query mechanism for Ecto
Stars: ✭ 20 (-85.51%)
Mutual labels:  ecto, elixir-library
guardian trackable
A Guardian hook to track user sign ins.
Stars: ✭ 25 (-81.88%)
Mutual labels:  ecto
commanded-ecto-projections
Read model projections for Commanded using Ecto
Stars: ✭ 68 (-50.72%)
Mutual labels:  ecto
txbox
Elixir Bitcoin transaction storage schema, built on Ecto.
Stars: ✭ 14 (-89.86%)
Mutual labels:  ecto
ecto conditionals
EctoConditionals implements a flexibly functional find_or_create and upsert behavior for Ecto models.
Stars: ✭ 17 (-87.68%)
Mutual labels:  ecto
pretty print formatter
Pretty Print Formatter for Elixir Logger module -- Colorize Ecto's SQL ouput 🖌️
Stars: ✭ 22 (-84.06%)
Mutual labels:  ecto
hierarch
Tree structure & hierarchy for ecto models with ltree(Postgres)
Stars: ✭ 30 (-78.26%)
Mutual labels:  ecto
ecto diff
Generates a data structure describing the difference between two ecto structs
Stars: ✭ 22 (-84.06%)
Mutual labels:  ecto
bourne
🚤 Better streaming for Ecto.
Stars: ✭ 71 (-48.55%)
Mutual labels:  ecto
pardall markdown
Reactive publishing framework, filesystem-based with support for Markdown, nested hierarchies, and instant content rebuilding. Written in Elixir.
Stars: ✭ 84 (-39.13%)
Mutual labels:  elixir-library
ex spirit
No description or website provided.
Stars: ✭ 26 (-81.16%)
Mutual labels:  elixir-library
ex sieve
Implement dynamic filtering and sorting API for Ecto queries
Stars: ✭ 37 (-73.19%)
Mutual labels:  ecto
comeonin ecto password
Ecto type for saving encrypted passwords using Comeonin
Stars: ✭ 34 (-75.36%)
Mutual labels:  ecto
ecto commons
Ecto common validators for Date, Time, URLs, Emails, PostalCodes, Phone Numbers, Luhn checks, etc.
Stars: ✭ 33 (-76.09%)
Mutual labels:  ecto
ecto generator
Generate Ecto schemas from existing database in Phoenix - Elixir
Stars: ✭ 20 (-85.51%)
Mutual labels:  ecto
exqlite
An SQLite3 driver for Elixir
Stars: ✭ 128 (-7.25%)
Mutual labels:  ecto
vim-ide-elixir
Highly opininated setup of vim plugins for Elixir development
Stars: ✭ 28 (-79.71%)
Mutual labels:  elixir-library
simple graphql client
SimpleGraphqlClient is a graphql client, focused on simplicity and ease of use.
Stars: ✭ 17 (-87.68%)
Mutual labels:  elixir-library
riemannx
A riemann client for elixir (TCP/UDP/TLS supported)
Stars: ✭ 23 (-83.33%)
Mutual labels:  elixir-library

EctoAutoslugField

Build Status Coverage Status Module Version Hex Docs License

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 >= 3.7 and ecto < 4!

See this blog post for more information.

Installation

def deps do
  [
    {:ecto_autoslug_field, "~> 3.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 override get_sources/2 function
  • :always_change - if this option is set slug will be recreated from the given sources each time maybe_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(model, params \\ :invalid) do
    model
    |> cast(params, [: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.

Copyright and License

Copyright (c) 2016 Nikita Sobolev

This library is released under the MIT License. See the LICENSE.md file for further 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].