yesod-0.6.4: Creation of type-safe, RESTful web applications.

Yesod.Yesod

Contents

Description

The basic typeclass for a Yesod application.

Synopsis

Type classes

class Eq (Route a) => Yesod a whereSource

Define settings for a Yesod applications. The only required setting is approot; other than that, there are intelligent defaults.

Methods

approot :: a -> StringSource

An absolute URL to the root of the application. Do not include trailing slash.

If you want to be lazy, you can supply an empty string under the following conditions:

  • Your application is served from the root of the domain.
  • You do not use any features that require absolute URLs, such as Atom feeds and XML sitemaps.

encryptKey :: a -> IO KeySource

The encryption key to be used for encrypting client sessions.

clientSessionDuration :: a -> IntSource

Number of minutes before a client session times out. Defaults to 120 (2 hours).

errorHandler :: ErrorResponse -> GHandler sub a ChooseRepSource

Output error response pages.

defaultLayout :: GWidget sub a () -> GHandler sub a RepHtmlSource

Applies some form of layout to the contents of a page.

onRequest :: GHandler sub a ()Source

Gets called at the beginning of each request. Useful for logging.

urlRenderOverride :: a -> Route a -> Maybe StringSource

Override the rendering function for a particular URL. One use case for this is to offload static hosting to a different domain name to avoid sending cookies.

isAuthorizedSource

Arguments

:: Route a 
-> Bool

is this a write request?

-> GHandler s a AuthResult 

Determine if a request is authorized or not.

Return Nothing is the request is authorized, Just a message if unauthorized. If authentication is required, you should use a redirect; the Auth helper provides this functionality automatically.

isWriteRequest :: Route a -> GHandler s a BoolSource

Determines whether the current request is a write request. By default, this assumes you are following RESTful principles, and determines this from request method. In particular, all except the following request methods are considered write: GET HEAD OPTIONS TRACE.

This function is used to determine if a request is authorized; see isAuthorized.

authRoute :: a -> Maybe (Route a)Source

The default route for authentication.

Used in particular by isAuthorized, but library users can do whatever they want with it.

splitPath :: a -> ByteString -> Either ByteString [String]Source

A function used to split a raw PATH_INFO value into path pieces. It returns a Left value when you should redirect to the given path, and a Right value on successful parse.

By default, it splits paths on slashes, and ensures the following are true:

  • No double slashes
  • If the last path segment has a period, there is no trailing slash.
  • Otherwise, ensures there is a trailing slash.

joinPath :: a -> String -> [String] -> [(String, String)] -> StringSource

Join the pieces of a path together into an absolute URL. This should be the inverse of splitPath.

addStaticContentSource

Arguments

:: String

filename extension

-> String

mime-type

-> ByteString

content

-> GHandler sub a (Maybe (Either String (Route a, [(String, String)]))) 

This function is used to store some static content to be served as an external file. The most common case of this is stashing CSS and JavaScript content in an external file; the Yesod.Widget module uses this feature.

The return value is Nothing if no storing was performed; this is the default implementation. A Just Left gives the absolute URL of the file, whereas a Just Right gives the type-safe URL. The former is necessary when you are serving the content outside the context of a Yesod application, such as via memcached.

sessionIpAddress :: a -> BoolSource

Whether or not to tie a session to a specific IP address. Defaults to True.

class Eq (Route y) => YesodSite y whereSource

This class is automatically instantiated when you use the template haskell mkYesod function. You should never need to deal with it directly.

Methods

getSite :: Site (Route y) (Method -> Maybe (GHandler y y ChooseRep))Source

class Eq (Route s) => YesodSubSite s y whereSource

Same as YesodSite, but for subsites. Once again, users should not need to deal with it directly, as the mkYesodSub creates instances appropriately.

Methods

getSubSite :: Site (Route s) (Method -> Maybe (GHandler s y ChooseRep))Source

Instances

YesodSubSite Static master 
(Yesod master, Item item, SinglePiece (Key item), ToForm item master) => YesodSubSite (Crud master item) master 

Persistence

class YesodPersist y whereSource

Associated Types

type YesodDB y :: (* -> *) -> * -> *Source

Methods

runDB :: YesodDB y (GHandler sub y) a -> GHandler sub y aSource

get404 :: (PersistBackend (t m), PersistEntity val, Monad (t m), Failure ErrorResponse m, MonadTrans t) => Key val -> t m valSource

Breadcrumbs

class YesodBreadcrumbs y whereSource

A type-safe, concise method of creating breadcrumbs for pages. For each resource, you declare the title of the page and the parent resource (if present).

Methods

breadcrumb :: Route y -> GHandler sub y (String, Maybe (Route y))Source

Returns the title and the parent resource, if available. If you return a Nothing, then this is considered a top-level page.

breadcrumbs :: YesodBreadcrumbs y => GHandler sub y (String, [(Route y, String)])Source

Gets the title of the current page and the hierarchy of parent pages, along with their respective titles.

Utitlities

maybeAuthorizedSource

Arguments

:: Yesod a 
=> Route a 
-> Bool

is this a write request?

-> GHandler s a (Maybe (Route a)) 

Return the same URL if the user is authorized to see it.

Built on top of isAuthorized. This is useful for building page that only contain links to pages the user is allowed to see.

widgetToPageContent :: (Eq (Route master), Yesod master) => GWidget sub master () -> GHandler sub master (PageContent (Route master))Source

Convert a widget to a PageContent.

defaultLayoutJson :: Yesod master => GWidget sub master () -> Json -> GHandler sub master RepHtmlJsonSource

Provide both an HTML and JSON representation for a piece of data, using the default layout for the HTML output (defaultLayout).

redirectToPost :: Route master -> GHandler sub master aSource

Redirect to a POST resource.

This is not technically a redirect; instead, it returns an HTML page with a POST form, and some Javascript to automatically submit the form. This can be useful when you need to post a plain link somewhere that needs to cause changes on the server.

Defaults

defaultErrorHandler :: Yesod y => ErrorResponse -> GHandler sub y ChooseRepSource

The default error handler for errorHandler.

Data types