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

Safe Haskell | None

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
  - 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 !(Source (ResourceT IO) (Flush Builder)) |
ContentFile !FilePath !(Maybe FilePart) |
ContentDontEvaluate !Content |

Instances

IsString Content |
ToContent Content |
ToTypedContent (ContentType, Content) |
ToContent (ContentType, 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.

Methods

toContent :: a -> Content

Instances

ToContent String |
ToContent () |
ToContent ByteString |
ToContent Text |
ToContent Value |
ToContent ByteString |
ToContent Text |
ToContent Builder |
ToContent Html |
ToContent RepXml |
ToContent RepPlain |
ToContent RepJson |
ToContent TypedContent |
ToContent Content |
ToContent a => ToContent (DontFullyEvaluate a) |
ToContent (ContentType, Content) |
ToFlushBuilder builder => ToContent (Source (ResourceT IO) builder) |
ToFlushBuilder builder => ToContent (ResumableSource (ResourceT IO) builder) |

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

ToFlushBuilder String |
ToFlushBuilder ByteString |
ToFlushBuilder Text |
ToFlushBuilder ByteString |
ToFlushBuilder Text |
ToFlushBuilder Builder |
ToFlushBuilder Html |
ToFlushBuilder (Flush String) |
ToFlushBuilder (Flush ByteString) |
ToFlushBuilder (Flush Text) |
ToFlushBuilder (Flush ByteString) |
ToFlushBuilder (Flush Text) |
ToFlushBuilder (Flush Builder) |
ToFlushBuilder (Flush Html) |

# 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) |
HasContentType a => HasContentType (DontFullyEvaluate a) |
ToContent a => ToContent (DontFullyEvaluate a) |

# Representations

data TypedContent

Constructors

TypedContent !ContentType !Content |

Instances

ToTypedContent TypedContent |
ToContent TypedContent |

class ToContent a => ToTypedContent a where

Any type which can be converted to `TypedContent`.

Since 1.2.0

Methods

toTypedContent :: a -> TypedContent

Instances

ToTypedContent () |
ToTypedContent Text |
ToTypedContent Value |
ToTypedContent Text |
ToTypedContent Html |
ToTypedContent RepXml |
ToTypedContent RepPlain |
ToTypedContent RepJson |
ToTypedContent TypedContent |
ToTypedContent [Char] |
ToTypedContent a => ToTypedContent (DontFullyEvaluate a) |
ToTypedContent (ContentType, Content) |

class ToTypedContent a => HasContentType a where

Methods

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

Instances

HasContentType Text |
HasContentType Value |
HasContentType Text |
HasContentType Html |
HasContentType RepXml |
HasContentType RepPlain |
HasContentType RepJson |
HasContentType a => HasContentType (DontFullyEvaluate a) |

## Specific content types

type RepHtml = Html

newtype RepJson

Constructors

RepJson Content |

Instances

ToTypedContent RepJson |
HasContentType RepJson |
ToContent RepJson |

newtype RepPlain

Constructors

RepPlain Content |

Instances

ToTypedContent RepPlain |
HasContentType RepPlain |
ToContent RepPlain |

newtype RepXml

Constructors

RepXml Content |

Instances

ToTypedContent RepXml |
HasContentType RepXml |
ToContent RepXml |

## Smart constructors

repJson :: ToContent a => a -> RepJson

repPlain :: ToContent a => a -> RepPlain

repXml :: ToContent a => a -> RepXml