57 lines
1.3 KiB
Haskell
57 lines
1.3 KiB
Haskell
{-# LANGUAGE NoImplicitPrelude #-}
|
|
{-# LANGUAGE OverloadedStrings #-}
|
|
{-# LANGUAGE TypeFamilies, FlexibleContexts, ConstraintKinds #-}
|
|
{-# LANGUAGE QuasiQuotes #-}
|
|
|
|
module Utils
|
|
( module Utils
|
|
) where
|
|
|
|
import ClassyPrelude.Yesod
|
|
|
|
import Utils.DB as Utils
|
|
import Utils.Common as Utils
|
|
|
|
import Text.Blaze (Markup, ToMarkup)
|
|
|
|
import Data.Map (Map)
|
|
import qualified Data.Map as Map
|
|
import qualified Data.List as List
|
|
|
|
|
|
tickmark :: IsString a => a
|
|
tickmark = fromString "✔"
|
|
|
|
text2Html :: Text -> Html
|
|
text2Html = toHtml -- prevents ambiguous types
|
|
|
|
toWgt :: (ToMarkup a, MonadBaseControl IO m, MonadThrow m, MonadIO m) =>
|
|
a -> WidgetT site m ()
|
|
toWgt = toWidget . toHtml
|
|
|
|
text2widget :: (MonadBaseControl IO m, MonadThrow m, MonadIO m) =>
|
|
Text -> WidgetT site m ()
|
|
text2widget t = [whamlet|#{t}|]
|
|
|
|
str2widget :: (MonadBaseControl IO m, MonadThrow m, MonadIO m) =>
|
|
String -> WidgetT site m ()
|
|
str2widget s = [whamlet|#{s}|]
|
|
|
|
|
|
withFragment :: ( Monad m
|
|
) => MForm m (a, WidgetT site IO ()) -> Markup -> MForm m (a, WidgetT site IO ())
|
|
withFragment form html = (flip fmap) form $ \(x, widget) -> (x, toWidget html >> widget)
|
|
|
|
-----------
|
|
-- Maybe --
|
|
-----------
|
|
whenIsJust :: Monad m => Maybe a -> (a -> m ()) -> m ()
|
|
whenIsJust (Just x) f = f x
|
|
whenIsJust Nothing _ = return ()
|
|
|
|
|
|
|
|
----------
|
|
-- Maps --
|
|
----------
|