RepHtml is a synonym for Html
This commit is contained in:
parent
1d0cac6e03
commit
f3f55a1ecd
@ -37,12 +37,11 @@ module Yesod.Content
|
|||||||
, ToTypedContent (..)
|
, ToTypedContent (..)
|
||||||
, HasContentType (..)
|
, HasContentType (..)
|
||||||
-- ** Specific content types
|
-- ** Specific content types
|
||||||
, RepHtml (..)
|
, RepHtml
|
||||||
, RepJson (..)
|
, RepJson (..)
|
||||||
, RepPlain (..)
|
, RepPlain (..)
|
||||||
, RepXml (..)
|
, RepXml (..)
|
||||||
-- ** Smart constructors
|
-- ** Smart constructors
|
||||||
, repHtml
|
|
||||||
, repJson
|
, repJson
|
||||||
, repPlain
|
, repPlain
|
||||||
, repXml
|
, repXml
|
||||||
@ -120,9 +119,6 @@ instance ToFlushBuilder Builder where toFlushBuilder = Chunk
|
|||||||
instance ToFlushBuilder (Flush B.ByteString) where toFlushBuilder = fmap fromByteString
|
instance ToFlushBuilder (Flush B.ByteString) where toFlushBuilder = fmap fromByteString
|
||||||
instance ToFlushBuilder B.ByteString where toFlushBuilder = Chunk . fromByteString
|
instance ToFlushBuilder B.ByteString where toFlushBuilder = Chunk . fromByteString
|
||||||
|
|
||||||
repHtml :: ToContent a => a -> RepHtml
|
|
||||||
repHtml = RepHtml . toContent
|
|
||||||
|
|
||||||
repJson :: ToContent a => a -> RepJson
|
repJson :: ToContent a => a -> RepJson
|
||||||
repJson = RepJson . toContent
|
repJson = RepJson . toContent
|
||||||
|
|
||||||
@ -135,10 +131,6 @@ repXml = RepXml . toContent
|
|||||||
class ToTypedContent a => HasContentType a where
|
class ToTypedContent a => HasContentType a where
|
||||||
getContentType :: Monad m => m a -> ContentType
|
getContentType :: Monad m => m a -> ContentType
|
||||||
|
|
||||||
instance HasContentType RepHtml where
|
|
||||||
getContentType _ = typeHtml
|
|
||||||
deriving instance ToContent RepHtml
|
|
||||||
|
|
||||||
instance HasContentType RepJson where
|
instance HasContentType RepJson where
|
||||||
getContentType _ = typeJson
|
getContentType _ = typeJson
|
||||||
deriving instance ToContent RepJson
|
deriving instance ToContent RepJson
|
||||||
@ -240,8 +232,6 @@ instance ToTypedContent () where
|
|||||||
toTypedContent () = TypedContent typePlain (toContent ())
|
toTypedContent () = TypedContent typePlain (toContent ())
|
||||||
instance ToTypedContent (ContentType, Content) where
|
instance ToTypedContent (ContentType, Content) where
|
||||||
toTypedContent (ct, content) = TypedContent ct content
|
toTypedContent (ct, content) = TypedContent ct content
|
||||||
instance ToTypedContent RepHtml where
|
|
||||||
toTypedContent (RepHtml c) = TypedContent typeHtml c
|
|
||||||
instance ToTypedContent RepJson where
|
instance ToTypedContent RepJson where
|
||||||
toTypedContent (RepJson c) = TypedContent typeJson c
|
toTypedContent (RepJson c) = TypedContent typeJson c
|
||||||
instance ToTypedContent RepPlain where
|
instance ToTypedContent RepPlain where
|
||||||
|
|||||||
@ -251,7 +251,7 @@ data Content = ContentBuilder !BBuilder.Builder !(Maybe Int) -- ^ The content an
|
|||||||
|
|
||||||
data TypedContent = TypedContent !ContentType !Content
|
data TypedContent = TypedContent !ContentType !Content
|
||||||
|
|
||||||
newtype RepHtml = RepHtml Content
|
type RepHtml = Html
|
||||||
newtype RepJson = RepJson Content
|
newtype RepJson = RepJson Content
|
||||||
newtype RepPlain = RepPlain Content
|
newtype RepPlain = RepPlain Content
|
||||||
newtype RepXml = RepXml Content
|
newtype RepXml = RepXml Content
|
||||||
|
|||||||
@ -112,8 +112,8 @@ module Yesod.Handler
|
|||||||
, getMessage
|
, getMessage
|
||||||
-- * Helpers for specific content
|
-- * Helpers for specific content
|
||||||
-- ** Hamlet
|
-- ** Hamlet
|
||||||
, hamletToContent
|
|
||||||
, hamletToRepHtml
|
, hamletToRepHtml
|
||||||
|
, giveUrlRenderer
|
||||||
-- ** Misc
|
-- ** Misc
|
||||||
, newIdent
|
, newIdent
|
||||||
-- * Lifting
|
-- * Lifting
|
||||||
@ -689,16 +689,20 @@ $doctype 5
|
|||||||
<input type="submit" value="Continue">
|
<input type="submit" value="Continue">
|
||||||
|] >>= sendResponse
|
|] >>= 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'.
|
-- | Wraps the 'Content' generated by 'hamletToContent' in a 'RepHtml'.
|
||||||
hamletToRepHtml :: HandlerReader m => HtmlUrl (Route (HandlerMaster m)) -> m RepHtml
|
hamletToRepHtml :: HandlerReader m => HtmlUrl (Route (HandlerMaster m)) -> m Html
|
||||||
hamletToRepHtml = liftM RepHtml . hamletToContent
|
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.
|
-- | Get the request\'s 'W.Request' value.
|
||||||
waiRequest :: HandlerReader m => m W.Request
|
waiRequest :: HandlerReader m => m W.Request
|
||||||
|
|||||||
@ -54,7 +54,6 @@ import Yesod.Routes.Class
|
|||||||
import Yesod.Handler (getMessageRender, getUrlRenderParams)
|
import Yesod.Handler (getMessageRender, getUrlRenderParams)
|
||||||
import Yesod.Core.Trans.Class (lift)
|
import Yesod.Core.Trans.Class (lift)
|
||||||
import Text.Shakespeare.I18N (RenderMessage)
|
import Text.Shakespeare.I18N (RenderMessage)
|
||||||
import Yesod.Content (toContent)
|
|
||||||
import Control.Monad (liftM)
|
import Control.Monad (liftM)
|
||||||
import Data.Text (Text)
|
import Data.Text (Text)
|
||||||
import qualified Data.Map as Map
|
import qualified Data.Map as Map
|
||||||
@ -217,11 +216,11 @@ rules = do
|
|||||||
-- | Wraps the 'Content' generated by 'hamletToContent' in a 'RepHtml'.
|
-- | Wraps the 'Content' generated by 'hamletToContent' in a 'RepHtml'.
|
||||||
ihamletToRepHtml :: RenderMessage master message
|
ihamletToRepHtml :: RenderMessage master message
|
||||||
=> HtmlUrlI18n message (Route master)
|
=> HtmlUrlI18n message (Route master)
|
||||||
-> GHandler sub master RepHtml
|
-> GHandler sub master Html
|
||||||
ihamletToRepHtml ih = do
|
ihamletToRepHtml ih = do
|
||||||
urender <- getUrlRenderParams
|
urender <- getUrlRenderParams
|
||||||
mrender <- getMessageRender
|
mrender <- getMessageRender
|
||||||
return $ RepHtml $ toContent $ ih (toHtml . mrender) urender
|
return $ ih (toHtml . mrender) urender
|
||||||
|
|
||||||
tell :: GWData (Route master) -> GWidget sub master ()
|
tell :: GWData (Route master) -> GWidget sub master ()
|
||||||
tell w = GWidget $ return ((), w)
|
tell w = GWidget $ return ((), w)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user