web-page-0.1.0: Monoidally construct web pages

Copyright(c) 2014 Ertugrul Soeylemez
LicenseBSD3
MaintainerErtugrul Soeylemez <ertesx@gmx.de>
Safe HaskellNone
LanguageHaskell2010

Web.Page.Widget

Contents

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.

Synopsis

Page widgets

data Widget k url Source

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 

Fields

_wHead :: Html

Head content.

_wScript :: JStat

Inline scripts.

_wScriptLinks :: Set url

External scripts.

_wSections :: Map k Html

Contents of body sections.

_wStyle :: Css

Stylesheet.

_wStyleLinks :: Set url

External stylesheets.

_wTitle :: Last [Text]

Page title chunks (outermost first).

Instances

Foldable (Widget k) 
(Ord k, Ord url) => Monoid (Widget k url) 
Typeable (* -> * -> *) 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

wHead :: Lens' (Widget k url) Html Source

Lens into a widget's head.

wScript :: Lens' (Widget k url) JStat Source

Lens into a widget's inline script.

wScriptLinks :: Lens' (Widget k url) (Set url) Source

Lens into a widget's external scripts.

wSections :: Lens' (Widget k url) (Map k Html) Source

Lens into a widget's body sections.

wStyle :: Lens' (Widget k url) Css Source

Lens into a widget's inline style.

wStyleLinks :: Lens' (Widget k url) (Set url) Source

Lens into a widget's external styles.

wTitle :: Lens' (Widget k url) (Last [Text]) Source

Lens into a widget's title.