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

Safe Haskell | None
Language | Haskell98

Yesod.Core.Widget

Contents

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

Description

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

Synopsis

- data WidgetT site m a
- data PageContent url = PageContent {
  - pageTitle :: Html
  - pageHead :: HtmlUrl url
  - pageBody :: HtmlUrl url
  }
- whamlet :: QuasiQuoter
- whamletFile :: FilePath -> Q Exp
- ihamletToRepHtml :: (MonadHandler m, RenderMessage (HandlerSite m) message) => HtmlUrlI18n message (Route (HandlerSite m)) -> m Html
- ihamletToHtml :: (MonadHandler m, RenderMessage (HandlerSite m) message) => HtmlUrlI18n message (Route (HandlerSite m)) -> m Html
- class ToWidget site a where
- class ToWidgetHead site a where
- class ToWidgetBody site a where
- class ToWidgetMedia site a where
- setTitle :: MonadWidget m => Html -> m ()
- setTitleI :: (MonadWidget m, RenderMessage (HandlerSite m) msg) => msg -> m ()
- addStylesheet :: MonadWidget m => Route (HandlerSite m) -> m ()
- addStylesheetAttrs :: MonadWidget m => Route (HandlerSite m) -> [(Text, Text)] -> m ()
- addStylesheetRemote :: MonadWidget m => Text -> m ()
- addStylesheetRemoteAttrs :: MonadWidget m => Text -> [(Text, Text)] -> m ()
- addStylesheetEither :: MonadWidget m => Either (Route (HandlerSite m)) Text -> m ()
- newtype CssBuilder = CssBuilder {
  - unCssBuilder :: Builder
  }
- addScript :: MonadWidget m => Route (HandlerSite m) -> m ()
- addScriptAttrs :: MonadWidget m => Route (HandlerSite m) -> [(Text, Text)] -> m ()
- addScriptRemote :: MonadWidget m => Text -> m ()
- addScriptRemoteAttrs :: MonadWidget m => Text -> [(Text, Text)] -> m ()
- addScriptEither :: MonadWidget m => Either (Route (HandlerSite m)) Text -> m ()
- widgetToParentWidget :: MonadIO m => WidgetT child IO a -> HandlerT child (HandlerT parent m) (WidgetT parent m a)
- handlerToWidget :: Monad m => HandlerT site m a -> WidgetT site m a
- whamletFileWithSettings :: HamletSettings -> FilePath -> Q Exp
- asWidgetT :: WidgetT site m () -> WidgetT site m ()

# Datatype

