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.Render

Contents

Description

This module provides the functionality to render web pages. This is the process to construct and then render a web page:

  1. Use a writer monad to construct a Widget, which represents a web page component and is usually constructed from multiple smaller components,
  2. use one of the rendering functions to render a widget to a Page, which represents a rendered web page, but still abstracts over the exact set of documents (everything inline or a set of separate documents for markup, script and style),
  3. turn the page into a set of documents that you can deliver to the client, for example by using inlinePage.

The motivation for rendering to separate documents is that most web pages consist of dynamic markup, but the stylesheet and script is mostly static. The way Page works you can have widgets with batteries included and still render to separate documents to utilise the client's cache better.

Helper functions for doing that are defined in this module, but framework-specific support is necessary to make this work.

Synopsis

Rendering pages

data Page Source

Rendered pages. This type supports rendering to multiple documents like an HTML document, as explained above.

If you're running a low-traffic site and don't want to afford the complexity, then you can just include the stylesheets and scripts inline by using the inlinePage function. Except for external script and style URLs this will give you a self-contained document that you can deliver to the client.

The pageHtml field is the function that takes the markup for the script and the style respectively and returns a lazy bytestring that you can send as text/html to the client. The other two fields are the rendered script and stylesheet. The markup is UTF-8-encoded, which you should indicate in the content-type header, if you deliver via HTTP.

Constructors

Page 

Fields

pageHtml :: Html -> Html -> ByteString

Markup document.

pageScript :: Text

Page script.

pageStyle :: Text

Page stylesheet.

renderWidget Source

Arguments

:: Ord k 
=> [k]

Sections to render.

-> ([Text] -> Text)

Title renderer.

-> Widget k Text

Widget to render.

-> Page 

This is the most general rendering function for widgets.

Single document

inlinePage :: Page -> ByteString Source

Render the given page to a single self-contained document, including the script and stylesheet inline.