ecto_autoslug_field v0.1.2 EctoAutoslugField.SlugBase

This module defines all fuctions Slug module uses.

Summary

Functions

This function is used to build the slug itself

This function is used to get sources for the slug

This function is used to generate slug

This is just a helper function to check for uniqueness

Functions

build_slug(sources)

Specs

build_slug(Keyword.t) :: String.t

This function is used to build the slug itself.

This function is a place to modify the result slug. For convinience you can call super(sources) which will return the slug binary. super(sources) uses Slugger, but you can completely change slug-engine to your own.

If for some reason slug should not be set - just return nil or empty binary.

It should return a binary or nil.

get_sources(changeset, opts)

Specs

get_sources(Ecto.Changeset.t, Keyword.t) :: [atom | binary]

This function is used to get sources for the slug.

There can be many usecases when this behaviour is required, here are the brief examples:

  1. Conditional slug sources
  2. Add any data from different sources

This function should return list of atoms or binaries.

When proccessing the returned list:

  1. atom-key is supposed to identify the model field
  2. binary-key is treated as a data itself, it won’t be changed
maybe_generate_slug(changeset, sources, opts)

Specs

maybe_generate_slug(Ecto.Changeset.t, atom | list | none, Keyword.t) :: Ecto.Changeset.t

This function is used to generate slug.

It is called ‘maybe’ since it may not generate slug for several reasons:

  1. It was already created and :always_change option was not set
  2. The source fields for the slug were empty

This function takes changeset as an input and returns changeset.

unique_constraint(changeset, to, opts \\ [])

Specs

unique_constraint(Ecto.Changeset.t, atom, Keyword.t) :: Ecto.Changeset.t

This is just a helper function to check for uniqueness.

It basically just wraps Ecto.Changeset and set a proper field name.