Various minor changes, better description

This commit is contained in:
Michael Snoyman 2010-05-11 23:47:05 +03:00
parent cda45d2837
commit 6376157c64
4 changed files with 64 additions and 14 deletions

View File

@ -50,7 +50,7 @@ import Web.ClientSession
-- | Generates URL datatype and site function for the given 'Resource's. This
-- 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
-> [Resource]
-> Q [Dec]
@ -58,8 +58,8 @@ mkYesod name = mkYesodGeneral name [] False
-- | Generates URL datatype and site function for the given 'Resource's. This
-- is used for creating subsites, *not* sites. See 'mkYesod' for the latter.
-- Use 'parseRoutes' in generate to create the 'Resource's. In general, a
-- subsite is not executable by itself, but instead provides functionality to
-- Use 'parseRoutes' to create the 'Resource's. In general, a subsite is not
-- executable by itself, but instead provides functionality to
-- be embedded in other sites.
mkYesodSub :: String -- ^ name of the argument datatype
-> [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
$ 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
-> QuasiSite YesodApp arg arg
-> Routes arg

View File

@ -19,17 +19,11 @@ module Yesod.Hamlet
where
import Text.Hamlet
import Text.Hamlet.Monad (outputHtml)
import Text.Hamlet.Monad (outputHtml, htmlContentToText)
import Yesod.Content
import Yesod.Handler
import Data.Convertible.Text
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
-- generic site templates, which would have the type signature:

View File

@ -24,11 +24,15 @@ module Yesod.Request
, waiRequest
, languages
-- * Lookup parameters
, lookupGetParam
, lookupPostParam
, lookupCookie
, lookupSession
-- ** Alternate
, getParams
, postParams
, cookies
, session
, lookupSession
-- * Parameter type synonyms
, ParamName
, ParamValue
@ -56,6 +60,18 @@ instance RequestReader ((->) Request) where
getRequest = id
-- | 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 = reqLangs `liftM` getRequest
@ -97,18 +113,39 @@ getParams = do
rr <- getRequest
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.
postParams :: MonadIO m => Request -> m (ParamName -> [ParamValue])
postParams rr = do
(pp, _) <- liftIO $ reqRequestBody rr
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.
cookies :: RequestReader m => m (ParamName -> [ParamValue])
cookies = do
rr <- getRequest
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.
session :: RequestReader m => m (ParamName -> [ParamValue])
session = do

View File

@ -4,7 +4,21 @@ license: BSD3
license-file: LICENSE
author: 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
stability: Stable
cabal-version: >= 1.6
@ -30,7 +44,7 @@ library
template-haskell >= 2.4 && < 2.5,
web-routes >= 0.22 && < 0.23,
web-routes-quasi >= 0.1 && < 0.2,
hamlet >= 0.2.0 && < 0.3,
hamlet >= 0.2.2 && < 0.3,
transformers >= 0.1 && < 0.3,
clientsession >= 0.2 && < 0.3,
MonadCatchIO-transformers >= 0.2.2 && < 0.3,