yesod-media-simple-0.2.0.1: Simple display of media types, served by yesod

Safe HaskellNone
LanguageHaskell98

Yesod.Media.Simple

Contents

Description

Easily serve different media types to the user.

Synopsis

Documentation

serve :: RenderContent a => a -> IO () Source #

Starts a web server which serves the given data to the client. It listens on the port specified by the PORT environment variable. If there is no PORT variable, it defaults to port 3000. This means that the results will be visible at http://localhost:3000. The server responds to any GET request with the results - the route is ignored.

serveHandler :: RenderContent a => LiteHandler a -> IO () Source #

Like serve, but the media to render results from a LiteHandler action. This allows the data to render to be computed within the LiteHandler monad, allowing it to respond particularly to the user's request.

class RenderContent a where Source #

This class defines how to serve different media types to the user.

Minimal complete definition

renderContent

Methods

renderContent :: a -> HandlerT site IO TypedContent Source #

Given some data, computes the TypedContent which should be sent to the client in order to view it.

Instances

RenderContent Jpeg Source # 
RenderContent PixelList Source # 
RenderContent SizedDiagram Source # 
RenderContent a => RenderContent (IO a) Source # 
RenderContent (Image Pixel8) Source # 
RenderContent (Image Pixel16) Source # 
RenderContent (Image PixelYA8) Source # 
RenderContent (Image PixelYA16) Source # 
RenderContent (Image PixelRGB8) Source # 
RenderContent (Image PixelRGB16) Source # 
RenderContent (Image PixelRGBA8) Source # 
RenderContent (Image PixelRGBA16) Source # 
RenderContent (QDiagram Cairo V2 Double Any) Source # 

Diagrams

Cairo is used to render diagrams to pngs.

serveDiagram :: Diagram Cairo -> IO () Source #

A type-specialized version of serve. This is usually preferred to serve because Diagrams tend to be polymorphic - this fixes the input data to be a Diagram Cairo.

data SizedDiagram Source #

SizedDiagram can be used to specify the output size of the diagram when rendering it with Cairo.

Images

The various types of Image from JuicyPixels (Codec.Picture) are servable as pngs, unless the Jpeg wrapper type is used.

data PixelList Source #

This type wraps RGB8 image data stored in nested lists, so that you don't need to use Codec.Picture. The inner list is one row of the image, and the tuple elements are the red green blue values, respectively.

Constructors

PixelList Int Int [[(Word8, Word8, Word8)]] 

data Jpeg Source #

This type wraps image data that is appropriate for JPEG export, along with the requested quality (from 0 to 100).

Constructors

Jpeg Word8 (Image PixelYCbCr8) 

Utilities

imageToDiagramEmb :: (Renderable (DImage (N b) Embedded) b, V b ~ V2, TypeableFloat (N b)) => DynamicImage -> Diagram b Source #

Convert a JuicyPixels Image to an image embedded in the Diagram. Note that this image is *NOT* renderable by the Cairo backend, which is used by other functions in this module.

imageToDiagramExt :: (Renderable (DImage (N b) External) b, V b ~ V2, TypeableFloat (N b)) => DynamicImage -> IO (Diagram b) Source #

Write a JuicyPixels Image to a file in the system temp directory, and create a diagram which references this Image file. Unlike imageToDiagramEmb, this Diagram can be rendered by the Cairo backend.