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

Safe Haskell | None
Language | Haskell98

Yesod.Core.Content

Contents

- Content
- Mime types
  - Data type
- Utilities
- Evaluation strategy
- Representations
  - Specific content types
  - Smart constructors

Synopsis

- data Content
  - = ContentBuilder !Builder !(Maybe Int)
  - | ContentSource !(Source (ResourceT IO) (Flush Builder))
  - | ContentFile !FilePath !(Maybe FilePart)
  - | ContentDontEvaluate !Content
- emptyContent :: Content
- class ToContent a where
- class ToFlushBuilder a where
- type ContentType = ByteString
- typeHtml :: ContentType
- typePlain :: ContentType
- typeJson :: ContentType
- typeXml :: ContentType
- typeAtom :: ContentType
- typeRss :: ContentType
- typeJpeg :: ContentType
- typePng :: ContentType
- typeGif :: ContentType
- typeSvg :: ContentType
- typeJavascript :: ContentType
- typeCss :: ContentType
- typeFlv :: ContentType
- typeOgv :: ContentType
- typeOctet :: ContentType
- simpleContentType :: ContentType -> ContentType
- contentTypeTypes :: ContentType -> (ByteString, ByteString)
- newtype DontFullyEvaluate a = DontFullyEvaluate {
  - unDontFullyEvaluate :: a
  }
- data TypedContent = TypedContent !ContentType !Content
- class ToContent a => ToTypedContent a where
- class ToTypedContent a => HasContentType a where
- type RepHtml = Html
- newtype RepJson = RepJson Content
- newtype RepPlain = RepPlain Content
- newtype RepXml = RepXml Content
- repJson :: ToContent a => a -> RepJson
- repPlain :: ToContent a => a -> RepPlain
- repXml :: ToContent a => a -> RepXml

# Content

data Content #

Constructors

ContentBuilder !Builder !(Maybe Int) | The content and optional content length.
ContentSource !(Source (ResourceT IO) (Flush Builder)) |
ContentFile !FilePath !(Maybe FilePart) |
ContentDontEvaluate !Content |

Instances

IsString Content # |
Methods fromString :: String -> Content #
ToContent Content # |
Methods toContent :: Content -> Content #
ToTypedContent (ContentType, Content) # |
Methods toTypedContent :: (ContentType, Content) -> TypedContent #
ToContent (ContentType, Content) # |
Methods toContent :: (ContentType, Content) -> Content #

emptyContent :: Content #

Zero-length enumerator.

class ToContent a where #

Anything which can be converted into `Content`. Most of the time, you will want to use the `ContentBuilder` constructor. An easier approach will be to use a pre-defined `toContent` function, such as converting your data into a lazy bytestring and then calling `toContent` on that.

Please note that the built-in instances for lazy data structures (`String`, lazy `ByteString`, lazy `Text` and `Html`) will not automatically include the content length for the `ContentBuilder` constructor.

Minimal complete definition

toContent

Methods

toContent :: a -> Content #

Instances

ToContent () # |
Methods toContent :: () -> Content #
ToContent ByteString # |
Methods toContent :: ByteString -> Content #
ToContent ByteString # |
Methods toContent :: ByteString -> Content #
ToContent String # |
Methods toContent :: String -> Content #
ToContent Text # |
Methods toContent :: Text -> Content #
ToContent Builder # |
Methods toContent :: Builder -> Content #
ToContent Encoding # |
Methods toContent :: Encoding -> Content #
ToContent Value # |
Methods toContent :: Value -> Content #
ToContent Text # |
Methods toContent :: Text -> Content #
ToContent Html # |
Methods toContent :: Html -> Content #
ToContent Css # |
Methods toContent :: Css -> Content #
ToContent Javascript # |
Methods toContent :: Javascript -> Content #
ToContent RepXml # |
Methods toContent :: RepXml -> Content #
ToContent RepPlain # |
Methods toContent :: RepPlain -> Content #
ToContent RepJson # |
Methods toContent :: RepJson -> Content #
ToContent TypedContent # |
Methods toContent :: TypedContent -> Content #
ToContent Content # |
Methods toContent :: Content -> Content #
ToContent a => ToContent (DontFullyEvaluate a) # |
Methods toContent :: DontFullyEvaluate a -> Content #
ToContent (ContentType, Content) # |
Methods toContent :: (ContentType, Content) -> Content #
ToFlushBuilder builder => ToContent (Source (ResourceT IO) builder) # |
Methods toContent :: Source (ResourceT IO) builder -> Content #
ToFlushBuilder builder => ToContent (ResumableSource (ResourceT IO) builder) # |
Methods toContent :: ResumableSource (ResourceT IO) builder -> Content #
ToFlushBuilder builder => ToContent (Pipe () () builder () (ResourceT IO) ()) # |
Methods toContent :: Pipe () () builder () (ResourceT IO) () -> Content #

