Safe Haskell | None |
---|---|
Language | Haskell2010 |
Build HTML tables using lucid
and colonnade
. It is
recommended that users read the documentation for colonnade
first,
since this library builds on the abstractions introduced there.
Also, look at the docs for blaze-colonnade
. These two
libraries are similar, but blaze offers an HTML pretty printer
which makes it possible to doctest examples. Since lucid
does not offer such facilities, examples are omitted here.
- encodeHtmlTable :: (Headedness h, Foldable f, Monoid d) => [Attribute] -> Colonnade h a (Html d) -> f a -> Html d
- encodeCellTable :: (Headedness h, Foldable f, Monoid d) => [Attribute] -> Colonnade h a (Cell d) -> f a -> Html d
- encodeTable :: forall f h a d c. (Foldable f, Headedness h, Monoid d) => h ([Attribute], [Attribute]) -> [Attribute] -> (a -> [Attribute]) -> (([Attribute] -> Html d -> Html d) -> c -> Html d) -> [Attribute] -> Colonnade h a c -> f a -> Html d
- data Cell d = Cell {
- cellAttribute :: ![Attribute]
- cellHtml :: !(Html d)
- htmlCell :: Html d -> Cell d
- stringCell :: String -> Cell ()
- textCell :: Text -> Cell ()
- lazyTextCell :: Text -> Cell ()
- builderCell :: Builder -> Cell ()
- htmlFromCell :: ([Attribute] -> Html d -> Html d) -> Cell d -> Html d
Apply
:: (Headedness h, Foldable f, Monoid d) | |
=> [Attribute] | Attributes of |
-> Colonnade h a (Html d) | How to encode data as columns |
-> f a | Collection of data |
-> Html d |
Encode a table. Table cell element do not have any attributes applied to them.
:: (Headedness h, Foldable f, Monoid d) | |
=> [Attribute] | Attributes of |
-> Colonnade h a (Cell d) | How to encode data as columns |
-> f a | Collection of data |
-> Html d |
Encode a table. Table cells may have attributes applied to them
:: (Foldable f, Headedness h, Monoid d) | |
=> h ([Attribute], [Attribute]) | Attributes of |
-> [Attribute] | Attributes of |
-> (a -> [Attribute]) | Attributes of each |
-> (([Attribute] -> Html d -> Html d) -> c -> Html d) | Wrap content and convert to |
-> [Attribute] | Attributes of |
-> Colonnade h a c | How to encode data as a row |
-> f a | Collection of data |
-> Html d |
Encode a table. This handles a very general case and
is seldom needed by users. One of the arguments provided is
used to add attributes to the generated <tr>
elements.
The elements of type d
produced by generating html are
strictly combined with their monoidal append function.
However, this type is nearly always ()
.
Cell
The Cell
type is used to build a Colonnade
that
has Html
content inside table cells and may optionally
have attributes added to the <td>
or <th>
elements
that wrap this HTML content.
The attributes that will be applied to a <td>
and
the HTML content that will go inside it. When using
this type, remember that Attribute
, defined in blaze-markup
,
is actually a collection of attributes, not a single attribute.
Cell | |
|
Discussion
In this module, some of the functions for applying a Colonnade
to
some values to build a table have roughly this type signature:
Foldable a => Colonnade Headedness a (Cell d) -> f a -> Html d
The Colonnade
content type is Cell
, but the content
type of the result is Html
. It may not be immidiately clear why
this is done. Another strategy, which this library also
uses, is to write
these functions to take a Colonnade
whose content is Html
:
Foldable a => Colonnade Headedness a (Html d) -> f a -> Html d
When the Colonnade
content type is Html
, then the header
content is rendered as the child of a <th>
and the row
content the child of a <td>
. However, it is not possible
to add attributes to these parent elements. To accomodate this
situation, it is necessary to introduce Cell
, which includes
the possibility of attributes on the parent node.