-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Two-dimensional data tables with rendering functions -- -- Tabular provides a Haskell representation of two-dimensional data -- tables, the kind that you might find in a spreadsheet or or a research -- report. It also comes with some default rendering functions for -- turning those tables into ASCII art, simple text with an arbitrary -- delimiter, CSV, HTML or LaTeX. -- -- Below is an example of the kind of output this library produces. The -- tabular package can group rows and columns, each group having one of -- three separators (no line, single line, double line) between its -- members. -- --
-- || 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 --@package tabular @version 0.2.2.4 -- | Note: the core types and comibnators from this module are from Toxaris -- in a #haskell conversation on 2008-08-24 module Text.Tabular data Properties NoLine :: Properties SingleLine :: Properties DoubleLine :: Properties data Header h Header :: h -> Header h Group :: Properties -> [Header h] -> Header h -- |
-- 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 example id -- -- -- -- || 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 --data Table rh ch a Table :: (Header rh) -> (Header ch) -> [[a]] -> Table rh ch a -- | Retrieve the contents of a header headerContents :: Header h -> [h] -- | 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 zipHeader :: h -> [h] -> Header a -> Header (h, a) flattenHeader :: Header h -> [Either Properties h] -- | 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 squish :: (Properties -> b -> b) -> (h -> b) -> Header h -> [b] -- | 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"] --data SemiTable h a SemiTable :: (Header h) -> [a] -> SemiTable h a empty :: Table rh ch a col :: ch -> [a] -> SemiTable ch a -- | Column header 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 -- | besides (^..^) :: Table rh ch a -> SemiTable ch a -> Table rh ch a -- | besides with a line (^|^) :: Table rh ch a -> SemiTable ch a -> Table rh ch a -- | besides with a double line (^||^) :: Table rh ch a -> SemiTable ch a -> Table rh ch a -- | below (+.+) :: Table rh ch a -> SemiTable rh a -> Table rh ch a -- | below with a line (+----+) :: Table rh ch a -> SemiTable rh a -> Table rh ch a -- | below with a double line (+====+) :: Table rh ch a -> SemiTable rh a -> Table rh ch a instance Functor Header module Text.Tabular.AsciiArt -- | for simplicity, we assume that each cell is rendered on a single line render :: (rh -> String) -> (ch -> String) -> (a -> String) -> Table rh ch a -> String -- | We stop rendering on the shortest list! renderColumns :: [Int] -> Header String -> String renderHLine :: [Int] -> Header String -> Properties -> [String] renderHLine' :: [Int] -> Char -> Header String -> String padLeft :: Int -> String -> String module Text.Tabular.SimpleText render :: String -> (rh -> String) -> (ch -> String) -> (a -> String) -> Table rh ch a -> String renderColumns :: String -> Header String -> String module Text.Tabular.Csv -- | for simplicity, we assume that each cell is rendered on a single line render :: (rh -> String) -> (ch -> String) -> (a -> String) -> Table rh ch a -> String module Text.Tabular.Html render :: (rh -> Html) -> (ch -> Html) -> (a -> Html) -> Table rh ch a -> Html vAttr :: Properties -> [HtmlAttr] hAttr :: Properties -> [HtmlAttr] -- | Convenience function to add a CSS string to your HTML document css :: String -> Html -- | You need to incorporate some CSS into your file with the classes -- thinbottom, thinright, thickbottom and -- thickright. See css defaultCss :: String module Text.Tabular.Latex render :: (rh -> String) -> (ch -> String) -> (a -> String) -> Table rh ch a -> String renderUsing :: [String] -> (rh -> String) -> (ch -> String) -> (a -> String) -> Table rh ch a -> String hline :: String addTableNl :: String -> String label :: String -> String hAttr :: Properties -> String vAttr :: Properties -> String