aboutsummaryrefslogtreecommitdiff
path: root/lib/Yesod
diff options
context:
space:
mode:
authorstuebinm2023-01-22 17:22:29 +0100
committerstuebinm2023-01-22 17:22:29 +0100
commit6c2454fb9edff9bdd34415e58a2a3782a984ec5a (patch)
tree2c81dec9a8b6077e3386be3b82542132549e4642 /lib/Yesod
parent3d0980811d61a78f265ec06dd5bd4ef2cde1cbdf (diff)
switch to ghc 9.0.2
this makes the nix builds /much/ nicer
Diffstat (limited to 'lib/Yesod')
-rw-r--r--lib/Yesod/Orphans.hs45
1 files changed, 45 insertions, 0 deletions
diff --git a/lib/Yesod/Orphans.hs b/lib/Yesod/Orphans.hs
new file mode 100644
index 0000000..f66f8af
--- /dev/null
+++ b/lib/Yesod/Orphans.hs
@@ -0,0 +1,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)