1
1
mirror of https://github.com/srid/ema.git synced 2024-12-01 15:13:36 +03:00

slug: add aeson instances

This commit is contained in:
Sridhar Ratnakumar 2021-05-15 17:52:23 -04:00
parent 735b182dc8
commit ed782ef1a9
2 changed files with 4 additions and 2 deletions

View File

@ -3,7 +3,7 @@
## Unreleased (0.2.0.0) ## Unreleased (0.2.0.0)
- `Ema.Slug` - `Ema.Slug`
- Add `Ord`, `Generic` and `Data` instances to `Slug` - Add `Ord`, `Generic`, `Data` and Aeson instances to `Slug`
- Unicode normalize slugs using NFC - Unicode normalize slugs using NFC
- TODO(doc) Add `decodeSlug` and `encodeSlug` - TODO(doc) Add `decodeSlug` and `encodeSlug`
- Add default implementation based on Enum for `staticRoute` - Add default implementation based on Enum for `staticRoute`

View File

@ -1,9 +1,11 @@
{-# LANGUAGE DeriveDataTypeable #-} {-# LANGUAGE DeriveDataTypeable #-}
{-# LANGUAGE DeriveGeneric #-} {-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE InstanceSigs #-} {-# LANGUAGE InstanceSigs #-}
module Ema.Route.Slug where module Ema.Route.Slug where
import Data.Aeson (FromJSON, ToJSON)
import Data.Data (Data) import Data.Data (Data)
import qualified Data.Text as T import qualified Data.Text as T
import qualified Data.Text.Normalize as UT import qualified Data.Text.Normalize as UT
@ -11,7 +13,7 @@ import qualified Network.URI.Encode as UE
-- | An URL path is made of multiple slugs, separated by '/' -- | An URL path is made of multiple slugs, separated by '/'
newtype Slug = Slug {unSlug :: Text} newtype Slug = Slug {unSlug :: Text}
deriving (Eq, Show, Ord, Data, Generic) deriving (Eq, Show, Ord, Data, Generic, ToJSON, FromJSON)
-- | Decode an URL component into a `Slug` using `Network.URI.Encode` -- | Decode an URL component into a `Slug` using `Network.URI.Encode`
decodeSlug :: Text -> Slug decodeSlug :: Text -> Slug