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

Yesod.Widget

Contents

- Datatype
- Special Hamlet quasiquoter/TH for Widgets
- Convert to Widget
- Creating
  - Head of page
  - Body
  - CSS
  - Javascript
- Utilities

Description

Widgets combine HTML with JS and CSS dependencies with a unique identifier generator, allowing you to create truly modular HTML components.

Synopsis

- type GWidget s m = GGWidget m (GHandler s m)
- newtype GGWidget m monad a = GWidget {
  - unGWidget :: GWInner m monad a
  }
- data PageContent url = PageContent {
  - pageTitle :: Html
  - pageHead :: HtmlUrl url
  - pageBody :: HtmlUrl url
  }
- whamlet :: QuasiQuoter
- whamletFile :: FilePath -> Q Exp
- ihamletToRepHtml :: (Monad mo, RenderMessage master message) => HtmlUrlI18n message (Route master) -> GGHandler sub master mo RepHtml
- class ToWidget sub master a where
  - toWidget :: a -> GWidget sub master ()
- class ToWidgetHead sub master a where
  - toWidgetHead :: a -> GWidget sub master ()
- class ToWidgetBody sub master a where
  - toWidgetBody :: a -> GWidget sub master ()
- setTitle :: Monad m => Html -> GGWidget master m ()
- setTitleI :: (RenderMessage master msg, Monad m) => msg -> GGWidget master (GGHandler sub master m) ()
- addHamletHead :: Monad m => HtmlUrl (Route master) -> GGWidget master m ()
- addHtmlHead :: Monad m => Html -> GGWidget master m ()
- addHamlet :: Monad m => HtmlUrl (Route master) -> GGWidget master m ()
- addHtml :: Monad m => Html -> GGWidget master m ()
- addWidget :: Monad mo => GGWidget m mo () -> GGWidget m mo ()
- addSubWidget :: YesodSubRoute sub master => sub -> GWidget sub master a -> GWidget sub' master a
- addCassius :: Monad m => CssUrl (Route master) -> GGWidget master m ()
- addCassiusMedia :: Monad m => Text -> CssUrl (Route master) -> GGWidget master m ()
- addLucius :: Monad m => CssUrl (Route master) -> GGWidget master m ()
- addLuciusMedia :: Monad m => Text -> CssUrl (Route master) -> GGWidget master m ()
- addStylesheet :: Monad m => Route master -> GGWidget master m ()
- addStylesheetAttrs :: Monad m => Route master -> [(Text, Text)] -> GGWidget master m ()
- addStylesheetRemote :: Monad m => Text -> GGWidget master m ()
- addStylesheetRemoteAttrs :: Monad m => Text -> [(Text, Text)] -> GGWidget master m ()
- addStylesheetEither :: Monad m => Either (Route master) Text -> GGWidget master m ()
- addJulius :: Monad m => JavascriptUrl (Route master) -> GGWidget master m ()
- addJuliusBody :: Monad m => JavascriptUrl (Route master) -> GGWidget master m ()
- addCoffee :: MonadIO m => CoffeeUrl (Route master) -> GGWidget master (GGHandler sub master m) ()
- addCoffeeBody :: MonadIO m => CoffeeUrl (Route master) -> GGWidget master (GGHandler sub master m) ()
- addScript :: Monad m => Route master -> GGWidget master m ()
- addScriptAttrs :: Monad m => Route master -> [(Text, Text)] -> GGWidget master m ()
- addScriptRemote :: Monad m => Text -> GGWidget master m ()
- addScriptRemoteAttrs :: Monad m => Text -> [(Text, Text)] -> GGWidget master m ()
- addScriptEither :: Monad m => Either (Route master) Text -> GGWidget master m ()
- extractBody :: Monad mo => GGWidget m mo () -> GGWidget m mo (HtmlUrl (Route m))

# Datatype

type GWidget s m = GGWidget m (GHandler s m)

newtype GGWidget m monad a

A generic widget, allowing specification of both the subsite and master site datatypes. This is basically a large `WriterT` stack keeping track of dependencies along with a `StateT` to track unique identifiers.

Constructors

GWidget |

Fields

unGWidget :: GWInner m monad a

Instances

ToWidget sub master (GWidget sub master ()) |
MonadBase b m => MonadBase b (GGWidget master m) |
MonadBaseControl b m => MonadBaseControl b (GGWidget master m) |
MonadTrans (GGWidget m) |
MonadTransControl (GGWidget master) |
Monad monad => Monad (GGWidget m monad) |
Functor monad => Functor (GGWidget m monad) |
Applicative monad => Applicative (GGWidget m monad) |
MonadIO monad => MonadIO (GGWidget m monad) |
(a ~ (), Monad monad) => Monoid (GGWidget master monad a) |

data PageContent url

Content for a web page. By providing this datatype, we can easily create generic site templates, which would have the type signature:

     PageContent url -> HtmlUrl url

Constructors

PageContent |

Fields

pageTitle :: Html
pageHead :: HtmlUrl url
pageBody :: HtmlUrl url

# Special Hamlet quasiquoter/TH for Widgets

whamlet :: QuasiQuoter

whamletFile :: FilePath -> Q Exp

ihamletToRepHtml :: (Monad mo, RenderMessage master message) => HtmlUrlI18n message (Route master) -> GGHandler sub master mo RepHtml

