{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE OverloadedStrings #-}
{-# OPTIONS_GHC -fno-warn-orphans #-}
module Web.Page.Html
( class__,
toText,
genName,
genNamePre,
libCss,
libJs,
HtmlT,
Html,
)
where
import Control.Monad.State
import Data.Bool
import Data.Text
import qualified Data.Text.Lazy as Lazy
import Lucid
import Prelude
class__ :: Text -> Attribute
class__ t = class_ (" " <> t <> " ")
toText :: Html a -> Text
toText = Lazy.toStrict . renderText
genName :: (MonadState Int m) => m Text
genName = do
modify (+ 1)
(pack . show) <$> get
genNamePre :: (MonadState Int m) => Text -> m Text
genNamePre pre = (pre <>) <$> genName
libCss :: Text -> Html ()
libCss url =
link_
[ rel_ "stylesheet",
href_ url
]
libJs :: Text -> Html ()
libJs url = with (script_ mempty) [src_ url]
instance ToHtml Double where
toHtml = toHtml . (pack . show)
toHtmlRaw = toHtmlRaw . (pack . show)
instance ToHtml Bool where
toHtml = toHtml . bool ("false" :: Text) "true"
toHtmlRaw = toHtmlRaw . bool ("false" :: Text) "true"
instance ToHtml Int where
toHtml = toHtml . (pack . show)
toHtmlRaw = toHtmlRaw . (pack . show)
instance ToHtml () where
toHtml = const "()"
toHtmlRaw = const "()"