lib: Write.Html.Attribute.tableStyle: style definitions taken from Commands.Balance.multiBalanceReportAsHtml
avoid duplicate with Write.Html.printHtml Write.Html.Attribute: remove dependency on Lucid
This commit is contained in:
parent
a494e15d55
commit
d8fc30f7c5
@ -23,12 +23,7 @@ import Data.Foldable (traverse_)
|
|||||||
|
|
||||||
printHtml :: (Lines border) => [[Cell border (Lucid.Html ())]] -> Lucid.Html ()
|
printHtml :: (Lines border) => [[Cell border (Lucid.Html ())]] -> Lucid.Html ()
|
||||||
printHtml table = do
|
printHtml table = do
|
||||||
Lucid.style_ $ Text.unlines $
|
Lucid.style_ Attr.tableStylesheet
|
||||||
"" :
|
|
||||||
"table {border-collapse:collapse}" :
|
|
||||||
"th, td {padding-left:1em}" :
|
|
||||||
"th.account, td.account {padding-left:0;}" :
|
|
||||||
[]
|
|
||||||
Lucid.table_ $ traverse_ formatRow table
|
Lucid.table_ $ traverse_ formatRow table
|
||||||
|
|
||||||
formatRow:: (Lines border) => [Cell border (Lucid.Html ())] -> Lucid.Html ()
|
formatRow:: (Lines border) => [Cell border (Lucid.Html ())] -> Lucid.Html ()
|
||||||
@ -50,7 +45,7 @@ formatCell cell =
|
|||||||
let style =
|
let style =
|
||||||
case leftBorder++rightBorder++topBorder++bottomBorder of
|
case leftBorder++rightBorder++topBorder++bottomBorder of
|
||||||
[] -> []
|
[] -> []
|
||||||
ss -> [Attr.styles_ ss] in
|
ss -> [Lucid.style_ $ Attr.concatStyles ss] in
|
||||||
let class_ =
|
let class_ =
|
||||||
map Lucid.class_ $
|
map Lucid.class_ $
|
||||||
filter (not . Text.null) [Spr.textFromClass $ cellClass cell] in
|
filter (not . Text.null) [Spr.textFromClass $ cellClass cell] in
|
||||||
|
|||||||
@ -1,11 +1,12 @@
|
|||||||
{-# LANGUAGE OverloadedStrings #-}
|
{-# LANGUAGE OverloadedStrings #-}
|
||||||
{-# LANGUAGE FlexibleContexts #-} -- for stylesheet_
|
|
||||||
{- |
|
{- |
|
||||||
Helpers and CSS styles for HTML output.
|
Helpers and CSS styles for HTML output.
|
||||||
-}
|
-}
|
||||||
module Hledger.Write.Html.Attribute (
|
module Hledger.Write.Html.Attribute (
|
||||||
stylesheet_,
|
stylesheet,
|
||||||
styles_,
|
concatStyles,
|
||||||
|
tableStylesheet,
|
||||||
|
tableStyle,
|
||||||
bold,
|
bold,
|
||||||
doubleborder,
|
doubleborder,
|
||||||
topdoubleborder,
|
topdoubleborder,
|
||||||
@ -20,20 +21,27 @@ module Hledger.Write.Html.Attribute (
|
|||||||
vpad,
|
vpad,
|
||||||
) where
|
) where
|
||||||
|
|
||||||
import qualified Lucid.Base as LucidBase
|
|
||||||
import qualified Lucid
|
|
||||||
import qualified Data.Text as Text
|
import qualified Data.Text as Text
|
||||||
import Data.Text (Text)
|
import Data.Text (Text)
|
||||||
|
|
||||||
|
|
||||||
-- | result can be 'Lucid.Attribute' or @Lucid.Html ()@
|
stylesheet :: [(Text,Text)] -> Text
|
||||||
stylesheet_ :: LucidBase.TermRaw Text result => [(Text,Text)] -> result
|
stylesheet elstyles =
|
||||||
stylesheet_ elstyles =
|
Text.unlines $
|
||||||
Lucid.style_ $ Text.unlines $
|
|
||||||
"" : [el<>" {"<>styles<>"}" | (el,styles) <- elstyles]
|
"" : [el<>" {"<>styles<>"}" | (el,styles) <- elstyles]
|
||||||
|
|
||||||
styles_ :: [Text] -> Lucid.Attribute
|
concatStyles :: [Text] -> Text
|
||||||
styles_ = Lucid.style_ . Text.intercalate "; "
|
concatStyles = Text.intercalate "; "
|
||||||
|
|
||||||
|
|
||||||
|
tableStylesheet :: Text
|
||||||
|
tableStylesheet = stylesheet tableStyle
|
||||||
|
|
||||||
|
tableStyle :: [(Text, Text)]
|
||||||
|
tableStyle =
|
||||||
|
[("table", collapse),
|
||||||
|
("th, td", lpad),
|
||||||
|
("th.account, td.account", "padding-left:0;")]
|
||||||
|
|
||||||
bold, doubleborder, topdoubleborder, bottomdoubleborder :: Text
|
bold, doubleborder, topdoubleborder, bottomdoubleborder :: Text
|
||||||
bold = "font-weight:bold"
|
bold = "font-weight:bold"
|
||||||
|
|||||||
@ -298,7 +298,7 @@ import Hledger.Cli.Utils
|
|||||||
import Hledger.Write.Csv (CSV, printCSV, printTSV)
|
import Hledger.Write.Csv (CSV, printCSV, printTSV)
|
||||||
import Hledger.Write.Ods (printFods)
|
import Hledger.Write.Ods (printFods)
|
||||||
import Hledger.Write.Html (printHtml)
|
import Hledger.Write.Html (printHtml)
|
||||||
import Hledger.Write.Html.Attribute (stylesheet_, collapse, lpad)
|
import Hledger.Write.Html.Attribute (tableStylesheet)
|
||||||
import qualified Hledger.Write.Html as Html
|
import qualified Hledger.Write.Html as Html
|
||||||
import qualified Hledger.Write.Spreadsheet as Ods
|
import qualified Hledger.Write.Spreadsheet as Ods
|
||||||
|
|
||||||
@ -811,7 +811,7 @@ multiBalanceReportAsHtml ropts mbr =
|
|||||||
let
|
let
|
||||||
(headingsrow,bodyrows,mtotalsrows) = multiBalanceReportHtmlRows ropts mbr
|
(headingsrow,bodyrows,mtotalsrows) = multiBalanceReportHtmlRows ropts mbr
|
||||||
in do
|
in do
|
||||||
stylesheet_ [("table",collapse), ("th, td",lpad), ("th.account, td.account","padding-left:0;")]
|
style_ tableStylesheet
|
||||||
table_ $ mconcat $
|
table_ $ mconcat $
|
||||||
[headingsrow]
|
[headingsrow]
|
||||||
++ bodyrows
|
++ bodyrows
|
||||||
|
|||||||
@ -22,7 +22,7 @@ import qualified Data.Text.Lazy.Builder as TB
|
|||||||
import Data.Time.Calendar (Day, addDays)
|
import Data.Time.Calendar (Day, addDays)
|
||||||
import System.Console.CmdArgs.Explicit as C (Mode, flagNone, flagReq)
|
import System.Console.CmdArgs.Explicit as C (Mode, flagNone, flagReq)
|
||||||
import Hledger.Write.Csv (CSV, printCSV, printTSV)
|
import Hledger.Write.Csv (CSV, printCSV, printTSV)
|
||||||
import Hledger.Write.Html.Attribute (stylesheet_, collapse, lpad, alignleft, alignright)
|
import Hledger.Write.Html.Attribute (stylesheet, tableStyle, alignleft, alignright)
|
||||||
import qualified Hledger.Write.Html as Html
|
import qualified Hledger.Write.Html as Html
|
||||||
import qualified Hledger.Write.Spreadsheet as Spr
|
import qualified Hledger.Write.Spreadsheet as Spr
|
||||||
import Lucid as L hiding (value_)
|
import Lucid as L hiding (value_)
|
||||||
@ -384,10 +384,8 @@ compoundBalanceReportAsHtml ropts cbr =
|
|||||||
|
|
||||||
in do
|
in do
|
||||||
link_ [rel_ "stylesheet", href_ "hledger.css"]
|
link_ [rel_ "stylesheet", href_ "hledger.css"]
|
||||||
stylesheet_ [
|
style_ $ stylesheet $
|
||||||
("table",collapse),
|
tableStyle ++ [
|
||||||
("th, td",lpad),
|
|
||||||
("th.account, td.account","padding-left:0;"),
|
|
||||||
("td:nth-child(1)", "white-space:nowrap"),
|
("td:nth-child(1)", "white-space:nowrap"),
|
||||||
("tr:nth-child(even) td", "background-color:#eee")
|
("tr:nth-child(even) td", "background-color:#eee")
|
||||||
]
|
]
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user