Skip to content
This repository has been archived by the owner on Jun 22, 2018. It is now read-only.

Commit

Permalink
Add some missing articles, etc.
Browse files Browse the repository at this point in the history
  • Loading branch information
mrkkrp committed Apr 22, 2017
1 parent 8d62f83 commit 5d071b2
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@
[![Build Status](https://travis-ci.org/mrkkrp/slug.svg?branch=master)](https://travis-ci.org/mrkkrp/slug)
[![Coverage Status](https://coveralls.io/repos/mrkkrp/slug/badge.svg?branch=master&service=github)](https://coveralls.io/github/mrkkrp/slug?branch=master)

This is [slug](https://en.wikipedia.org/wiki/Semantic_URL#Slug)
This is a [slug](https://en.wikipedia.org/wiki/Semantic_URL#Slug)
implementation that plays nicely with [Yesod](http://www.yesodweb.com/)
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 data type `Slug` that is instance of various type
classes, so it can be used with Persistent or as part of route. It also
works with `aeson` package.
The package provides the data type `Slug` that is an instance of various
type classes, so it can be used with Persistent or as 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:
Expand Down
18 changes: 9 additions & 9 deletions Web/Slug.hs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ import Control.Applicative ((<$>))
#endif

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

data SlugException
= InvalidInput Text -- ^ Slug cannot be generated for given text
Expand Down Expand Up @@ -74,12 +74,12 @@ instance Exception SlugException where

newtype Slug = Slug Text deriving (Eq, Ord, Data, Typeable)

-- | Create 'Slug' from 'Text', all necessary transformations are
-- | Create a 'Slug' from a 'Text' value, 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'
-- Note that the result is inside 'MonadThrow', that means you can just get
-- it in 'Maybe', in more complex contexts it will throw 'SlugException'
-- exception using 'InvalidInput' constructor.
--
-- This function also has a useful property:
Expand All @@ -93,22 +93,22 @@ mkSlug text =
then throwM (InvalidInput text)
else return . Slug . T.intercalate "-" $ ws

-- | Get textual representation of 'Slug'.
-- | Get textual representation of a 'Slug'.

unSlug :: Slug -> Text
unSlug (Slug x) = x

-- | Convert 'Text' to possibly empty collection of words. Every word is
-- guaranteed to be non-empty alpha-numeric lowercased sequence of
-- | Convert 'Text' to a possibly empty collection of words. Every word is
-- guaranteed to be non-empty alpha-numeric lower-cased sequence of
-- characters.

getSlugWords :: Text -> [Text]
getSlugWords = T.words . T.toLower . T.map f . T.replace "'" ""
where f x = if isAlphaNum x then x else ' '

-- | Convert 'Text' into 'Slug' only when it is already valid slug.
-- | Convert a 'Text' into a 'Slug' only when it is already valid slug.
--
-- This function can throw 'SlugException' exception using 'InvalidSlug'
-- This function can throw the 'SlugException' exception using 'InvalidSlug'
-- constructor.

parseSlug :: MonadThrow m => Text -> m Slug
Expand Down

0 comments on commit 5d071b2

Please sign in to comment.