Various minor changes, better description
This commit is contained in:
parent
cda45d2837
commit
6376157c64
@ -50,7 +50,7 @@ import Web.ClientSession
|
|||||||
|
|
||||||
-- | Generates URL datatype and site function for the given 'Resource's. This
|
-- | Generates URL datatype and site function for the given 'Resource's. This
|
||||||
-- is used for creating sites, *not* subsites. See 'mkYesodSub' for the latter.
|
-- is used for creating sites, *not* subsites. See 'mkYesodSub' for the latter.
|
||||||
-- Use 'parseRoutes' in generate to create the 'Resource's.
|
-- Use 'parseRoutes' to create the 'Resource's.
|
||||||
mkYesod :: String -- ^ name of the argument datatype
|
mkYesod :: String -- ^ name of the argument datatype
|
||||||
-> [Resource]
|
-> [Resource]
|
||||||
-> Q [Dec]
|
-> Q [Dec]
|
||||||
@ -58,8 +58,8 @@ mkYesod name = mkYesodGeneral name [] False
|
|||||||
|
|
||||||
-- | Generates URL datatype and site function for the given 'Resource's. This
|
-- | Generates URL datatype and site function for the given 'Resource's. This
|
||||||
-- is used for creating subsites, *not* sites. See 'mkYesod' for the latter.
|
-- is used for creating subsites, *not* sites. See 'mkYesod' for the latter.
|
||||||
-- Use 'parseRoutes' in generate to create the 'Resource's. In general, a
|
-- Use 'parseRoutes' to create the 'Resource's. In general, a subsite is not
|
||||||
-- subsite is not executable by itself, but instead provides functionality to
|
-- executable by itself, but instead provides functionality to
|
||||||
-- be embedded in other sites.
|
-- be embedded in other sites.
|
||||||
mkYesodSub :: String -- ^ name of the argument datatype
|
mkYesodSub :: String -- ^ name of the argument datatype
|
||||||
-> [Name] -- ^ a list of classes the master datatype must be an instance of
|
-> [Name] -- ^ a list of classes the master datatype must be an instance of
|
||||||
@ -172,7 +172,12 @@ toWaiApp' y resource env = do
|
|||||||
ContentEnum e -> Right $ W.buffer
|
ContentEnum e -> Right $ W.buffer
|
||||||
$ W.Enumerator e
|
$ W.Enumerator e
|
||||||
|
|
||||||
-- | Fully render a route to an absolute URL.
|
-- | Fully render a route to an absolute URL. Since Yesod does this for you
|
||||||
|
-- internally, you will rarely need access to this. However, if you need to
|
||||||
|
-- generate links *outside* of the Handler monad, this may be useful.
|
||||||
|
--
|
||||||
|
-- For example, if you want to generate an e-mail which links to your site,
|
||||||
|
-- this is the function you would want to use.
|
||||||
fullRender :: String -- ^ approot, no trailing slash
|
fullRender :: String -- ^ approot, no trailing slash
|
||||||
-> QuasiSite YesodApp arg arg
|
-> QuasiSite YesodApp arg arg
|
||||||
-> Routes arg
|
-> Routes arg
|
||||||
|
|||||||
@ -19,17 +19,11 @@ module Yesod.Hamlet
|
|||||||
where
|
where
|
||||||
|
|
||||||
import Text.Hamlet
|
import Text.Hamlet
|
||||||
import Text.Hamlet.Monad (outputHtml)
|
import Text.Hamlet.Monad (outputHtml, htmlContentToText)
|
||||||
import Yesod.Content
|
import Yesod.Content
|
||||||
import Yesod.Handler
|
import Yesod.Handler
|
||||||
import Data.Convertible.Text
|
import Data.Convertible.Text
|
||||||
import Web.Routes.Quasi (Routes)
|
import Web.Routes.Quasi (Routes)
|
||||||
import Data.Text (Text)
|
|
||||||
import Web.Encodings (encodeHtml)
|
|
||||||
|
|
||||||
htmlContentToText :: HtmlContent -> Text
|
|
||||||
htmlContentToText (Encoded t) = t
|
|
||||||
htmlContentToText (Unencoded t) = encodeHtml t
|
|
||||||
|
|
||||||
-- | Content for a web page. By providing this datatype, we can easily create
|
-- | Content for a web page. By providing this datatype, we can easily create
|
||||||
-- generic site templates, which would have the type signature:
|
-- generic site templates, which would have the type signature:
|
||||||
|
|||||||
@ -24,11 +24,15 @@ module Yesod.Request
|
|||||||
, waiRequest
|
, waiRequest
|
||||||
, languages
|
, languages
|
||||||
-- * Lookup parameters
|
-- * Lookup parameters
|
||||||
|
, lookupGetParam
|
||||||
|
, lookupPostParam
|
||||||
|
, lookupCookie
|
||||||
|
, lookupSession
|
||||||
|
-- ** Alternate
|
||||||
, getParams
|
, getParams
|
||||||
, postParams
|
, postParams
|
||||||
, cookies
|
, cookies
|
||||||
, session
|
, session
|
||||||
, lookupSession
|
|
||||||
-- * Parameter type synonyms
|
-- * Parameter type synonyms
|
||||||
, ParamName
|
, ParamName
|
||||||
, ParamValue
|
, ParamValue
|
||||||
@ -56,6 +60,18 @@ instance RequestReader ((->) Request) where
|
|||||||
getRequest = id
|
getRequest = id
|
||||||
|
|
||||||
-- | Get the list of supported languages supplied by the user.
|
-- | Get the list of supported languages supplied by the user.
|
||||||
|
--
|
||||||
|
-- Languages are determined based on the following three (in descending order
|
||||||
|
-- of preference:
|
||||||
|
--
|
||||||
|
-- * The _LANG get parameter.
|
||||||
|
--
|
||||||
|
-- * The _LANG cookie.
|
||||||
|
--
|
||||||
|
-- * Accept-Language HTTP header.
|
||||||
|
--
|
||||||
|
-- This is handled by the parseWaiRequest function in Yesod.Dispatch (not
|
||||||
|
-- exposed).
|
||||||
languages :: RequestReader m => m [String]
|
languages :: RequestReader m => m [String]
|
||||||
languages = reqLangs `liftM` getRequest
|
languages = reqLangs `liftM` getRequest
|
||||||
|
|
||||||
@ -97,18 +113,39 @@ getParams = do
|
|||||||
rr <- getRequest
|
rr <- getRequest
|
||||||
return $ multiLookup $ reqGetParams rr
|
return $ multiLookup $ reqGetParams rr
|
||||||
|
|
||||||
|
-- | Lookup for GET parameters.
|
||||||
|
lookupGetParam :: RequestReader m => ParamName -> m (Maybe ParamValue)
|
||||||
|
lookupGetParam pn = do
|
||||||
|
rr <- getRequest
|
||||||
|
return $ lookup pn $ reqGetParams rr
|
||||||
|
|
||||||
-- | All POST paramater values with the given name.
|
-- | All POST paramater values with the given name.
|
||||||
postParams :: MonadIO m => Request -> m (ParamName -> [ParamValue])
|
postParams :: MonadIO m => Request -> m (ParamName -> [ParamValue])
|
||||||
postParams rr = do
|
postParams rr = do
|
||||||
(pp, _) <- liftIO $ reqRequestBody rr
|
(pp, _) <- liftIO $ reqRequestBody rr
|
||||||
return $ multiLookup pp
|
return $ multiLookup pp
|
||||||
|
|
||||||
|
-- | Lookup for POST parameters.
|
||||||
|
lookupPostParam :: (MonadIO m, RequestReader m)
|
||||||
|
=> ParamName
|
||||||
|
-> m (Maybe ParamValue)
|
||||||
|
lookupPostParam pn = do
|
||||||
|
rr <- getRequest
|
||||||
|
(pp, _) <- liftIO $ reqRequestBody rr
|
||||||
|
return $ lookup pn pp
|
||||||
|
|
||||||
-- | All cookies with the given name.
|
-- | All cookies with the given name.
|
||||||
cookies :: RequestReader m => m (ParamName -> [ParamValue])
|
cookies :: RequestReader m => m (ParamName -> [ParamValue])
|
||||||
cookies = do
|
cookies = do
|
||||||
rr <- getRequest
|
rr <- getRequest
|
||||||
return $ multiLookup $ reqCookies rr
|
return $ multiLookup $ reqCookies rr
|
||||||
|
|
||||||
|
-- | Lookup for cookie data.
|
||||||
|
lookupCookie :: RequestReader m => ParamName -> m (Maybe ParamValue)
|
||||||
|
lookupCookie pn = do
|
||||||
|
rr <- getRequest
|
||||||
|
return $ lookup pn $ reqCookies rr
|
||||||
|
|
||||||
-- | All session data with the given name.
|
-- | All session data with the given name.
|
||||||
session :: RequestReader m => m (ParamName -> [ParamValue])
|
session :: RequestReader m => m (ParamName -> [ParamValue])
|
||||||
session = do
|
session = do
|
||||||
|
|||||||
18
yesod.cabal
18
yesod.cabal
@ -4,7 +4,21 @@ license: BSD3
|
|||||||
license-file: LICENSE
|
license-file: LICENSE
|
||||||
author: Michael Snoyman <michael@snoyman.com>
|
author: Michael Snoyman <michael@snoyman.com>
|
||||||
maintainer: Michael Snoyman <michael@snoyman.com>
|
maintainer: Michael Snoyman <michael@snoyman.com>
|
||||||
synopsis: A library for creating RESTful web applications.
|
synopsis: Creation of type-safe, RESTful web applications.
|
||||||
|
description:
|
||||||
|
Yesod is a framework designed to foster creation of RESTful web application that have strong compile-time guarantees of correctness. It also affords space efficient code and portability to many deployment backends, from CGI to stand-alone serving.
|
||||||
|
.
|
||||||
|
The Yesod documentation site <http://docs.yesodweb.com/> has much more information, tutorials and information on some of the supporting packages, like Hamlet and web-routes-quasi.
|
||||||
|
.
|
||||||
|
As a quick overview, here is a fully-functional Hello World application:
|
||||||
|
.
|
||||||
|
> {-# LANGUAGE TypeFamilies, QuasiQuotes, TemplateHaskell #-}
|
||||||
|
> import Yesod
|
||||||
|
> data HelloWorld = HelloWorld
|
||||||
|
> mkYesod "HelloWorld" [$parseRoutes|/ Home GET|]
|
||||||
|
> instance Yesod HelloWorld where approot _ = ""
|
||||||
|
> getHome = return $ RepPlain $ cs "Hello World!"
|
||||||
|
> main = toWaiApp HelloWorld >>= basicHandler 3000
|
||||||
category: Web
|
category: Web
|
||||||
stability: Stable
|
stability: Stable
|
||||||
cabal-version: >= 1.6
|
cabal-version: >= 1.6
|
||||||
@ -30,7 +44,7 @@ library
|
|||||||
template-haskell >= 2.4 && < 2.5,
|
template-haskell >= 2.4 && < 2.5,
|
||||||
web-routes >= 0.22 && < 0.23,
|
web-routes >= 0.22 && < 0.23,
|
||||||
web-routes-quasi >= 0.1 && < 0.2,
|
web-routes-quasi >= 0.1 && < 0.2,
|
||||||
hamlet >= 0.2.0 && < 0.3,
|
hamlet >= 0.2.2 && < 0.3,
|
||||||
transformers >= 0.1 && < 0.3,
|
transformers >= 0.1 && < 0.3,
|
||||||
clientsession >= 0.2 && < 0.3,
|
clientsession >= 0.2 && < 0.3,
|
||||||
MonadCatchIO-transformers >= 0.2.2 && < 0.3,
|
MonadCatchIO-transformers >= 0.2.2 && < 0.3,
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user