packages feed

tabular 0.2.1.0 → 0.2.2.0

raw patch · 4 files changed

+41/−3 lines, 4 files

Files

Text/Tabular/Csv.hs view
@@ -16,5 +16,5 @@  where   -- cell2 includes the row and column labels   cells2 = zipWith (\h cs -> h : map f cs) rhStrings cells-  chStrings = map fc $ headerContents ch+  chStrings = "" : (map fc $ headerContents ch)   rhStrings = map fr $ headerContents rh
+ Text/Tabular/SimpleText.hs view
@@ -0,0 +1,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
example/sample1.hs view
@@ -2,12 +2,14 @@ import Text.Html (renderHtml, stringToHtml, (+++))  import qualified Text.Tabular.AsciiArt as A+import qualified Text.Tabular.SimpleText as S import qualified Text.Tabular.Html     as H import qualified Text.Tabular.Latex    as L import qualified Text.Tabular.Csv      as C  main =  do writeFile "sample1.txt"  $ A.render id id id example2+    writeFile "sample1.tab"  $ S.render "\t" id id id example2     writeFile "sample1.html" $ renderHtml $       H.css H.defaultCss +++ H.render stringToHtml stringToHtml stringToHtml example2     writeFile "sample1T.tex" $ L.render id id id example2
tabular.cabal view
@@ -1,11 +1,11 @@ name:                tabular-version:             0.2.1.0+version:             0.2.2.0 synopsis:            Two-dimensional data tables with rendering functions description:         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,-                     CSV, HTML or LaTeX.+                     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@@ -33,6 +33,7 @@ ghc-options: exposed-modules:     Text.Tabular,                      Text.Tabular.AsciiArt,+                     Text.Tabular.SimpleText,                      Text.Tabular.Csv,                      Text.Tabular.Html,                      Text.Tabular.Latex