1 -----------------------------------------------------------------------------
\r
2 -- TableClass : Class for combinators used in building 2D tables.
\r
4 -- Copyright (c) 1999 Andy Gill
\r
6 -- This module is distributed as Open Source software under the
\r
7 -- Artistic License; see the file "Artistic" that is included
\r
8 -- in the distribution for details.
\r
9 -----------------------------------------------------------------------------
\r
20 {----------------------------------------------------------------------------
\r
21 These combinators can be used to build formated 2D tables.
\r
22 The specific target useage is for HTML table generation.
\r
23 ----------------------------------------------------------------------------
\r
27 > table1 :: (Table t) => t String
\r
28 > table1 = single "Hello" +-----+
\r
30 This is a 1x1 cell +-----+
\r
31 Note: single has type
\r
33 single :: (Table t) => a -> t a
\r
35 So the cells can contain anything.
\r
37 > table2 :: (Table t) => t String
\r
38 > table2 = single "World" +-----+
\r
43 > table3 :: (Table t) => t String
\r
44 > table3 = table1 %-% table2 +-----%-----+
\r
46 % is used to indicate +-----%-----+
\r
47 the join edge between
\r
50 > table4 :: (Table t) => t String
\r
51 > table4 = table3 %/% table2 +-----+-----+
\r
53 Notice the padding on the %%%%%%%%%%%%%
\r
54 smaller (bottom) cell to |World |
\r
55 force the table to be a +-----------+
\r
58 > table5 :: (Table t) => t String
\r
59 > table5 = table1 %-% table4 +-----%-----+-----+
\r
61 Notice the padding on the | %-----+-----+
\r
62 leftmost cell, again to | %World |
\r
63 force the table to be a +-----%-----------+
\r
66 Now the table can be rendered with processTable, for example:
\r
67 Main> processTable table5
\r
71 [("World",(2,1))]] :: [[([Char],(Int,Int))]]
\r
74 ----------------------------------------------------------------------------}
\r
77 -- There are no empty tables
\r
79 --Single element table
\r
81 -- horizontal composition
\r
82 beside :: t a -> t a -> t a
\r
83 -- vertical composition
\r
84 above :: t a -> t a -> t a
\r
85 -- generation of raw table matrix
\r
86 getMatrix :: t a -> [[(a,(Int,Int))]]
\r
88 showsTable :: (Show a,Table t) => t a -> ShowS
\r
89 showsTable table = shows (getMatrix table)
\r
91 showTable :: (Show a,Table t) => t a -> String
\r
92 showTable table = showsTable table ""
\r