Wraps the `Content` generated by `hamletToContent` in a `RepHtml`.

# Convert to Widget

class ToWidget sub master a where

Methods

toWidget :: a -> GWidget sub master ()

Instances

ToWidget sub master Html |
render ~ RY master => ToWidget sub master (render -> Coffeescript) |
render ~ RY master => ToWidget sub master (render -> Javascript) |
render ~ RY master => ToWidget sub master (render -> Css) |
render ~ RY master => ToWidget sub master (render -> Html) |
ToWidget sub master (GWidget sub master ()) |

class ToWidgetHead sub master a where

Methods

toWidgetHead :: a -> GWidget sub master ()

Instances

ToWidgetHead sub master Html |
render ~ RY master => ToWidgetHead sub master (render -> Coffeescript) |
render ~ RY master => ToWidgetHead sub master (render -> Javascript) |
render ~ RY master => ToWidgetHead sub master (render -> Css) |
render ~ RY master => ToWidgetHead sub master (render -> Html) |

class ToWidgetBody sub master a where

Methods

toWidgetBody :: a -> GWidget sub master ()

Instances

ToWidgetBody sub master Html |
render ~ RY master => ToWidgetBody sub master (render -> Coffeescript) |
render ~ RY master => ToWidgetBody sub master (render -> Javascript) |
render ~ RY master => ToWidgetBody sub master (render -> Html) |

# Creating

## Head of page

setTitle :: Monad m => Html -> GGWidget master m ()

Set the page title. Calling `setTitle` multiple times overrides previously set values.

setTitleI :: (RenderMessage master msg, Monad m) => msg -> GGWidget master (GGHandler sub master m) ()

Set the page title. Calling `setTitle` multiple times overrides previously set values.

addHamletHead :: Monad m => HtmlUrl (Route master) -> GGWidget master m ()

Add a `Hamlet` to the head tag.

addHtmlHead :: Monad m => Html -> GGWidget master m ()

Add a `Html` to the head tag.

## Body

addHamlet :: Monad m => HtmlUrl (Route master) -> GGWidget master m ()

Add a `Hamlet` to the body tag.

addHtml :: Monad m => Html -> GGWidget master m ()

Add a `Html` to the body tag.

addWidget :: Monad mo => GGWidget m mo () -> GGWidget m mo ()

Add another widget. This is defined as `id`, by can help with types, and makes widget blocks look more consistent.

addSubWidget :: YesodSubRoute sub master => sub -> GWidget sub master a -> GWidget sub' master a

## CSS

addCassius :: Monad m => CssUrl (Route master) -> GGWidget master m ()

Add some raw CSS to the style tag. Applies to all media types.

addCassiusMedia :: Monad m => Text -> CssUrl (Route master) -> GGWidget master m ()

Add some raw CSS to the style tag, for a specific media type.

addLucius :: Monad m => CssUrl (Route master) -> GGWidget master m ()

Identical to `addCassius`.

addLuciusMedia :: Monad m => Text -> CssUrl (Route master) -> GGWidget master m ()

Identical to `addCassiusMedia`.

addStylesheet :: Monad m => Route master -> GGWidget master m ()

Link to the specified local stylesheet.

addStylesheetAttrs :: Monad m => Route master -> [(Text, Text)] -> GGWidget master m ()

Link to the specified local stylesheet.

addStylesheetRemote :: Monad m => Text -> GGWidget master m ()

Link to the specified remote stylesheet.

addStylesheetRemoteAttrs :: Monad m => Text -> [(Text, Text)] -> GGWidget master m ()

Link to the specified remote stylesheet.

addStylesheetEither :: Monad m => Either (Route master) Text -> GGWidget master m ()

## Javascript

addJulius :: Monad m => JavascriptUrl (Route master) -> GGWidget master m ()

Include raw Javascript in the page's script tag.

addJuliusBody :: Monad m => JavascriptUrl (Route master) -> GGWidget master m ()

Add a new script tag to the body with the contents of this `Julius` template.

addCoffee :: MonadIO m => CoffeeUrl (Route master) -> GGWidget master (GGHandler sub master m) ()

Add Coffesscript to the page's script tag. Requires the coffeescript executable to be present at runtime.

addCoffeeBody :: MonadIO m => CoffeeUrl (Route master) -> GGWidget master (GGHandler sub master m) ()

Add a new script tag to the body with the contents of this Coffesscript template. Requires the coffeescript executable to be present at runtime.

addScript :: Monad m => Route master -> GGWidget master m ()

Link to the specified local script.

addScriptAttrs :: Monad m => Route master -> [(Text, Text)] -> GGWidget master m ()

Link to the specified local script.

addScriptRemote :: Monad m => Text -> GGWidget master m ()

Link to the specified remote script.

addScriptRemoteAttrs :: Monad m => Text -> [(Text, Text)] -> GGWidget master m ()

Link to the specified remote script.

addScriptEither :: Monad m => Either (Route master) Text -> GGWidget master m ()

# Utilities

extractBody :: Monad mo => GGWidget m mo () -> GGWidget m mo (HtmlUrl (Route m))

Pull out the HTML tag contents and return it. Useful for performing some manipulations. It can be easier to use this sometimes than `wrapWidget`.