File: SimpleText.hs

package info (click to toggle)
haskell-tabular 0.2.2.8-4
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 100 kB
  • sloc: haskell: 307; makefile: 2
file content (35 lines) | stat: -rw-r--r-- 1,069 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
module Text.Tabular.SimpleText where

import Data.List (intersperse, transpose)
import Text.Tabular

render :: String -- ^ delim
       -> (rh -> String)
       -> (ch -> String)
       -> (a -> String)
       -> Table rh ch a
       -> String
render delim fr fc f (Table rh ch cells) =
  unlines $ [ renderColumns delim ch2
            ] ++
            (renderRs $ fmap renderR $ zipHeader [] cells $ fmap fr rh)
 where
  -- ch2 and cell2 include the row and column labels
  ch2 = Group DoubleLine [Header "", fmap fc ch]
  cells2 = headerContents ch2
         : zipWith (\h cs -> h : map f cs) rhStrings cells
  --
  renderR (cs,h) = renderColumns delim $ Group DoubleLine
                    [ Header h
                    , fmap fst $ zipHeader "" (map f cs) ch]
  rhStrings = map fr $ headerContents rh
  renderRs (Header s)   = [s]
  renderRs (Group _ hs) = concatMap renderRs hs

renderColumns :: String
              -> Header String
              -> String
renderColumns delim h =
  concatMap helper $ flattenHeader h
 where
  helper = either (const delim) id