ProductPromotion
Logo

Elixir

made by https://0x3d.site

GitHub - wemake-services/ecto_autoslug_field: Automatically create slugs for Ecto schemas.
Automatically create slugs for Ecto schemas. Contribute to wemake-services/ecto_autoslug_field development by creating an account on GitHub.
Visit Site

GitHub - wemake-services/ecto_autoslug_field: Automatically create slugs for Ecto schemas.

GitHub - wemake-services/ecto_autoslug_field: Automatically create slugs for Ecto schemas.

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 slugify 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.1"}
  ]
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.

Articles
to learn more about the elixir concepts.

Resources
which are currently available to browse on.

mail [email protected] to add your project or resources here 🔥.

FAQ's
to know more about the topic.

mail [email protected] to add your project or resources here 🔥.

Queries
or most google FAQ's about Elixir.

mail [email protected] to add more queries here 🔍.

More Sites
to check out once you're finished browsing here.

0x3d
https://www.0x3d.site/
0x3d is designed for aggregating information.
NodeJS
https://nodejs.0x3d.site/
NodeJS Online Directory
Cross Platform
https://cross-platform.0x3d.site/
Cross Platform Online Directory
Open Source
https://open-source.0x3d.site/
Open Source Online Directory
Analytics
https://analytics.0x3d.site/
Analytics Online Directory
JavaScript
https://javascript.0x3d.site/
JavaScript Online Directory
GoLang
https://golang.0x3d.site/
GoLang Online Directory
Python
https://python.0x3d.site/
Python Online Directory
Swift
https://swift.0x3d.site/
Swift Online Directory
Rust
https://rust.0x3d.site/
Rust Online Directory
Scala
https://scala.0x3d.site/
Scala Online Directory
Ruby
https://ruby.0x3d.site/
Ruby Online Directory
Clojure
https://clojure.0x3d.site/
Clojure Online Directory
Elixir
https://elixir.0x3d.site/
Elixir Online Directory
Elm
https://elm.0x3d.site/
Elm Online Directory
Lua
https://lua.0x3d.site/
Lua Online Directory
C Programming
https://c-programming.0x3d.site/
C Programming Online Directory
C++ Programming
https://cpp-programming.0x3d.site/
C++ Programming Online Directory
R Programming
https://r-programming.0x3d.site/
R Programming Online Directory
Perl
https://perl.0x3d.site/
Perl Online Directory
Java
https://java.0x3d.site/
Java Online Directory
Kotlin
https://kotlin.0x3d.site/
Kotlin Online Directory
PHP
https://php.0x3d.site/
PHP Online Directory
React JS
https://react.0x3d.site/
React JS Online Directory
Angular
https://angular.0x3d.site/
Angular JS Online Directory