class ToFlushBuilder a where #

A class for all data which can be sent in a streaming response. Note that for textual data, instances must use UTF-8 encoding.

Since 1.2.0

Minimal complete definition

toFlushBuilder

Methods

toFlushBuilder :: a -> Flush Builder #

Instances

ToFlushBuilder ByteString # |
Methods toFlushBuilder :: ByteString -> Flush Builder #
ToFlushBuilder ByteString # |
Methods toFlushBuilder :: ByteString -> Flush Builder #
ToFlushBuilder String # |
Methods toFlushBuilder :: String -> Flush Builder #
ToFlushBuilder Text # |
Methods toFlushBuilder :: Text -> Flush Builder #
ToFlushBuilder Builder # |
Methods toFlushBuilder :: Builder -> Flush Builder #
ToFlushBuilder Text # |
Methods toFlushBuilder :: Text -> Flush Builder #
ToFlushBuilder Html # |
Methods toFlushBuilder :: Html -> Flush Builder #
ToFlushBuilder (Flush ByteString) # |
Methods toFlushBuilder :: Flush ByteString -> Flush Builder #
ToFlushBuilder (Flush ByteString) # |
Methods toFlushBuilder :: Flush ByteString -> Flush Builder #
ToFlushBuilder (Flush String) # |
Methods toFlushBuilder :: Flush String -> Flush Builder #
ToFlushBuilder (Flush Text) # |
Methods toFlushBuilder :: Flush Text -> Flush Builder #
ToFlushBuilder (Flush Builder) # |
Methods toFlushBuilder :: Flush Builder -> Flush Builder #
ToFlushBuilder (Flush Text) # |
Methods toFlushBuilder :: Flush Text -> Flush Builder #
ToFlushBuilder (Flush Html) # |
Methods toFlushBuilder :: Flush Html -> Flush Builder #

# Mime types

## Data type

type ContentType = ByteString #

typeHtml :: ContentType #

typePlain :: ContentType #

typeJson :: ContentType #

typeXml :: ContentType #

typeAtom :: ContentType #

typeRss :: ContentType #

typeJpeg :: ContentType #

typePng :: ContentType #

typeGif :: ContentType #

typeSvg :: ContentType #

typeJavascript :: ContentType #

typeCss :: ContentType #

typeFlv :: ContentType #

typeOgv :: ContentType #

typeOctet :: ContentType #

# Utilities

simpleContentType :: ContentType -> ContentType #

Removes "extra" information at the end of a content type string. In particular, removes everything after the semicolon, if present.

For example, "text/html; charset=utf-8" is commonly used to specify the character encoding for HTML data. This function would return "text/html".

contentTypeTypes :: ContentType -> (ByteString, ByteString) #

# Evaluation strategy

newtype DontFullyEvaluate a #

Prevents a response body from being fully evaluated before sending the request.

Since 1.1.0

Constructors

DontFullyEvaluate |
Fields unDontFullyEvaluate :: a

Instances

ToTypedContent a => ToTypedContent (DontFullyEvaluate a) # |
Methods toTypedContent :: DontFullyEvaluate a -> TypedContent #
HasContentType a => HasContentType (DontFullyEvaluate a) # |
Methods getContentType :: Monad m => m (DontFullyEvaluate a) -> ContentType #
ToContent a => ToContent (DontFullyEvaluate a) # |
Methods toContent :: DontFullyEvaluate a -> Content #

# Representations

data TypedContent #

Constructors

TypedContent !ContentType !Content |

Instances

ToTypedContent TypedContent # |
Methods toTypedContent :: TypedContent -> TypedContent #
ToContent TypedContent # |
Methods toContent :: TypedContent -> Content #

