lucid-colonnade-1.0.2: Helper functions for using lucid with colonnade
Safe HaskellSafe-Inferred
LanguageHaskell2010

Lucid.Colonnade

Description

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.

Synopsis

Apply

encodeHtmlTable Source #

Arguments

:: (Headedness h, Foldable f, Monoid d) 
=> [Attribute]

Attributes of <table> element

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

encodeCellTable Source #

Arguments

:: (Headedness h, Foldable f, Monoid d) 
=> [Attribute]

Attributes of <table> element

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

encodeCellTableSized Source #

Arguments

:: (Headedness h, Foldable f, Monoid d) 
=> [Attribute]

Attributes of <table> element

-> Colonnade (Sized Int h) a (Cell d)

How to encode data as columns

-> f a

Collection of data

-> Html () 

encodeTable Source #

Arguments

:: forall f h a d c. (Foldable f, Headedness h, Monoid d) 
=> h ([Attribute], [Attribute])

Attributes of <thead> and its <tr>

-> [Attribute]

Attributes of <tbody> element

-> (a -> [Attribute])

Attributes of each <tr> element

-> (([Attribute] -> Html d -> Html d) -> c -> Html d)

Wrap content and convert to Html

-> [Attribute]

Attributes of <table> element

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

data Cell d Source #

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.

Constructors

Cell 

Fields

Instances

Instances details
d ~ () => IsString (Cell d) Source # 
Instance details

Defined in Lucid.Colonnade

Methods

fromString :: String -> Cell d #

Monoid d => Monoid (Cell d) Source # 
Instance details

Defined in Lucid.Colonnade

Methods

mempty :: Cell d #

mappend :: Cell d -> Cell d -> Cell d #

mconcat :: [Cell d] -> Cell d #

Semigroup d => Semigroup (Cell d) Source # 
Instance details

Defined in Lucid.Colonnade

Methods

(<>) :: Cell d -> Cell d -> Cell d #

sconcat :: NonEmpty (Cell d) -> Cell d #

stimes :: Integral b => b -> Cell d -> Cell d #

charCell :: Char -> Cell () Source #

Create a Cell from a Char

htmlCell :: Html d -> Cell d Source #

Create a Cell from a Widget

stringCell :: String -> Cell () Source #

Create a Cell from a String

textCell :: Text -> Cell () Source #

Create a Cell from a Text

lazyTextCell :: Text -> Cell () Source #

Create a Cell from a lazy text

builderCell :: Builder -> Cell () Source #

Create a Cell from a text builder

htmlFromCell :: ([Attribute] -> Html d -> Html d) -> Cell d -> Html d Source #

Convert a Cell to Html by wrapping the content with a tag and applying the Cell attributes to that tag.

encodeBodySized :: (Foldable f, Monoid d) => (a -> [Attribute]) -> [Attribute] -> Colonnade (Sized Int h) a (Cell d) -> f a -> Html () Source #

sectioned Source #

Arguments

:: (Foldable f, Headedness h, Foldable g, Monoid c) 
=> [Attribute]

<table> tag attributes

-> Maybe ([Attribute], [Attribute])

Attributes of <thead> and its <tr>, pass Nothing to omit <thead>

-> [Attribute]

<tbody> tag attributes

-> (a -> [Attribute])

<tr> tag attributes for data rows

-> (b -> Cell c)

Section divider encoding strategy

-> Colonnade h a (Cell c)

Data encoding strategy

-> f (b, g a)

Collection of data

-> Html () 

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.