{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE IncoherentInstances #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# OPTIONS_GHC -fno-warn-orphans #-}
module Web.Rep.Html
( class__,
toText,
libCss,
libJs,
HtmlT,
Html,
)
where
import Data.List (intersperse)
import qualified Data.Text.Lazy as Lazy
import Lucid
import NumHask.Prelude
class__ :: Text -> Attribute
class__ t = class_ (" " <> t <> " ")
toText :: Html a -> Text
toText = Lazy.toStrict . renderText
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 "()"
instance {-# INCOHERENT #-} (ToHtml a) => ToHtml [a] where
toHtml = mconcat . Data.List.intersperse (toHtml ("," :: Text)) . fmap toHtml
toHtmlRaw = mconcat . Data.List.intersperse (toHtmlRaw ("," :: Text)) . fmap toHtmlRaw