digestive-functors-heist-0.3.0.0: Heist frontend for the digestive-functors library

Safe HaskellSafe-Infered

Text.Digestive.Heist

Contents

Description

This module provides a Heist frontend for the digestive-functors library.

Disclaimer: this documentation requires very basic familiarity with digestive-functors. You might want to take a quick look at this tutorial first:

https://github.com/jaspervdj/digestive-functors/blob/master/examples/tutorial.lhs

This module exports the functions digestiveSplices and bindDigestiveSplices, and most users will not require anything else.

These splices are used to create HTML for different form elements. This way, the developer doesn't have to care about setting e.g. the previous values in a text field when something goes wrong.

For documentation on the different splices, see the different functions exported by this module. All splices have the same name as given in digestiveSplices.

You can give arbitrary attributes to most of the elements (i.e. where it makes sense). This means you can do e.g.:

 <dfInputTextArea ref="description" cols="20" rows="3" />

Synopsis

Core methods

Splices

dfInputText :: Monad m => View v -> Splice mSource

Generate a text input field. Example:

 <dfInputText ref="user.name" />

dfInputTextArea :: Monad m => View v -> Splice mSource

Generate a text area. Example:

 <dfInputTextArea ref="user.about" />

dfInputPassword :: Monad m => View v -> Splice mSource

Generate a password field. Example:

 <dfInputPassword ref="user.password" />

dfInputHidden :: Monad m => View v -> Splice mSource

Generate a hidden input field. Example:

 <dfInputHidden ref="user.forgery" />

dfInputSelect :: Monad m => View Text -> Splice mSource

Generate a select button (also known as a combo box). Example:

 <dfInputSelect ref="user.sex" />

dfInputRadio :: Monad m => View Text -> Splice mSource

Generate a number of radio buttons. Example:

 <dfInputRadio ref="user.sex" />

dfInputCheckbox :: Monad m => View Text -> Splice mSource

Generate a checkbox. Example:

 <dfInputCheckbox ref="user.married" />

dfInputSubmit :: Monad m => View v -> Splice mSource

Generate a submit button. Example:

 <dfInputSubmit />

dfLabel :: Monad m => View v -> Splice mSource

Generate a label for a field. Example:

 <dfLabel ref="user.married">Married: </dfLabel>
 <dfInputCheckbox ref="user.married" />

dfForm :: Monad m => View v -> Splice mSource

Generate a form tag with the method attribute set to POST and the enctype set to the right value (depending on the form). Example:

 <dfForm action="/users/new">
     <dfInputText ... />
     ...
     <dfInputSubmit />
 </dfForm>

dfErrorList :: Monad m => View Text -> Splice mSource

Display the list of errors for a certain field. Example:

 <dfErrorList ref="user.name" />
 <dfInputText ref="user.name" />

dfChildErrorList :: Monad m => View Text -> Splice mSource

Display the list of errors for a certain form and all forms below it. E.g., if there is a subform called "user":

 <dfChildErrorList ref="user" />

Or display all errors for the form:

 <dfChildErrorList ref="" />

dfSubView :: Monad m => View Text -> Splice mSource

This splice allows reuse of templates by selecting some child of a form tree. While this may sound complicated, it's pretty straightforward and practical. Suppose we have:

 <dfInputText ref="user.name" />
 <dfInputText ref="user.password" />

 <dfInputTextArea ref="comment.body" />

You may want to abstract the "user" parts in some other template so you Don't Repeat Yourself (TM). If you create a template called "user-form" with the following contents:

 <dfInputText ref="name" />
 <dfInputText ref="password" />

You will be able to use:

 <dfSubView ref="user">
     <apply template="user-form" />
 </dfSubView>

 <dfInputTextArea ref="comment.body" />