{-# LANGUAGE UndecidableInstances #-}
{-# LANGUAGE FlexibleInstances #-}
module IHP.HSX.ToHtml where
import Prelude
import qualified Text.Blaze.Html5 as Html5
import qualified Text.Blaze.Internal
import Data.Text
import Data.ByteString
import Data.String.Conversions (cs)
import IHP.HSX.ConvertibleStrings ()
class ToHtml a where
toHtml :: a -> Html5.Html
instance ToHtml (Text.Blaze.Internal.MarkupM ()) where
{-# INLINE toHtml #-}
toHtml :: MarkupM () -> MarkupM ()
toHtml MarkupM ()
a = MarkupM ()
a
instance ToHtml Text where
{-# INLINE toHtml #-}
toHtml :: Text -> MarkupM ()
toHtml = Text -> MarkupM ()
Html5.text
instance ToHtml String where
{-# INLINE toHtml #-}
toHtml :: String -> MarkupM ()
toHtml = String -> MarkupM ()
Html5.string
instance ToHtml ByteString where
{-# INLINE toHtml #-}
toHtml :: ByteString -> MarkupM ()
toHtml ByteString
value = Text -> MarkupM ()
forall a. ToHtml a => a -> MarkupM ()
toHtml (ByteString -> Text
forall a b. ConvertibleStrings a b => a -> b
cs ByteString
value :: Text)
instance {-# OVERLAPPABLE #-} ToHtml a => ToHtml (Maybe a) where
{-# INLINE toHtml #-}
toHtml :: Maybe a -> MarkupM ()
toHtml Maybe a
maybeValue = MarkupM () -> (a -> MarkupM ()) -> Maybe a -> MarkupM ()
forall b a. b -> (a -> b) -> Maybe a -> b
maybe MarkupM ()
forall a. Monoid a => a
mempty a -> MarkupM ()
forall a. ToHtml a => a -> MarkupM ()
toHtml Maybe a
maybeValue
instance {-# OVERLAPPABLE #-} Show a => ToHtml a where
{-# INLINE toHtml #-}
toHtml :: a -> MarkupM ()
toHtml a
value = String -> MarkupM ()
Html5.string (a -> String
forall a. Show a => a -> String
show a
value)