Giter VIP home page Giter VIP logo

slug's Introduction

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:

  • 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.

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.

slug's People

Contributors

mrkkrp avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

hecrj lucch

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.