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

Safe HaskellNone
LanguageHaskell98

Yesod.Core.Widget

Contents

Description

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

Synopsis

Datatype

data WidgetT site m a Source

A generic widget, allowing specification of both the subsite and master site datatypes. While this is simply a WriterT, we define a newtype for better error messages.

Instances

MonadBaseControl b m => MonadBaseControl b (WidgetT site m) Source 
MonadBase b m => MonadBase b (WidgetT site m) Source 
Monad m => MonadReader site (WidgetT site m) Source 
((~) * site' site, (~) (* -> *) IO m, (~) * a ()) => ToWidget site' (WidgetT site m a) Source 
MonadTrans (WidgetT site) Source 
Monad m => Monad (WidgetT site m) Source 
Monad m => Functor (WidgetT site m) Source 
Monad m => Applicative (WidgetT site m) Source 
MonadActive m => MonadActive (WidgetT site m) Source 
MonadThrow m => MonadThrow (WidgetT site m) Source 
MonadCatch m => MonadCatch (WidgetT site m) Source 
MonadMask m => MonadMask (WidgetT site m) Source 
MonadIO m => MonadLogger (WidgetT site m) Source 
MonadIO m => MonadLoggerIO (WidgetT site m) Source 
MonadIO m => MonadIO (WidgetT site m) Source 
(Applicative m, MonadIO m, MonadBase IO m, MonadThrow m) => MonadResource (WidgetT site m) Source 
MonadResourceBase m => MonadWidget (WidgetT site m) Source 
MonadResourceBase m => MonadHandler (WidgetT site m) Source 
(Monad m, (~) * a ()) => IsString (WidgetT site m a) Source

A String can be trivially promoted to a widget.

For example, in a yesod-scaffold site you could use:

getHomeR = do defaultLayout "Widget text"
((~) * a (), Monad m) => Monoid (WidgetT site m a) Source 
((~) * a (), Monad m) => Semigroup (WidgetT site m a) Source 
type HandlerSite (WidgetT site m) = site Source 
type StM (WidgetT site m) a = StM m (a, GWData (Route site)) Source 

data PageContent url Source

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

ihamletToRepHtml :: (MonadHandler m, RenderMessage (HandlerSite m) message) => HtmlUrlI18n message (Route (HandlerSite m)) -> m Html Source

Deprecated: Please use ihamletToHtml instead

Wraps the Content generated by hamletToContent in a RepHtml.

ihamletToHtml :: (MonadHandler m, RenderMessage (HandlerSite m) message) => HtmlUrlI18n message (Route (HandlerSite m)) -> m Html Source

Wraps the Content generated by hamletToContent in a RepHtml.

Since 1.2.1

Convert to Widget

class ToWidget site a where Source

Methods

toWidget :: (MonadWidget m, HandlerSite m ~ site) => a -> m () Source

Instances

ToWidget site Html Source 
ToWidget site Javascript Source 
ToWidget site CssBuilder Source 
ToWidget site Css Source 
(~) * render (RY site) => ToWidget site (render -> Javascript) Source 
(~) * render (RY site) => ToWidget site (render -> CssBuilder) Source 
(~) * render (RY site) => ToWidget site (render -> Css) Source 
(~) * render (RY site) => ToWidget site (render -> Html) Source 
((~) * site' site, (~) (* -> *) IO m, (~) * a ()) => ToWidget site' (WidgetT site m a) Source 

class ToWidgetHead site a where Source

Methods

toWidgetHead :: (MonadWidget m, HandlerSite m ~ site) => a -> m () Source

Instances

ToWidgetHead site Html Source 
ToWidgetHead site Javascript Source 
ToWidgetHead site CssBuilder Source 
ToWidgetHead site Css Source 
(~) * render (RY site) => ToWidgetHead site (render -> Javascript) Source 
(~) * render (RY site) => ToWidgetHead site (render -> CssBuilder) Source 
(~) * render (RY site) => ToWidgetHead site (render -> Css) Source 
(~) * render (RY site) => ToWidgetHead site (render -> Html) Source 

class ToWidgetBody site a where Source

Methods

toWidgetBody :: (MonadWidget m, HandlerSite m ~ site) => a -> m () Source

Instances

ToWidgetBody site Html Source 
ToWidgetBody site Javascript Source 
(~) * render (RY site) => ToWidgetBody site (render -> Javascript) Source 
(~) * render (RY site) => ToWidgetBody site (render -> Html) Source 

class ToWidgetMedia site a where Source

Allows adding some CSS to the page with a specific media type.

Since 1.2

Methods

toWidgetMedia Source

Arguments

:: (MonadWidget m, HandlerSite m ~ site) 
=> Text

media value

-> a 
-> m () 

Add the given content to the page, but only for the given media type.

Since 1.2

Instances

ToWidgetMedia site CssBuilder Source 
ToWidgetMedia site Css Source 
(~) * render (RY site) => ToWidgetMedia site (render -> CssBuilder) Source 
(~) * render (RY site) => ToWidgetMedia site (render -> Css) Source 

Creating

Head of page

setTitle :: MonadWidget m => Html -> m () Source

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

setTitleI :: (MonadWidget m, RenderMessage (HandlerSite m) msg) => msg -> m () Source

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

CSS

addStylesheet :: MonadWidget m => Route (HandlerSite m) -> m () Source

Link to the specified local stylesheet.

addStylesheetAttrs :: MonadWidget m => Route (HandlerSite m) -> [(Text, Text)] -> m () Source

Link to the specified local stylesheet.

addStylesheetRemote :: MonadWidget m => Text -> m () Source

Link to the specified remote stylesheet.

addStylesheetRemoteAttrs :: MonadWidget m => Text -> [(Text, Text)] -> m () Source

Link to the specified remote stylesheet.

newtype CssBuilder Source

Newtype wrapper allowing injection of arbitrary content into CSS.

Usage:

toWidget $ CssBuilder "p { color: red }"

Since: 1.1.3

Constructors

CssBuilder 

Instances

ToWidgetHead site CssBuilder Source 
ToWidgetMedia site CssBuilder Source 
ToWidget site CssBuilder Source 
(~) * render (RY site) => ToWidgetHead site (render -> CssBuilder) Source 
(~) * render (RY site) => ToWidgetMedia site (render -> CssBuilder) Source 
(~) * render (RY site) => ToWidget site (render -> CssBuilder) Source 

Javascript

addScript :: MonadWidget m => Route (HandlerSite m) -> m () Source

Link to the specified local script.

addScriptAttrs :: MonadWidget m => Route (HandlerSite m) -> [(Text, Text)] -> m () Source

Link to the specified local script.

addScriptRemote :: MonadWidget m => Text -> m () Source

Link to the specified remote script.

addScriptRemoteAttrs :: MonadWidget m => Text -> [(Text, Text)] -> m () Source

Link to the specified remote script.

Subsites

widgetToParentWidget :: MonadIO m => WidgetT child IO a -> HandlerT child (HandlerT parent m) (WidgetT parent m a) Source

handlerToWidget :: Monad m => HandlerT site m a -> WidgetT site m a Source

Internal

asWidgetT :: WidgetT site m () -> WidgetT site m () Source