servant/servant-lucid/src/Servant/HTML/Lucid.hs

37 lines
1.1 KiB
Haskell
Raw Normal View History

2015-05-02 12:04:47 +02:00
{-# LANGUAGE CPP #-}
{-# LANGUAGE DeriveDataTypeable #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE OverloadedStrings #-}
2015-12-27 17:54:29 +01:00
#include "overlapping-compat.h"
2015-05-02 12:04:47 +02:00
-- | An @HTML@ empty data type with `MimeRender` instances for @lucid@'s
-- `ToHtml` class and `Html` datatype.
-- You should only need to import this module for it's instances and the
-- `HTML` datatype.:
--
-- >>> type Eg = Get '[HTML] a
--
-- Will then check that @a@ has a `ToHtml` instance, or is `Html`.
module Servant.HTML.Lucid where
import Data.Typeable (Typeable)
import Lucid (Html, ToHtml (..), renderBS)
import qualified Network.HTTP.Media as M
import Servant.API (Accept (..), MimeRender (..))
data HTML deriving Typeable
2015-05-29 16:08:14 +02:00
-- | @text/html;charset=utf-8@
2015-05-02 12:04:47 +02:00
instance Accept HTML where
contentType _ = "text" M.// "html" M./: ("charset", "utf-8")
2015-12-27 17:54:29 +01:00
instance OVERLAPPABLE_
2015-05-02 12:04:47 +02:00
ToHtml a => MimeRender HTML a where
mimeRender _ = renderBS . toHtml
2015-12-27 17:54:29 +01:00
instance OVERLAPPING_
2015-05-02 12:04:47 +02:00
MimeRender HTML (Html a) where
mimeRender _ = renderBS