-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Painfully simple URL writing combinators -- -- Simple URL DSL for Haskell. -- -- This library tries to make it easier for people to write Url strings, -- structurally. Packages like Yesod Routes do a wonderful job at -- implementing string-free routing and references, but sometimes we have -- to compromise. This tries to make that compromise less painful. -- -- Use bare combinators to render your strings (kinda useless): -- --
--   expandRelative $ "foo.php" <?> ("key1","bar") <&> ("key2","baz")
--   
--   ↪ "foo.php?key1=bar&key2=baz"
--   
-- -- ... or use the MonadReader instance for a configurable host: -- --
--   let path = runAbsoluteUrl $ url $ "foo.php" <?> ("key1","bar") <&> ("key2","baz")
--   path "example.com"
--   
--   ↪ "example.com/foo.php?key1=bar&key2=baz"
--   
-- -- url puts the UrlString in a MonadReader that we can -- use for applying our host. We use different monads for different -- deployment schemes (currently we have 3 - RelativeUrl, -- GroundedUrl, and AbsoluteUrl), which we can -- integrate in different libraries, like Lucid: -- --
--   (runAbsoluteUrl $ renderTextT $ do
--       foo <- lift $ url $ "foo" <?> ("bar","baz")
--       script_ [src_ foo] "" )
--   ) "example.com"
--   
--   ↪ "<script src=\"example.com/foo?bar=baz\"></script>"
--   
-- -- ... and in Scotty ... -- --
--   main :: IO ()
--   main = scottyT 3000
--       rootConf
--       rootConf
--       run
--   
--     where
--       rootConf = flip runAbsoluteT "http://example.com"
--   
--       run :: ( MonadIO m
--              , MonadReader T.Text m
--              , Url T.Text m ) =>
--              ScottyT LT.Text m ()
--       run = get "/" $ do
--         path <- lift $ url $ "foo" <?> ("bar","baz")
--         text $ LT.fromStrict path
--   
--   λ> curl localhost:3000/
--   ↪ "http://example.com/foo?bar=baz"
--   
-- -- Note that in the scotty example, we don't use one of our deployment -- schemes - this is because the scottyT function expects it's -- underlying monad to be an instance of MonadIO, which we can -- only instantiate in our monad transformers. -- -- Please take mind - the string type underlying the Url rendering is -- generalized to Data.String.IsString for convenient use with -- -XOverloadedStrings. However, due to that generality, we need -- to specify the monomorphic type (like Data.Text.Text above). @package urlpath @version 2.0.0 module Data.Url.Types -- | Abstract data type for a Url - a "target" and GET parameters. We -- require IsString and Monoid for generic -- construction, but rendering will require a monomorphic type. -- -- The type constructor is parameterized over it's underlying -- IsString & Monoid instance. data QueryString a [QueryString] :: a -> [(a, a)] -> Maybe a -> QueryString a -- | We can't provide a Show instance for QueryString -- because that would force us to use String. showUrlString :: QueryString a -> a -- | Makes a QueryString out of a raw target path and a GET -- parameter pair. () :: (TextualMonoid a) => a -> (a, a) -> QueryString a -- | Adds another GET parameter pair to a QueryString. (<&>) :: (TextualMonoid a) => QueryString a -> (a, a) -> QueryString a -- | Adds a hash parameter to a QueryString. (<#>) :: (TextualMonoid a) => QueryString a -> a -> QueryString a fromRoute :: (TextualMonoid a) => ([a], [(a, a)]) -> QueryString a -- | Render the Url String flatly - without anything prepended to the -- target. expandRelative :: (TextualMonoid plain) => QueryString plain -> plain -- | Render the Url String as grounded - prepended with a "root" -- // character. expandGrounded :: (TextualMonoid plain) => QueryString plain -> plain -- | Render the Url String as absolute - getting the root from a -- MonadReader context. expandAbsolute :: (MonadReader plain m, TextualMonoid plain) => QueryString plain -> m plain -- | Render the Url String as absolute, but with your own configuration -- type. -- --
--   data SiteConfig = SiteConfig { host :: T.Text
--                                , cdnHost :: T.Text
--                                }
--     deriving (Show, Eq)
--   
--   foo :: HtmlT (Reader SiteConfig) ()
--   foo = do
--     url <- lift $ expandAbsoluteWith ("foo.php" <?> ("bar","baz")) host
--     script_ [src_ url] ""
--   
--   bar :: LT.Text
--   bar = (runReader (runTextT foo)) $
--     SiteConfig "example.com" "cdn.example.com"
--   
expandAbsoluteWith :: (MonadReader a m, TextualMonoid plain) => QueryString plain -> (a -> plain) -> m plain newtype RelativeUrlT h m b [RelativeUrlT] :: (h -> m b) -> RelativeUrlT h m b [runRelativeUrlT] :: RelativeUrlT h m b -> h -> m b type RelativeUrl h b = RelativeUrlT h Identity b newtype GroundedUrlT h m b [GroundedUrlT] :: (h -> m b) -> GroundedUrlT h m b [runGroundedUrlT] :: GroundedUrlT h m b -> h -> m b type GroundedUrl h b = GroundedUrlT h Identity b newtype AbsoluteUrlT h m b [AbsoluteUrlT] :: (h -> m b) -> AbsoluteUrlT h m b [runAbsoluteUrlT] :: AbsoluteUrlT h m b -> h -> m b type AbsoluteUrl h b = AbsoluteUrlT h Identity b instance Functor m => Functor (AbsoluteUrlT h m) instance Functor m => Functor (GroundedUrlT h m) instance Functor m => Functor (RelativeUrlT h m) instance Applicative f => Applicative (RelativeUrlT h f) instance Monad m => Monad (RelativeUrlT h m) instance MonadTrans (RelativeUrlT h) instance (Monad m, IsString h) => MonadReader h (RelativeUrlT h m) instance MonadIO m => MonadIO (RelativeUrlT h m) instance Applicative f => Applicative (GroundedUrlT h f) instance Monad m => Monad (GroundedUrlT h m) instance MonadTrans (GroundedUrlT h) instance (Monad m, IsString h) => MonadReader h (GroundedUrlT h m) instance MonadIO m => MonadIO (GroundedUrlT h m) instance Applicative f => Applicative (AbsoluteUrlT h f) instance Monad m => Monad (AbsoluteUrlT h m) instance MonadTrans (AbsoluteUrlT h) instance (Monad m, IsString h) => MonadReader h (AbsoluteUrlT h m) instance MonadIO m => MonadIO (AbsoluteUrlT h m) module Data.Url -- | Overload deployment schemes with this - then, all that's needed is a -- type coercion to change deployment. class Url plain m => UrlReader plain m where type family Result m :: * -> * runUrlReader :: (UrlReader plain m, Url plain m) => m b -> plain -> Result m b -- | Url is a relationship between an underlying string type -- plain, and a deployment context m. We try to make -- the deployment style coercible at the top level - if the expression -- has a type Url String (AbsoluteUrlT String Identity) or -- Monad m => Url T.Text (GroundedUrlT LT.Text m) will force -- all use-cases within the expression to coerce to that type. class (TextualMonoid plain, MonadReader plain m) => Url plain (m :: * -> *) queryUrl :: Url plain m => QueryString plain -> m plain plainUrl :: Url plain m => plain -> m plain instance (Monad m, TextualMonoid plain) => Url plain (RelativeUrlT plain m) instance (Monad m, TextualMonoid plain) => UrlReader plain (RelativeUrlT plain m) instance (Monad m, TextualMonoid plain) => Url plain (GroundedUrlT plain m) instance (Monad m, TextualMonoid plain) => UrlReader plain (GroundedUrlT plain m) instance (Monad m, TextualMonoid plain) => Url plain (AbsoluteUrlT plain m) instance (Monad m, TextualMonoid plain) => UrlReader plain (AbsoluteUrlT plain m)