yesod-core-1.6.28.1: 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 Source #

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 Source # |
Instance details Defined in Yesod.Core.Types Methods fromString :: String -> Content Source #
ToContent Content Source # |
Instance details Defined in Yesod.Core.Content Methods toContent :: Content -> Content Source #
ToContent (ContentType, Content) Source # |
Instance details Defined in Yesod.Core.Content Methods toContent :: (ContentType, Content) -> Content Source #
ToTypedContent (ContentType, Content) Source # |
Instance details Defined in Yesod.Core.Content Methods toTypedContent :: (ContentType, Content) -> TypedContent Source #

emptyContent :: Content Source #

Zero-length enumerator.

class ToContent a where Source #

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 Source #

#### Instances

Instances details

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

class ToFlushBuilder a where Source #

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 Source #

#### Instances

Instances details

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

# Mime types

## Data type

type ContentType = ByteString Source #

typeHtml :: ContentType Source #

typePlain :: ContentType Source #

typeJson :: ContentType Source #

typeXml :: ContentType Source #

typeAtom :: ContentType Source #

typeRss :: ContentType Source #

typeJpeg :: ContentType Source #

typePng :: ContentType Source #

typeGif :: ContentType Source #

typeSvg :: ContentType Source #

typeJavascript :: ContentType Source #

typeCss :: ContentType Source #

typeFlv :: ContentType Source #

typeOgv :: ContentType Source #

typeOctet :: ContentType Source #

# Utilities

simpleContentType :: ContentType -> ContentType Source #

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) Source #

Give just the media types as a pair.

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

# Evaluation strategy

newtype DontFullyEvaluate a Source #

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

# Representations

data TypedContent Source #

Constructors

TypedContent !ContentType !Content |

#### Instances

Instances details

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

class ToContent a => ToTypedContent a where Source #

Any type which can be converted to `TypedContent`.

Since 1.2.0

Methods

toTypedContent :: a -> TypedContent Source #

#### Instances

Instances details

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

class ToTypedContent a => HasContentType a where Source #

Methods

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

#### Instances

Instances details

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

## Specific content types

type RepHtml = Html Source #

Deprecated: Please use Html instead

newtype RepJson Source #

Constructors

RepJson Content |

#### Instances

Instances details

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

newtype RepPlain Source #

Constructors

RepPlain Content |

#### Instances

Instances details

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

newtype RepXml Source #

Constructors

RepXml Content |

#### Instances

Instances details

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

## Smart constructors

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

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

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