class ToContent a => ToTypedContent a where #

Any type which can be converted to `TypedContent`.

Since 1.2.0

Minimal complete definition

toTypedContent

Methods

toTypedContent :: a -> TypedContent #

Instances

ToTypedContent () # |
Methods toTypedContent :: () -> TypedContent #
ToTypedContent Text # |
Methods toTypedContent :: Text -> TypedContent #
ToTypedContent Encoding # |
Methods toTypedContent :: Encoding -> TypedContent #
ToTypedContent Value # |
Methods toTypedContent :: Value -> TypedContent #
ToTypedContent Text # |
Methods toTypedContent :: Text -> TypedContent #
ToTypedContent Html # |
Methods toTypedContent :: Html -> TypedContent #
ToTypedContent Css # |
Methods toTypedContent :: Css -> TypedContent #
ToTypedContent Javascript # |
Methods toTypedContent :: Javascript -> TypedContent #
ToTypedContent RepXml # |
Methods toTypedContent :: RepXml -> TypedContent #
ToTypedContent RepPlain # |
Methods toTypedContent :: RepPlain -> TypedContent #
ToTypedContent RepJson # |
Methods toTypedContent :: RepJson -> TypedContent #
ToTypedContent TypedContent # |
Methods toTypedContent :: TypedContent -> TypedContent #
ToTypedContent [Char] # |
Methods toTypedContent :: [Char] -> TypedContent #
ToTypedContent a => ToTypedContent (DontFullyEvaluate a) # |
Methods toTypedContent :: DontFullyEvaluate a -> TypedContent #
ToTypedContent (ContentType, Content) # |
Methods toTypedContent :: (ContentType, Content) -> TypedContent #

class ToTypedContent a => HasContentType a where #

Minimal complete definition

getContentType

Methods

getContentType :: Monad m => m a -> ContentType #

Instances

HasContentType Text # |
Methods getContentType :: Monad m => m Text -> ContentType #
HasContentType Encoding # |
Methods getContentType :: Monad m => m Encoding -> ContentType #
HasContentType Value # |
Methods getContentType :: Monad m => m Value -> ContentType #
HasContentType Text # |
Methods getContentType :: Monad m => m Text -> ContentType #
HasContentType Html # |
Methods getContentType :: Monad m => m Html -> ContentType #
HasContentType Css # |
Methods getContentType :: Monad m => m Css -> ContentType #
HasContentType Javascript # |
Methods getContentType :: Monad m => m Javascript -> ContentType #
HasContentType RepXml # |
Methods getContentType :: Monad m => m RepXml -> ContentType #
HasContentType RepPlain # |
Methods getContentType :: Monad m => m RepPlain -> ContentType #
HasContentType RepJson # |
Methods getContentType :: Monad m => m RepJson -> ContentType #
HasContentType a => HasContentType (DontFullyEvaluate a) # |
Methods getContentType :: Monad m => m (DontFullyEvaluate a) -> ContentType #

## Specific content types

type RepHtml = Html #

Deprecated: Please use Html instead

newtype RepJson #

Constructors

RepJson Content |

Instances

ToTypedContent RepJson # |
Methods toTypedContent :: RepJson -> TypedContent #
HasContentType RepJson # |
Methods getContentType :: Monad m => m RepJson -> ContentType #
ToContent RepJson # |
Methods toContent :: RepJson -> Content #

newtype RepPlain #

Constructors

RepPlain Content |

Instances

ToTypedContent RepPlain # |
Methods toTypedContent :: RepPlain -> TypedContent #
HasContentType RepPlain # |
Methods getContentType :: Monad m => m RepPlain -> ContentType #
ToContent RepPlain # |
Methods toContent :: RepPlain -> Content #

newtype RepXml #

Constructors

RepXml Content |

Instances

ToTypedContent RepXml # |
Methods toTypedContent :: RepXml -> TypedContent #
HasContentType RepXml # |
Methods getContentType :: Monad m => m RepXml -> ContentType #
ToContent RepXml # |
Methods toContent :: RepXml -> Content #

## Smart constructors

repJson :: ToContent a => a -> RepJson #

repPlain :: ToContent a => a -> RepPlain #

repXml :: ToContent a => a -> RepXml #