1import Text.Tabular
2import Text.Html (renderHtml, stringToHtml, (+++))
3
4import qualified Text.Tabular.AsciiArt as A
5import qualified Text.Tabular.SimpleText as S
6import qualified Text.Tabular.Html     as H
7import qualified Text.Tabular.Latex    as L
8import qualified Text.Tabular.Csv      as C
9
10main =
11 do writeFile "sample1.txt"  $ A.render id id id example2
12    writeFile "sample1.tab"  $ S.render "\t" id id id example2
13    writeFile "sample1.html" $ renderHtml $
14      H.css H.defaultCss +++ H.render stringToHtml stringToHtml stringToHtml example2
15    writeFile "sample1T.tex" $ L.render id id id example2
16    writeFile "sample1.csv"  $ C.render id id id example2
17    putStrLn $ "wrote sample1.txt, sample1.html and sample1T.tex"
18    putStrLn $ "(hint: pdflatex sample1)"
19
20-- | an example table showing grouped columns and rows
21sample1 = Table
22  (Group SingleLine
23     [ Group NoLine [Header "A 1", Header "A 2"]
24     , Group NoLine [Header "B 1", Header "B 2", Header "B 3"]
25     ])
26  (Group DoubleLine
27     [ Group SingleLine [Header "memtest 1", Header "memtest 2"]
28     , Group SingleLine [Header "time test 1", Header "time test 2"]
29     ])
30  [ ["hog", "terrible", "slow", "slower"]
31  , ["pig", "not bad",  "fast", "slowest"]
32  , ["good", "awful" ,  "intolerable", "bearable"]
33  , ["better", "no chance", "crawling", "amazing"]
34  , ["meh",  "well...", "worst ever", "ok"]
35  ]
36
37-- | the same example built a slightly different way
38example2 =
39  empty ^..^ colH "memtest 1" ^|^ colH "memtest 2"
40        ^||^ colH "time test" ^|^ colH "time test 2"
41  +.+ row "A 1" ["hog", "terrible", "slow", "slower"]
42  +.+ row "A 2" ["pig", "not bad", "fast", "slowest"]
43  +----+
44      row "B 1" ["good", "awful", "intolerable", "bearable"]
45  +.+ row "B 2" ["better", "no chance", "crawling", "amazing"]
46  +.+ row "B 3" ["meh",  "well...", "worst ever", "ok"]
47