module UrlPath
( UrlReader (..)
, Url (..)
, module UrlPath.Types ) where
import UrlPath.Types
import qualified Data.Text as T
import Control.Monad.Trans
import Control.Monad.Reader.Class
import Data.Monoid
import Control.Applicative
import Control.Monad
import Data.Functor.Identity
class MonadReader T.Text m => UrlReader (m :: * -> *) where
runUrlReader :: m a
-> T.Text
-> a
instance MonadReader T.Text Identity where
ask = return ""
instance UrlReader Identity where
runUrlReader x _ = runIdentity x
instance UrlReader AbsoluteUrl where
runUrlReader = runAbsoluteUrl
instance UrlReader RelativeUrl where
runUrlReader = runRelativeUrl
instance UrlReader GroundedUrl where
runUrlReader = runGroundedUrl
class MonadReader T.Text m => Url a m where
renderUrl :: a
-> m T.Text
instance Url T.Text Identity where
renderUrl = Identity
instance Url UrlString Identity where
renderUrl = Identity . expandRelative
instance Url UrlString RelativeUrl where
renderUrl x = RelativeUrl $ \_ -> expandRelative x
instance Url UrlString GroundedUrl where
renderUrl x = GroundedUrl $ \_ -> expandGrounded x
instance Url UrlString AbsoluteUrl where
renderUrl = expandAbsolute
instance Monad m => Url UrlString (RelativeUrlT m) where
renderUrl x = RelativeUrlT $ \_ -> return $ expandRelative x
instance Monad m => Url UrlString (GroundedUrlT m) where
renderUrl x = GroundedUrlT $ \_ -> return $ expandGrounded x
instance Monad m => Url UrlString (AbsoluteUrlT m) where
renderUrl = expandAbsolute
instance Url T.Text RelativeUrl where
renderUrl x = RelativeUrl $ \_ -> expandRelative $ UrlString x []
instance Url T.Text GroundedUrl where
renderUrl x = GroundedUrl $ \_ -> expandGrounded $ UrlString x []
instance Url T.Text AbsoluteUrl where
renderUrl x = expandAbsolute $ UrlString x []
instance Monad m => Url T.Text (RelativeUrlT m) where
renderUrl x = RelativeUrlT $ \_ -> return $ expandRelative $ UrlString x []
instance Monad m => Url T.Text (GroundedUrlT m) where
renderUrl x = GroundedUrlT $ \_ -> return $ expandGrounded $ UrlString x []
instance Monad m => Url T.Text (AbsoluteUrlT m) where
renderUrl x = expandAbsolute $ UrlString x []