yesod/Yesod/Hamlet.hs
Michael Snoyman c91a4ada56 Changes reflecting web-routes-quasi modifications.
Minimal changes to get hello world working.
2010-06-30 12:23:55 +03:00

41 lines
1.2 KiB
Haskell

{-# LANGUAGE TypeSynonymInstances #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# OPTIONS_GHC -fno-warn-orphans #-}
module Yesod.Hamlet
( -- * Hamlet library
module Text.Hamlet
-- * Convert to something displayable
, hamletToContent
, hamletToRepHtml
-- * Page templates
, PageContent (..)
)
where
import Text.Hamlet
import Yesod.Content
import Yesod.Handler
-- | Content for a web page. By providing this datatype, we can easily create
-- generic site templates, which would have the type signature:
--
-- > PageContent url -> Hamlet url
data PageContent url = PageContent
{ pageTitle :: Html ()
, pageHead :: Hamlet url
, pageBody :: Hamlet url
}
-- | Converts the given Hamlet template into 'Content', which can be used in a
-- Yesod 'Response'.
hamletToContent :: Hamlet (Routes master) -> GHandler sub master Content
hamletToContent h = do
render <- getUrlRender
return $ toContent $ renderHamlet render h
-- | Wraps the 'Content' generated by 'hamletToContent' in a 'RepHtml'.
hamletToRepHtml :: Hamlet (Routes master) -> GHandler sub master RepHtml
hamletToRepHtml = fmap RepHtml . hamletToContent