tabular-0.2.2.8: Two-dimensional data tables with rendering functions

Safe Haskell | Safe-Inferred
Language | Haskell2010

Text.Tabular

Contents

- Helper functions for rendering
- Combinators

Description

Synopsis

- data Properties
  - = NoLine
  - | SingleLine
  - | DoubleLine
- data Header h
  - = Header h
  - | Group Properties [Header h]
- data Table rh ch a = Table (Header rh) (Header ch) [[a]]
- headerContents :: Header h -> [h]
- zipHeader :: h -> [h] -> Header a -> Header (h, a)
- flattenHeader :: Header h -> [Either Properties h]
- squish :: (Properties -> b -> b) -> (h -> b) -> Header h -> [b]
- data SemiTable h a = SemiTable (Header h) [a]
- empty :: Table rh ch a
- col :: ch -> [a] -> SemiTable ch a
- colH :: ch -> SemiTable ch a
- row :: rh -> [a] -> SemiTable rh a
- rowH :: rh -> SemiTable rh a
- beside :: Properties -> Table rh ch a -> SemiTable ch a -> Table rh ch a
- below :: Properties -> Table rh ch a -> SemiTable rh a -> Table rh ch a
- (^..^) :: Table rh ch a -> SemiTable ch a -> Table rh ch a
- (^|^) :: Table rh ch a -> SemiTable ch a -> Table rh ch a
- (^||^) :: Table rh ch a -> SemiTable ch a -> Table rh ch a
- (+.+) :: Table rh ch a -> SemiTable rh a -> Table rh ch a
- (+----+) :: Table rh ch a -> SemiTable rh a -> Table rh ch a
- (+====+) :: Table rh ch a -> SemiTable rh a -> Table rh ch a

# Documentation

data Properties Source #

Constructors

NoLine |
SingleLine |
DoubleLine |

#### Instances

Instances details

Show Properties Source # |
Instance details Defined in Text.Tabular Methods showsPrec :: Int -> Properties -> ShowS Source # show :: Properties -> String Source # showList :: [Properties] -> ShowS Source #

data Header h Source #

Constructors

Header h |
Group Properties [Header h] |

#### Instances

Instances details

Functor Header Source # |
Instance details Defined in Text.Tabular Methods fmap :: (a -> b) -> Header a -> Header b Source # (<$) :: a -> Header b -> Header a Source #
Show h => Show (Header h) Source # |
Instance details Defined in Text.Tabular Methods showsPrec :: Int -> Header h -> ShowS Source # show :: Header h -> String Source # showList :: [Header h] -> ShowS Source #

data Table rh ch a Source #

    example = Table
      (Group SingleLine
         [ Group NoLine [Header "A 1", Header "A 2"]
         , Group NoLine [Header "B 1", Header "B 2", Header "B 3"]
         ])
      (Group DoubleLine
         [ Group SingleLine [Header "memtest 1", Header "memtest 2"]
         , Group SingleLine [Header "time test 1", Header "time test 2"]
         ])
      [ ["hog", "terrible", "slow", "slower"]
      , ["pig", "not bad",  "fast", "slowest"]
      , ["good", "awful" ,  "intolerable", "bearable"]
      , ["better", "no chance", "crawling", "amazing"]
      , ["meh",  "well...", "worst ever", "ok"]
      ]

    -- Text.Tabular.AsciiArt.render id id id example
    --
    --     || memtest 1 | memtest 2 ||  time test  | time test 2
    -- ====++===========+===========++=============+============
    -- A 1 ||       hog |  terrible ||        slow |      slower
    -- A 2 ||       pig |   not bad ||        fast |     slowest
    -- ----++-----------+-----------++-------------+------------
    -- B 1 ||      good |     awful || intolerable |    bearable
    -- B 2 ||    better | no chance ||    crawling |     amazing
    -- B 3 ||       meh |   well... ||  worst ever |          ok

Constructors

Table (Header rh) (Header ch) [[a]] |

#### Instances

Instances details

(Show rh, Show ch, Show a) => Show (Table rh ch a) Source # |
Instance details Defined in Text.Tabular Methods showsPrec :: Int -> Table rh ch a -> ShowS Source # show :: Table rh ch a -> String Source # showList :: [Table rh ch a] -> ShowS Source #

# Helper functions for rendering

headerContents :: Header h -> [h] Source #

Retrieve the contents of a header

zipHeader :: h -> [h] -> Header a -> Header (h, a) Source #

`zipHeader` `e` `ss` `h` returns the same structure as `h` except with all the text replaced by the contents of `ss`.

If `ss` has too many cells, the excess is ignored. If it has too few cells, the missing ones (at the end) and replaced with the empty contents `e`

flattenHeader :: Header h -> [Either Properties h] Source #

squish :: (Properties -> b -> b) -> (h -> b) -> Header h -> [b] Source #

The idea is to deal with the fact that Properties (e.g. borders) are not standalone cells but attributes of a cell. A border is just a CSS decoration of a TD element.

squish `decorator f h` applies `f` to every item in the list represented by `h` (see `flattenHeader`), additionally applying `decorator` if the item is followed by some kind of boundary

So `o o o | o o o | o o` gets converted into `O O X O O X O O`

# Combinators

data SemiTable h a Source #

Convenience type for just one row (or column). To be used with combinators as follows:

    example2 =
      empty ^..^ col "memtest 1" [] ^|^ col "memtest 2"   []
            ^||^ col "time test "[] ^|^ col "time test 2" []
      +.+ row "A 1" ["hog", "terrible", "slow", "slower"]
      +.+ row "A 2" ["pig", "not bad", "fast", "slowest"]
      +----+
          row "B 1" ["good", "awful", "intolerable", "bearable"]
      +.+ row "B 2" ["better", "no chance", "crawling", "amazing"]
      +.+ row "B 3" ["meh",  "well...", "worst ever", "ok"]

Constructors

SemiTable (Header h) [a] |

#### Instances

Instances details

(Show h, Show a) => Show (SemiTable h a) Source # |
Instance details Defined in Text.Tabular Methods showsPrec :: Int -> SemiTable h a -> ShowS Source # show :: SemiTable h a -> String Source # showList :: [SemiTable h a] -> ShowS Source #

empty :: Table rh ch a Source #

col :: ch -> [a] -> SemiTable ch a Source #

colH :: ch -> SemiTable ch a Source #

Column header

row :: rh -> [a] -> SemiTable rh a Source #

rowH :: rh -> SemiTable rh a Source #

beside :: Properties -> Table rh ch a -> SemiTable ch a -> Table rh ch a Source #

below :: Properties -> Table rh ch a -> SemiTable rh a -> Table rh ch a Source #

(^..^) :: Table rh ch a -> SemiTable ch a -> Table rh ch a Source #

besides

(^|^) :: Table rh ch a -> SemiTable ch a -> Table rh ch a Source #

besides with a line

(^||^) :: Table rh ch a -> SemiTable ch a -> Table rh ch a Source #

besides with a double line

(+.+) :: Table rh ch a -> SemiTable rh a -> Table rh ch a Source #

below

(+----+) :: Table rh ch a -> SemiTable rh a -> Table rh ch a Source #

below with a line

(+====+) :: Table rh ch a -> SemiTable rh a -> Table rh ch a Source #

below with a double line