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

Safe Haskell | None
Language | Haskell2010

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 !(ConduitT () (Flush Builder) (ResourceT IO) ())
  - | ContentFile !FilePath !(Maybe FilePart)
  - | ContentDontEvaluate !Content
- emptyContent :: Content
- class ToContent a where
  - toContent :: a -> Content
- class ToFlushBuilder a where
  - toFlushBuilder :: a -> Flush Builder
- 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
  - toTypedContent :: a -> TypedContent
- class ToTypedContent a => HasContentType a where
  - getContentType :: Monad m => m a -> ContentType
- 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 !(ConduitT () (Flush Builder) (ResourceT IO) ()) |
ContentFile !FilePath !(Maybe FilePart) |
ContentDontEvaluate !Content |

#### Instances

Instances details

IsString Content # |
Instance details Defined in Yesod.Core.Types Methods fromString :: String -> Content #
ToContent Content # |
Instance details Defined in Yesod.Core.Content Methods toContent :: Content -> Content #
ToContent (ContentType, Content) # |
Instance details Defined in Yesod.Core.Content Methods toContent :: (ContentType, Content) -> Content #
ToTypedContent (ContentType, Content) # |
Instance details Defined in Yesod.Core.Content Methods toTypedContent :: (ContentType, Content) -> TypedContent #

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.

Methods

toContent :: a -> Content #

#### Instances

Instances details

ToContent Encoding # |
Instance details Defined in Yesod.Core.Content Methods toContent :: Encoding -> Content #
ToContent Value # |
Instance details Defined in Yesod.Core.Content Methods toContent :: Value -> Content #
ToContent Html # |
Instance details Defined in Yesod.Core.Content Methods toContent :: Html -> Content #
ToContent Builder # |
Instance details Defined in Yesod.Core.Content Methods toContent :: Builder -> Content #
ToContent ByteString # |
Instance details Defined in Yesod.Core.Content Methods toContent :: ByteString -> Content #
ToContent ByteString # |
Instance details Defined in Yesod.Core.Content Methods toContent :: ByteString -> Content #
ToContent Void # |
Instance details Defined in Yesod.Core.Content Methods toContent :: Void -> Content #
ToContent Css # |
Instance details Defined in Yesod.Core.Content Methods toContent :: Css -> Content #
ToContent Javascript # |
Instance details Defined in Yesod.Core.Content Methods toContent :: Javascript -> Content #
ToContent Text # |
Instance details Defined in Yesod.Core.Content Methods toContent :: Text -> Content #
ToContent Text # |
Instance details Defined in Yesod.Core.Content Methods toContent :: Text -> Content #
ToContent Content # |
Instance details Defined in Yesod.Core.Content Methods toContent :: Content -> Content #
ToContent RepJson # |
Instance details Defined in Yesod.Core.Content Methods toContent :: RepJson -> Content #
ToContent RepPlain # |
Instance details Defined in Yesod.Core.Content Methods toContent :: RepPlain -> Content #
ToContent RepXml # |
Instance details Defined in Yesod.Core.Content Methods toContent :: RepXml -> Content #
ToContent TypedContent # |
Instance details Defined in Yesod.Core.Content Methods toContent :: TypedContent -> Content #
ToContent String # |
Instance details Defined in Yesod.Core.Content Methods toContent :: String -> Content #
ToContent () # |
Instance details Defined in Yesod.Core.Content Methods toContent :: () -> Content #
ToContent a => ToContent (DontFullyEvaluate a) # |
Instance details Defined in Yesod.Core.Content Methods toContent :: DontFullyEvaluate a -> Content #
ToContent (JSONResponse a) # |
Instance details Defined in Yesod.Core.Content Methods toContent :: JSONResponse a -> Content #
ToContent (ContentType, Content) # |
Instance details Defined in Yesod.Core.Content Methods toContent :: (ContentType, Content) -> Content #
ToFlushBuilder builder => ToContent (ConduitT () builder (ResourceT IO) ()) # |
Instance details Defined in Yesod.Core.Content Methods toContent :: ConduitT () builder (ResourceT IO) () -> Content #
ToFlushBuilder builder => ToContent (SealedConduitT () builder (ResourceT IO) ()) # |
Instance details Defined in Yesod.Core.Content Methods toContent :: SealedConduitT () builder (ResourceT IO) () -> Content #
ToFlushBuilder builder => ToContent (Pipe () () builder () (ResourceT IO) ()) # |
Instance details Defined in Yesod.Core.Content 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

Methods

toFlushBuilder :: a -> Flush Builder #

#### Instances

Instances details