data WidgetT site m a #

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) # |
Associated Types type StM (WidgetT site m :: * -> *) a :: * # Methods liftBaseWith :: (RunInBase (WidgetT site m) b -> b a) -> WidgetT site m a # restoreM :: StM (WidgetT site m) a -> WidgetT site m a #
MonadBase b m => MonadBase b (WidgetT site m) # |
Methods liftBase :: b α -> WidgetT site m α #
Monad m => MonadReader site (WidgetT site m) # |
Methods ask :: WidgetT site m site # local :: (site -> site) -> WidgetT site m a -> WidgetT site m a # reader :: (site -> a) -> WidgetT site m a #
((~) * site' site, (~) (* -> *) IO m, (~) * a ()) => ToWidget site' (WidgetT site m a) # |
Methods toWidget :: (MonadWidget m, (* ~ HandlerSite m) site') => WidgetT site m a -> m () #
MonadTrans (WidgetT site) # |
Methods lift :: Monad m => m a -> WidgetT site m a #
Monad m => Monad (WidgetT site m) # |
Methods (>>=) :: WidgetT site m a -> (a -> WidgetT site m b) -> WidgetT site m b # (>>) :: WidgetT site m a -> WidgetT site m b -> WidgetT site m b # return :: a -> WidgetT site m a # fail :: String -> WidgetT site m a #
Monad m => Functor (WidgetT site m) # |
Methods fmap :: (a -> b) -> WidgetT site m a -> WidgetT site m b # (<$) :: a -> WidgetT site m b -> WidgetT site m a #
Monad m => Applicative (WidgetT site m) # |
Methods pure :: a -> WidgetT site m a # (<*>) :: WidgetT site m (a -> b) -> WidgetT site m a -> WidgetT site m b # (*>) :: WidgetT site m a -> WidgetT site m b -> WidgetT site m b # (<*) :: WidgetT site m a -> WidgetT site m b -> WidgetT site m a #
MonadIO m => MonadIO (WidgetT site m) # |
Methods liftIO :: IO a -> WidgetT site m a #
MonadActive m => MonadActive (WidgetT site m) # |
Methods monadActive :: WidgetT site m Bool #
MonadThrow m => MonadThrow (WidgetT site m) # |
Methods throwM :: Exception e => e -> WidgetT site m a #
MonadCatch m => MonadCatch (WidgetT site m) # |
Methods catch :: Exception e => WidgetT site m a -> (e -> WidgetT site m a) -> WidgetT site m a #
MonadMask m => MonadMask (WidgetT site m) # |
Methods mask :: ((forall a. WidgetT site m a -> WidgetT site m a) -> WidgetT site m b) -> WidgetT site m b # uninterruptibleMask :: ((forall a. WidgetT site m a -> WidgetT site m a) -> WidgetT site m b) -> WidgetT site m b #
MonadIO m => MonadLogger (WidgetT site m) # |
Methods monadLoggerLog :: ToLogStr msg => Loc -> LogSource -> LogLevel -> msg -> WidgetT site m () #
MonadIO m => MonadLoggerIO (WidgetT site m) # |
Methods askLoggerIO :: WidgetT site m (Loc -> LogSource -> LogLevel -> LogStr -> IO ()) #
(MonadIO m, MonadBase IO m, MonadThrow m) => MonadResource (WidgetT site m) # |
Methods liftResourceT :: ResourceT IO a -> WidgetT site m a #
MonadResourceBase m => MonadWidget (WidgetT site m) # |
Methods liftWidgetT :: WidgetT (HandlerSite (WidgetT site m)) IO a -> WidgetT site m a #
MonadResourceBase m => MonadHandler (WidgetT site m) # |
Associated Types type HandlerSite (WidgetT site m :: * -> *) :: * # Methods liftHandlerT :: HandlerT (HandlerSite (WidgetT site m)) IO a -> WidgetT site m a #
(Monad m, (~) * a ()) => IsString (WidgetT site m a) # | A `String` can be trivially promoted to a widget. For example, in a yesod-scaffold site you could use:
    getHomeR = do defaultLayout "Widget text"
Methods fromString :: String -> WidgetT site m a #
((~) * a (), Monad m) => Semigroup (WidgetT site m a) # |
Methods (<>) :: WidgetT site m a -> WidgetT site m a -> WidgetT site m a # sconcat :: NonEmpty (WidgetT site m a) -> WidgetT site m a # stimes :: Integral b => b -> WidgetT site m a -> WidgetT site m a #
((~) * a (), Monad m) => Monoid (WidgetT site m a) # |
Methods mempty :: WidgetT site m a # mappend :: WidgetT site m a -> WidgetT site m a -> WidgetT site m a # mconcat :: [WidgetT site m a] -> WidgetT site m a #
type HandlerSite (WidgetT site m) # |
type HandlerSite (WidgetT site m) = site
type StM (WidgetT site m) a # |
type StM (WidgetT site m) a = StM m (a, GWData (Route site))

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 :: (MonadHandler m, RenderMessage (HandlerSite m) message) => HtmlUrlI18n message (Route (HandlerSite m)) -> m Html #

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 #

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

Since 1.2.1

# Convert to Widget

class ToWidget site a where #

Minimal complete definition

toWidget

Methods

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

Instances

ToWidget site Builder # | Since: 1.4.28
Methods toWidget :: (MonadWidget m, (* ~ HandlerSite m) site) => Builder -> m () #
ToWidget site Text # | Since: 1.4.28
Methods toWidget :: (MonadWidget m, (* ~ HandlerSite m) site) => Text -> m () #
ToWidget site Text # | Since: 1.4.28
Methods toWidget :: (MonadWidget m, (* ~ HandlerSite m) site) => Text -> m () #
ToWidget site Html # |
Methods toWidget :: (MonadWidget m, (* ~ HandlerSite m) site) => Html -> m () #
ToWidget site Javascript # |
Methods toWidget :: (MonadWidget m, (* ~ HandlerSite m) site) => Javascript -> m () #
ToWidget site CssBuilder # |
Methods toWidget :: (MonadWidget m, (* ~ HandlerSite m) site) => CssBuilder -> m () #
ToWidget site Css # |
Methods toWidget :: (MonadWidget m, (* ~ HandlerSite m) site) => Css -> m () #
(~) * render (RY site) => ToWidget site (render -> Javascript) # |
Methods toWidget :: (MonadWidget m, (* ~ HandlerSite m) site) => (render -> Javascript) -> m () #
(~) * render (RY site) => ToWidget site (render -> CssBuilder) # |
Methods toWidget :: (MonadWidget m, (* ~ HandlerSite m) site) => (render -> CssBuilder) -> m () #
(~) * render (RY site) => ToWidget site (render -> Css) # |
Methods toWidget :: (MonadWidget m, (* ~ HandlerSite m) site) => (render -> Css) -> m () #
(~) * render (RY site) => ToWidget site (render -> Html) # |
Methods toWidget :: (MonadWidget m, (* ~ HandlerSite m) site) => (render -> Html) -> m () #
((~) * site' site, (~) (* -> *) IO m, (~) * a ()) => ToWidget site' (WidgetT site m a) # |
Methods toWidget :: (MonadWidget m, (* ~ HandlerSite m) site') => WidgetT site m a -> m () #

class ToWidgetHead site a where #

Minimal complete definition

toWidgetHead

Methods

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

Instances

ToWidgetHead site Html # |
Methods toWidgetHead :: (MonadWidget m, (* ~ HandlerSite m) site) => Html -> m () #
ToWidgetHead site Javascript # |
Methods toWidgetHead :: (MonadWidget m, (* ~ HandlerSite m) site) => Javascript -> m () #
ToWidgetHead site CssBuilder # |
Methods toWidgetHead :: (MonadWidget m, (* ~ HandlerSite m) site) => CssBuilder -> m () #
ToWidgetHead site Css # |
Methods toWidgetHead :: (MonadWidget m, (* ~ HandlerSite m) site) => Css -> m () #
(~) * render (RY site) => ToWidgetHead site (render -> Javascript) # |
Methods toWidgetHead :: (MonadWidget m, (* ~ HandlerSite m) site) => (render -> Javascript) -> m () #
(~) * render (RY site) => ToWidgetHead site (render -> CssBuilder) # |
Methods toWidgetHead :: (MonadWidget m, (* ~ HandlerSite m) site) => (render -> CssBuilder) -> m () #
(~) * render (RY site) => ToWidgetHead site (render -> Css) # |
Methods toWidgetHead :: (MonadWidget m, (* ~ HandlerSite m) site) => (render -> Css) -> m () #
(~) * render (RY site) => ToWidgetHead site (render -> Html) # |
Methods toWidgetHead :: (MonadWidget m, (* ~ HandlerSite m) site) => (render -> Html) -> m () #

class ToWidgetBody site a where #

Minimal complete definition

toWidgetBody

Methods

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

Instances

ToWidgetBody site Html # |
Methods toWidgetBody :: (MonadWidget m, (* ~ HandlerSite m) site) => Html -> m () #
ToWidgetBody site Javascript # |
Methods toWidgetBody :: (MonadWidget m, (* ~ HandlerSite m) site) => Javascript -> m () #
(~) * render (RY site) => ToWidgetBody site (render -> Javascript) # |
Methods toWidgetBody :: (MonadWidget m, (* ~ HandlerSite m) site) => (render -> Javascript) -> m () #
(~) * render (RY site) => ToWidgetBody site (render -> Html) # |
Methods toWidgetBody :: (MonadWidget m, (* ~ HandlerSite m) site) => (render -> Html) -> m () #

class ToWidgetMedia site a where #

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

Since 1.2

Minimal complete definition

toWidgetMedia

Methods

toWidgetMedia :: (MonadWidget m, HandlerSite m ~ site) => Text -> a -> m () #

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

Since 1.2

Instances

ToWidgetMedia site CssBuilder # |
Methods toWidgetMedia :: (MonadWidget m, (* ~ HandlerSite m) site) => Text -> CssBuilder -> m () #
ToWidgetMedia site Css # |
Methods toWidgetMedia :: (MonadWidget m, (* ~ HandlerSite m) site) => Text -> Css -> m () #
(~) * render (RY site) => ToWidgetMedia site (render -> CssBuilder) # |
Methods toWidgetMedia :: (MonadWidget m, (* ~ HandlerSite m) site) => Text -> (render -> CssBuilder) -> m () #
(~) * render (RY site) => ToWidgetMedia site (render -> Css) # |
Methods toWidgetMedia :: (MonadWidget m, (* ~ HandlerSite m) site) => Text -> (render -> Css) -> m () #

# Creating

## Head of page

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

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

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

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

## CSS

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

Link to the specified local stylesheet.

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

Link to the specified local stylesheet.

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

Link to the specified remote stylesheet.

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

Link to the specified remote stylesheet.

addStylesheetEither :: MonadWidget m => Either (Route (HandlerSite m)) Text -> m () #

newtype CssBuilder #

Newtype wrapper allowing injection of arbitrary content into CSS.

Usage:

    toWidget $ CssBuilder "p { color: red }"

Since: 1.1.3

Constructors

CssBuilder |
Fields unCssBuilder :: Builder

Instances

ToWidgetHead site CssBuilder # |
Methods toWidgetHead :: (MonadWidget m, (* ~ HandlerSite m) site) => CssBuilder -> m () #
ToWidgetMedia site CssBuilder # |
Methods toWidgetMedia :: (MonadWidget m, (* ~ HandlerSite m) site) => Text -> CssBuilder -> m () #
ToWidget site CssBuilder # |
Methods toWidget :: (MonadWidget m, (* ~ HandlerSite m) site) => CssBuilder -> m () #
(~) * render (RY site) => ToWidgetHead site (render -> CssBuilder) # |
Methods toWidgetHead :: (MonadWidget m, (* ~ HandlerSite m) site) => (render -> CssBuilder) -> m () #
(~) * render (RY site) => ToWidgetMedia site (render -> CssBuilder) # |
Methods toWidgetMedia :: (MonadWidget m, (* ~ HandlerSite m) site) => Text -> (render -> CssBuilder) -> m () #
(~) * render (RY site) => ToWidget site (render -> CssBuilder) # |
Methods toWidget :: (MonadWidget m, (* ~ HandlerSite m) site) => (render -> CssBuilder) -> m () #

## Javascript

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

Link to the specified local script.

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

Link to the specified local script.

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

Link to the specified remote script.

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

Link to the specified remote script.

addScriptEither :: MonadWidget m => Either (Route (HandlerSite m)) Text -> m () #

# Subsites

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

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

# Internal

whamletFileWithSettings :: HamletSettings -> FilePath -> Q Exp #

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