{-# LANGUAGE  UndecidableInstances #-}

module IHP.HtmlSupport.ToHtml where
import qualified Text.Blaze.Html5              as Html5
import qualified Text.Blaze.Internal
import ClassyPrelude
import Data.String.Conversions (cs)
import IHP.View.ConvertibleStrings ()
import qualified Data.ByteString
import Prelude (String)

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 ()
forall a b. ConvertibleStrings a b => a -> b
cs

instance ToHtml String where
    {-# INLINE toHtml #-}
    toHtml :: String -> MarkupM ()
toHtml = String -> MarkupM ()
forall a b. ConvertibleStrings a b => a -> b
cs

instance ToHtml Data.ByteString.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 #-} Show 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 ()
forall a b. ConvertibleStrings a b => a -> b
cs (a -> String
forall a. Show a => a -> String
show a
value)