aboutsummaryrefslogtreecommitdiff
path: root/lib/Yesod/Orphans.hs
blob: f66f8af06f0884acbf66c5161848831c5eeb023e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
-- | a module containing orphan shakespeare instances to make writing templates
-- a bit more fun & less of a hassle.
module Yesod.Orphans where

import           Data.Text                (Text)
import qualified Data.Text                as T
import           Data.Time                (UTCTime)
import           Data.Time.Calendar       (Day)
import           Data.Time.Format.ISO8601 (iso8601Show)
import           Data.UUID                (UUID)
import qualified Data.UUID                as UUID
import           Fmt                      ((+|), (|+))
import           GTFS
import           Persist
import           Text.Blaze.Html          (ToMarkup (..))
import           Text.Shakespeare.Text
import           Yesod

--- some orphans to make hamlet easier to deal with
instance ToMarkup Time where
  toMarkup time =
    toMarkup (show time)

instance ToMarkup Day where
  toMarkup day = toMarkup (iso8601Show day)

instance ToMessage UTCTime where
  toMessage = formatW3

instance ToMessage Token where
  toMessage (Token uuid) = UUID.toText uuid

instance ToMarkup UTCTime where
  toMarkup = toMarkup . formatW3

instance ToMarkup Token where
  toMarkup (Token uuid) = toMarkup (UUID.toText uuid)

instance ToMessage Double where
  toMessage = T.pack . show

instance ToMarkup Seconds where
  toMarkup (Seconds s) =
    if s > 0 then toMarkup ("+"+|s `div` 60|+"" :: Text)
    else toMarkup (s `div` 60)