ToFlushBuilder Html # |
Instance details Defined in Yesod.Core.Content Methods toFlushBuilder :: Html -> Flush Builder #
ToFlushBuilder Builder # |
Instance details Defined in Yesod.Core.Content Methods toFlushBuilder :: Builder -> Flush Builder #
ToFlushBuilder ByteString # |
Instance details Defined in Yesod.Core.Content Methods toFlushBuilder :: ByteString -> Flush Builder #
ToFlushBuilder ByteString # |
Instance details Defined in Yesod.Core.Content Methods toFlushBuilder :: ByteString -> Flush Builder #
ToFlushBuilder Text # |
Instance details Defined in Yesod.Core.Content Methods toFlushBuilder :: Text -> Flush Builder #
ToFlushBuilder Text # |
Instance details Defined in Yesod.Core.Content Methods toFlushBuilder :: Text -> Flush Builder #
ToFlushBuilder String # |
Instance details Defined in Yesod.Core.Content Methods toFlushBuilder :: String -> Flush Builder #
ToFlushBuilder (Flush Html) # |
Instance details Defined in Yesod.Core.Content Methods toFlushBuilder :: Flush Html -> Flush Builder #
ToFlushBuilder (Flush Builder) # |
Instance details Defined in Yesod.Core.Content Methods toFlushBuilder :: Flush Builder -> Flush Builder #
ToFlushBuilder (Flush ByteString) # |
Instance details Defined in Yesod.Core.Content Methods toFlushBuilder :: Flush ByteString -> Flush Builder #
ToFlushBuilder (Flush ByteString) # |
Instance details Defined in Yesod.Core.Content Methods toFlushBuilder :: Flush ByteString -> Flush Builder #
ToFlushBuilder (Flush Text) # |
Instance details Defined in Yesod.Core.Content Methods toFlushBuilder :: Flush Text -> Flush Builder #
ToFlushBuilder (Flush Text) # |
Instance details Defined in Yesod.Core.Content Methods toFlushBuilder :: Flush Text -> Flush Builder #
ToFlushBuilder (Flush String) # |
Instance details Defined in Yesod.Core.Content Methods toFlushBuilder :: Flush String -> 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) #

Give just the media types as a pair.

For example, "text/html; charset=utf-8" returns ("text", "html")

# 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

Instances details

HasContentType a => HasContentType (DontFullyEvaluate a) # |
Instance details Defined in Yesod.Core.Content Methods getContentType :: Monad m => m (DontFullyEvaluate a) -> ContentType #
ToContent a => ToContent (DontFullyEvaluate a) # |
Instance details Defined in Yesod.Core.Content Methods toContent :: DontFullyEvaluate a -> Content #
ToTypedContent a => ToTypedContent (DontFullyEvaluate a) # |
Instance details Defined in Yesod.Core.Content Methods toTypedContent :: DontFullyEvaluate a -> TypedContent #

# Representations

data TypedContent #

Constructors

TypedContent !ContentType !Content |

#### Instances

Instances details

ToContent TypedContent # |
Instance details Defined in Yesod.Core.Content Methods toContent :: TypedContent -> Content #
ToTypedContent TypedContent # |
Instance details Defined in Yesod.Core.Content Methods toTypedContent :: TypedContent -> TypedContent #

class ToContent a => ToTypedContent a where #

Any type which can be converted to `TypedContent`.

Since 1.2.0

Methods

toTypedContent :: a -> TypedContent #

#### Instances

Instances details

ToTypedContent Encoding # |
Instance details Defined in Yesod.Core.Content Methods toTypedContent :: Encoding -> TypedContent #
ToTypedContent Value # |
Instance details Defined in Yesod.Core.Content Methods toTypedContent :: Value -> TypedContent #
ToTypedContent Html # |
Instance details Defined in Yesod.Core.Content Methods toTypedContent :: Html -> TypedContent #
ToTypedContent Void # |
Instance details Defined in Yesod.Core.Content Methods toTypedContent :: Void -> TypedContent #
ToTypedContent Css # |
Instance details Defined in Yesod.Core.Content Methods toTypedContent :: Css -> TypedContent #
ToTypedContent Javascript # |
Instance details Defined in Yesod.Core.Content Methods toTypedContent :: Javascript -> TypedContent #
ToTypedContent Text # |
Instance details Defined in Yesod.Core.Content Methods toTypedContent :: Text -> TypedContent #
ToTypedContent Text # |
Instance details Defined in Yesod.Core.Content Methods toTypedContent :: Text -> TypedContent #
ToTypedContent RepJson # |
Instance details Defined in Yesod.Core.Content Methods toTypedContent :: RepJson -> TypedContent #
ToTypedContent RepPlain # |
Instance details Defined in Yesod.Core.Content Methods toTypedContent :: RepPlain -> TypedContent #
ToTypedContent RepXml # |
Instance details Defined in Yesod.Core.Content Methods toTypedContent :: RepXml -> TypedContent #
ToTypedContent TypedContent # |
Instance details Defined in Yesod.Core.Content Methods toTypedContent :: TypedContent -> TypedContent #
ToTypedContent () # |
Instance details Defined in Yesod.Core.Content Methods toTypedContent :: () -> TypedContent #
ToTypedContent a => ToTypedContent (DontFullyEvaluate a) # |
Instance details Defined in Yesod.Core.Content Methods toTypedContent :: DontFullyEvaluate a -> TypedContent #
ToTypedContent (JSONResponse a) # |
Instance details Defined in Yesod.Core.Content Methods toTypedContent :: JSONResponse a -> TypedContent #
ToTypedContent [Char] # |
Instance details Defined in Yesod.Core.Content Methods toTypedContent :: [Char] -> TypedContent #
ToTypedContent (ContentType, Content) # |
Instance details Defined in Yesod.Core.Content Methods toTypedContent :: (ContentType, Content) -> TypedContent #

