From ed56c8731775f5c80f7c0c46ea885ba430e7a0cd Mon Sep 17 00:00:00 2001 From: Michael Snoyman Date: Tue, 4 May 2010 22:08:20 +0300 Subject: [PATCH] Exposing fullRender --- Yesod/Dispatch.hs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/Yesod/Dispatch.hs b/Yesod/Dispatch.hs index 9dfa3819..b941a2eb 100644 --- a/Yesod/Dispatch.hs +++ b/Yesod/Dispatch.hs @@ -8,6 +8,8 @@ module Yesod.Dispatch -- * Convert to WAI , toWaiApp , basicHandler + -- * Utilities + , fullRender ) where import Yesod.Handler @@ -120,8 +122,7 @@ toWaiApp' y resource session' env = do types = httpAccept env pathSegments = filter (not . null) $ cleanupSegments resource eurl = quasiParse site pathSegments - render u = approot y ++ '/' - : encodePathInfo (fixSegs $ quasiRender site u) + render = fullRender (approot y) site rr <- parseWaiRequest env session' onRequest y rr let ya = case eurl of @@ -143,6 +144,14 @@ toWaiApp' y resource session' env = do let eh er = runHandler (errorHandler y er) render eurl' id y id unYesodApp ya eh rr types >>= responseToWaiResponse +-- | Fully render a route to an absolute URL. +fullRender :: String -- ^ approot, no trailing slash + -> QuasiSite YesodApp arg arg + -> Routes arg + -> String +fullRender ar site route = + ar ++ '/' : encodePathInfo (fixSegs $ quasiRender site route) + cleanupSegments :: [B.ByteString] -> [String] cleanupSegments = decodePathInfo . intercalate "/" . map B.unpack