| Copyright | (c) 2014 Ertugrul Soeylemez |
|---|---|
| License | BSD3 |
| Maintainer | Ertugrul Soeylemez <ertesx@gmx.de> |
| Safe Haskell | None |
| Language | Haskell2010 |
Web.Page.Widget
Description
A widget is a self-contained web page component represented by the
Widget type. This type is a family of monoids, so you can use it
together with a writer monad.
- data Widget k url = Widget {}
- type MonadWidget k url = MonadWriter (Widget k url)
- type WidgetWriter k url a = forall m. MonadWidget k url m => m a
- addBody :: MonadWriter (Widget () url) m => Html -> m ()
- addHead :: MonadWriter (Widget k url) m => Html -> m ()
- addScript :: MonadWriter (Widget k url) m => JStat -> m ()
- addScriptLink :: MonadWriter (Widget k url) m => url -> m ()
- addSection :: MonadWriter (Widget k url) m => k -> Html -> m ()
- addStyle :: MonadWriter (Widget k url) m => Css -> m ()
- addStyleLink :: MonadWriter (Widget k url) m => url -> m ()
- setTitle :: MonadWriter (Widget k url) m => Text -> m ()
- withTitle :: MonadWriter (Widget k url) m => Text -> m a -> m a
- wHead :: Lens' (Widget k url) Html
- wScript :: Lens' (Widget k url) JStat
- wScriptLinks :: Lens' (Widget k url) (Set url)
- wSections :: Lens' (Widget k url) (Map k Html)
- wStyle :: Lens' (Widget k url) Css
- wStyleLinks :: Lens' (Widget k url) (Set url)
- wTitle :: Lens' (Widget k url) (Last [Text])
Page widgets
A widget is a self-contained fragment of a web page together with its scripts and styles. This type is inspired by Yesod's widgets, but is supposed to be constructed by using a writer monad and may not denote effects of its own.
To construct widgets through a writer monad, use lens combinators
like scribe and censoring. Alternatively you can use the add*
functions like addSection or addStyle. The title is constructed
by using withTitle and setTitle. This allows you to have a
hierarchy of titles with a site title, a page title and even a
component title.
The first type argument is the key type for the individual body sections of the resulting document. You can use it for example to divide your document into a header, a menu, a content area and a footer and each widget can add to them individually.
The second type argument is the type of URLs. You may use it for type-safe routing.
Constructors
| Widget | |
Widget actions
type MonadWidget k url = MonadWriter (Widget k url) Source
Convenient constraint alias for widget actions.
type WidgetWriter k url a = forall m. MonadWidget k url m => m a Source
Convenient type alias for polymorphic widget actions.
Constructing widgets
addBody :: MonadWriter (Widget () url) m => Html -> m () Source
Construct a widget with the given body. Use this combinator if you don't need sections.
addHead :: MonadWriter (Widget k url) m => Html -> m () Source
Construct a widget with the given head markup.
addScript :: MonadWriter (Widget k url) m => JStat -> m () Source
Construct a widget with the given script.
addScriptLink :: MonadWriter (Widget k url) m => url -> m () Source
Construct a widget with the given script link.
addSection :: MonadWriter (Widget k url) m => k -> Html -> m () Source
Construct a widget with the given body section.
addStyle :: MonadWriter (Widget k url) m => Css -> m () Source
Construct a widget with the given stylesheet.
addStyleLink :: MonadWriter (Widget k url) m => url -> m () Source
Construct a widget with the given style link.
setTitle :: MonadWriter (Widget k url) m => Text -> m () Source
Scribe the title of the widget. Use this function to construct the
lowest level title. For higher level titles use withTitle.
withTitle :: MonadWriter (Widget k url) m => Text -> m a -> m a Source
Prepend the given title chunk to the given widget action.
Conceptually this wraps the given widget in a higher level title.
Use setTitle for the lowest level title.
Widget lenses
wScriptLinks :: Lens' (Widget k url) (Set url) Source
Lens into a widget's external scripts.
wStyleLinks :: Lens' (Widget k url) (Set url) Source
Lens into a widget's external styles.