class ToTypedContent a => HasContentType a where #

Methods

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

#### Instances

Instances details

HasContentType Encoding # |
Instance details Defined in Yesod.Core.Content Methods getContentType :: Monad m => m Encoding -> ContentType #
HasContentType Value # |
Instance details Defined in Yesod.Core.Content Methods getContentType :: Monad m => m Value -> ContentType #
HasContentType Html # |
Instance details Defined in Yesod.Core.Content Methods getContentType :: Monad m => m Html -> ContentType #
HasContentType Css # |
Instance details Defined in Yesod.Core.Content Methods getContentType :: Monad m => m Css -> ContentType #
HasContentType Javascript # |
Instance details Defined in Yesod.Core.Content Methods getContentType :: Monad m => m Javascript -> ContentType #
HasContentType Text # |
Instance details Defined in Yesod.Core.Content Methods getContentType :: Monad m => m Text -> ContentType #
HasContentType Text # |
Instance details Defined in Yesod.Core.Content Methods getContentType :: Monad m => m Text -> ContentType #
HasContentType RepJson # |
Instance details Defined in Yesod.Core.Content Methods getContentType :: Monad m => m RepJson -> ContentType #
HasContentType RepPlain # |
Instance details Defined in Yesod.Core.Content Methods getContentType :: Monad m => m RepPlain -> ContentType #
HasContentType RepXml # |
Instance details Defined in Yesod.Core.Content Methods getContentType :: Monad m => m RepXml -> ContentType #
HasContentType a => HasContentType (DontFullyEvaluate a) # |
Instance details Defined in Yesod.Core.Content Methods getContentType :: Monad m => m (DontFullyEvaluate a) -> ContentType #
HasContentType (JSONResponse a) # |
Instance details Defined in Yesod.Core.Content Methods getContentType :: Monad m => m (JSONResponse a) -> ContentType #

## Specific content types

type RepHtml = Html #

Deprecated: Please use Html instead

newtype RepJson #

Constructors

RepJson Content |

#### Instances

Instances details

HasContentType RepJson # |
Instance details Defined in Yesod.Core.Content Methods getContentType :: Monad m => m RepJson -> ContentType #
ToContent RepJson # |
Instance details Defined in Yesod.Core.Content Methods toContent :: RepJson -> Content #
ToTypedContent RepJson # |
Instance details Defined in Yesod.Core.Content Methods toTypedContent :: RepJson -> TypedContent #

newtype RepPlain #

Constructors

RepPlain Content |

#### Instances

Instances details

HasContentType RepPlain # |
Instance details Defined in Yesod.Core.Content Methods getContentType :: Monad m => m RepPlain -> ContentType #
ToContent RepPlain # |
Instance details Defined in Yesod.Core.Content Methods toContent :: RepPlain -> Content #
ToTypedContent RepPlain # |
Instance details Defined in Yesod.Core.Content Methods toTypedContent :: RepPlain -> TypedContent #

newtype RepXml #

Constructors

RepXml Content |

#### Instances

Instances details

HasContentType RepXml # |
Instance details Defined in Yesod.Core.Content Methods getContentType :: Monad m => m RepXml -> ContentType #
ToContent RepXml # |
Instance details Defined in Yesod.Core.Content Methods toContent :: RepXml -> Content #
ToTypedContent RepXml # |
Instance details Defined in Yesod.Core.Content Methods toTypedContent :: RepXml -> TypedContent #

## Smart constructors

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

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

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