Home

Awesome

Slug

License BSD3 Hackage Stackage Nightly Stackage LTS Build Status

This is a slug implementation that plays nicely with the Yesod ecosystem. Although it's fairly easy to write this thing, slugs are useful and general enough to be coded once and be used again and again. So this little package eliminates some boilerplate you might find yourself writing.

Quick start

The package provides the data type Slug that is an instance of various type classes, so it can be used with Persistent or as a part of a route. It also works with the aeson package.

The slugs are completely type-safe. When you have a Slug, you can be sure that there is a valid slug inside. Valid slug has the following qualities:

To use the package with persistent models, just import Web.Slug and add it to model file:

MyEntity
  slug Slug
  …

Use it in route file like this:

/post/#Slug PostR GET

In Haskell code, create slugs from Text with mkSlug and extract their textual representation with unSlug. The following property holds:

mkSlug = mkSlug >=> mkSlug . unSlug

License

Copyright © 2015–2018 Mark Karpov

Distributed under BSD 3 clause license.