RepHtml is a synonym for Html

This commit is contained in:
Michael Snoyman 2013-03-11 10:54:26 +02:00
parent 1d0cac6e03
commit f3f55a1ecd
4 changed files with 18 additions and 25 deletions

View File

@ -37,12 +37,11 @@ module Yesod.Content
, ToTypedContent (..)
, HasContentType (..)
-- ** Specific content types
, RepHtml (..)
, RepHtml
, RepJson (..)
, RepPlain (..)
, RepXml (..)
-- ** Smart constructors
, repHtml
, repJson
, repPlain
, repXml
@ -120,9 +119,6 @@ instance ToFlushBuilder Builder where toFlushBuilder = Chunk
instance ToFlushBuilder (Flush B.ByteString) where toFlushBuilder = fmap fromByteString
instance ToFlushBuilder B.ByteString where toFlushBuilder = Chunk . fromByteString
repHtml :: ToContent a => a -> RepHtml
repHtml = RepHtml . toContent
repJson :: ToContent a => a -> RepJson
repJson = RepJson . toContent
@ -135,10 +131,6 @@ repXml = RepXml . toContent
class ToTypedContent a => HasContentType a where
getContentType :: Monad m => m a -> ContentType
instance HasContentType RepHtml where
getContentType _ = typeHtml
deriving instance ToContent RepHtml
instance HasContentType RepJson where
getContentType _ = typeJson
deriving instance ToContent RepJson
@ -240,8 +232,6 @@ instance ToTypedContent () where
toTypedContent () = TypedContent typePlain (toContent ())
instance ToTypedContent (ContentType, Content) where
toTypedContent (ct, content) = TypedContent ct content
instance ToTypedContent RepHtml where
toTypedContent (RepHtml c) = TypedContent typeHtml c
instance ToTypedContent RepJson where
toTypedContent (RepJson c) = TypedContent typeJson c
instance ToTypedContent RepPlain where

View File

@ -251,7 +251,7 @@ data Content = ContentBuilder !BBuilder.Builder !(Maybe Int) -- ^ The content an
data TypedContent = TypedContent !ContentType !Content
newtype RepHtml = RepHtml Content
type RepHtml = Html
newtype RepJson = RepJson Content
newtype RepPlain = RepPlain Content
newtype RepXml = RepXml Content

View File

@ -112,8 +112,8 @@ module Yesod.Handler
, getMessage
-- * Helpers for specific content
-- ** Hamlet
, hamletToContent
, hamletToRepHtml
, giveUrlRenderer
-- ** Misc
, newIdent
-- * Lifting
@ -689,16 +689,20 @@ $doctype 5
<input type="submit" value="Continue">
|] >>= sendResponse
-- | Converts the given Hamlet template into 'Content', which can be used in a
-- Yesod 'Response'.
hamletToContent :: HandlerReader m => HtmlUrl (Route (HandlerMaster m)) -> m Content
hamletToContent h = do
render <- getUrlRenderParams
return $ toContent $ h render
-- | Wraps the 'Content' generated by 'hamletToContent' in a 'RepHtml'.
hamletToRepHtml :: HandlerReader m => HtmlUrl (Route (HandlerMaster m)) -> m RepHtml
hamletToRepHtml = liftM RepHtml . hamletToContent
hamletToRepHtml :: HandlerReader m => HtmlUrl (Route (HandlerMaster m)) -> m Html
hamletToRepHtml = giveUrlRenderer
-- | Provide a URL rendering function to the given function and return the
-- result. Useful for processing Shakespearean templates.
--
-- Since 1.2.0
giveUrlRenderer :: HandlerReader m
=> ((Route (HandlerMaster m) -> [(Text, Text)] -> Text) -> output)
-> m output
giveUrlRenderer f = do
render <- getUrlRenderParams
return $ f render
-- | Get the request\'s 'W.Request' value.
waiRequest :: HandlerReader m => m W.Request

View File

@ -54,7 +54,6 @@ import Yesod.Routes.Class
import Yesod.Handler (getMessageRender, getUrlRenderParams)
import Yesod.Core.Trans.Class (lift)
import Text.Shakespeare.I18N (RenderMessage)
import Yesod.Content (toContent)
import Control.Monad (liftM)
import Data.Text (Text)
import qualified Data.Map as Map
@ -217,11 +216,11 @@ rules = do
-- | Wraps the 'Content' generated by 'hamletToContent' in a 'RepHtml'.
ihamletToRepHtml :: RenderMessage master message
=> HtmlUrlI18n message (Route master)
-> GHandler sub master RepHtml
-> GHandler sub master Html
ihamletToRepHtml ih = do
urender <- getUrlRenderParams
mrender <- getMessageRender
return $ RepHtml $ toContent $ ih (toHtml . mrender) urender
return $ ih (toHtml . mrender) urender
tell :: GWData (Route master) -> GWidget sub master ()
tell w = GWidget $ return ((), w)