slug-0.1.0: Type-safe slugs for Yesod ecosystem

Copyright© 2015 Mark Karpov
LicenseBSD 3 clause
MaintainerMark Karpov <markkarpov@openmailbox.org>
Stabilityexperimental
Portabilityportable
Safe HaskellNone
LanguageHaskell2010

Web.Slug

Description

Type-safe slug implementation for Yesod ecosystem.

Synopsis

Documentation

data Slug Source

Slug. Textual value inside is always guaranteed to have the following qualities:

  • it's not empty;
  • it consists only of alpha-numeric groups of characters (words) separated by '-' dashes in such a way that entire slug cannot start or end in a dash and also two dashes in a row cannot be found;
  • every character with defined notion of case is lower-cased.

Slugs are good for semantic URLs and also can be used as identifier of a sort in some cases.

mkSlug :: MonadThrow m => Text -> m Slug Source

Create Slug from Text, all necessary transformations are applied. Argument of this function can be title of an article or something like that.

Note that result is inside MonadThrow, that means you can just get it in Maybe, in more complex contexts it will throw SlugException.

This function also have a useful property:

mkSlug = mkSlug >=> mkSlug . unSlug

unSlug :: Slug -> Text Source

Get textual representation of Slug.

data SlugException Source

This exception is thrown by mkSlug when its input cannot be converted into proper Slug.

Constructors

InvalidInput Text