Safe Haskell | None |
---|
Renders Penny data in a format that can be parsed by
Penny.Copper.Parsec. These functions render text that is
compliant with the EBNF grammar which is at
doc/ledger-grammar.org
.
- txtWords :: [Text] -> Text
- renMaybe :: Maybe a -> (a -> Maybe Text) -> Maybe Text
- isSubAcctLvl1 :: SubAccount -> Bool
- isAcctLvl1 :: Account -> Bool
- quotedLvl1Acct :: Account -> Maybe Text
- isFirstSubAcctLvl2 :: SubAccount -> Bool
- isOtherSubAcctLvl2 :: SubAccount -> Bool
- isAcctLvl2 :: Account -> Bool
- lvl2Acct :: Account -> Maybe Text
- ledgerAcct :: Account -> Maybe Text
- quotedLvl1Cmdty :: Commodity -> Maybe Text
- lvl2Cmdty :: Commodity -> Maybe Text
- lvl3Cmdty :: Commodity -> Maybe Text
- quoteQtyRep :: QtyRep -> (Text, Text)
- qtyRep :: QtyRep -> Text
- hasSpace :: WholeOrFrac (GroupedDigits PeriodGrp) -> Bool
- amount :: Maybe (Amount Qty -> S3 Radix PeriodGrp CommaGrp) -> Maybe Side -> Maybe SpaceBetween -> Either (Amount QtyRep) (Amount Qty) -> Maybe Text
- comment :: Comment -> Maybe Text
- dateTime :: DateTime -> Text
- pad2 :: Text -> Text
- pad4 :: Text -> Text
- showX :: Show a => a -> Text
- hoursMinsSecsZone :: Hours -> Minutes -> Seconds -> TimeZoneOffset -> Text
- entry :: Maybe (Amount Qty -> S3 Radix PeriodGrp CommaGrp) -> Maybe Side -> Maybe SpaceBetween -> Either (Entry QtyRep) (Entry Qty) -> Maybe Text
- flag :: Flag -> Maybe Text
- postingMemoLine :: Int -> Text -> Maybe Text
- postingMemo :: Bool -> Memo -> Maybe Text
- transactionMemoLine :: Text -> Maybe Text
- transactionMemo :: Memo -> Maybe Text
- number :: Number -> Maybe Text
- quotedLvl1Payee :: Payee -> Maybe Text
- lvl2Payee :: Payee -> Maybe Text
- payee :: Payee -> Maybe Text
- price :: PricePoint -> Maybe Text
- tag :: Tag -> Maybe Text
- tags :: Tags -> Maybe Text
- topLine :: TopLineCore -> Maybe Text
- posting :: Maybe (Amount Qty -> S3 Radix PeriodGrp CommaGrp) -> Bool -> Ent PostingCore -> Maybe Text
- formatter :: Bool -> Text -> Text -> Text -> Text -> Text -> Text -> Text -> Text
- transaction :: Maybe (Amount Qty -> S3 Radix PeriodGrp CommaGrp) -> (TopLineCore, Ents PostingCore) -> Maybe Text
- item :: Maybe (Amount Qty -> S3 Radix PeriodGrp CommaGrp) -> S4 (TopLineCore, Ents PostingCore) PricePoint Comment BlankLine -> Maybe Text
Helpers
txtWords :: [Text] -> TextSource
Merges a list of words into one Text; however, if any given Text is empty, that Text is first dropped from the list.
renMaybe :: Maybe a -> (a -> Maybe Text) -> Maybe TextSource
Takes a field that may or may not be present and a function that renders it. If the field is not present at all, returns an empty Text. Otherwise will succeed or fail depending upon whether the rendering function succeeds or fails.
Accounts
isSubAcctLvl1 :: SubAccount -> BoolSource
Is True if a sub account can be rendered at Level 1; False otherwise.
isAcctLvl1 :: Account -> BoolSource
quotedLvl1Acct :: Account -> Maybe TextSource
isAcctLvl2 :: Account -> BoolSource
ledgerAcct :: Account -> Maybe TextSource
Shows an account, with the minimum level of quoting
possible. Fails with an error if any one of the characters in the
account name does not satisfy the lvl1Char
predicate. Otherwise
returns a rendered account, quoted if necessary.
Commodities
quotedLvl1Cmdty :: Commodity -> Maybe TextSource
Render a quoted Level 1 commodity. Fails if any character does not satisfy lvl1Char.
lvl2Cmdty :: Commodity -> Maybe TextSource
Render a Level 2 commodity. Fails if the first character is not a letter or a symbol, or if any other character is a space.
lvl3Cmdty :: Commodity -> Maybe TextSource
Render a Level 3 commodity. Fails if any character is not a letter or a symbol.
Quantities
quoteQtyRep :: QtyRep -> (Text, Text)Source
Gets the characters necessary to quote a qtyRep.
Amounts
:: Maybe (Amount Qty -> S3 Radix PeriodGrp CommaGrp) | If Just, render entries that are NOT inferred and that do not have a QtyRep. If Nothing, fail if an entry is NOT inferred and does not have a QtyRep. (Inferred entries are always rendered without an entry.) |
-> Maybe Side | |
-> Maybe SpaceBetween | |
-> Either (Amount QtyRep) (Amount Qty) | |
-> Maybe Text |
Render an Amount. The Format is required so that the commodity can be displayed in the right place.
Comments
DateTime
dateTime :: DateTime -> TextSource
Render a DateTime. The day is always printed. If the time zone offset is not zero, then the time and time zone offset are both printed. If the time zone offset is zero, then the hours and minutes are printed, but only if the time is not midnight. If the seconds are not zero, they are also printed.
hoursMinsSecsZone :: Hours -> Minutes -> Seconds -> TimeZoneOffset -> TextSource
Entries
:: Maybe (Amount Qty -> S3 Radix PeriodGrp CommaGrp) | If Just, render entries that are NOT inferred and that do not have a QtyRep. If Nothing, fail if an entry is NOT inferred and does not have a QtyRep. (Inferred entries are always rendered without an entry.) |
-> Maybe Side | |
-> Maybe SpaceBetween | |
-> Either (Entry QtyRep) (Entry Qty) | |
-> Maybe Text |
Flags
Memos
Renders a postingMemoLine, optionally with trailing whitespace. The trailing whitespace allows the next line to be indented properly if is also a postingMemoLine. This is handled using trailing whitespace rather than leading whitespace because leading whitespace is inconsistent with the grammar.
postingMemo :: Bool -> Memo -> Maybe TextSource
Renders a postingMemo. Fails if the postingMemo is empty, as the grammar requires that they have at least one line.
If the boolean is True, inserts padding after the last postingMemoLine so that the next line is indented by four columns. Use this if the posting memo is followed by another posting. If the last boolean if False, there is no indenting after the last postingMemoLine.
transactionMemo :: Memo -> Maybe TextSource
Numbers
Payees
quotedLvl1Payee :: Payee -> Maybe TextSource
Prices
price :: PricePoint -> Maybe TextSource
Tags
TopLine
topLine :: TopLineCore -> Maybe TextSource
Renders the TopLine. Emits trailing whitespace after the newline so that the first posting is properly indented.
Posting
:: Maybe (Amount Qty -> S3 Radix PeriodGrp CommaGrp) | If Just, render entries that are NOT inferred and that do not have a QtyRep. If Nothing, fail if an entry is NOT inferred and does not have a QtyRep. (Inferred entries are always rendered without an entry.) |
-> Bool | If True, emit four spaces after the trailing newline. |
-> Ent PostingCore | |
-> Maybe Text |
Renders a Posting. Fails if any of the components fail to render. In addition, if the unverified Posting has an Entry, a Format must be provided, otherwise render fails.
The columns look like this. Column numbers begin with 0 (like they do in Emacs) rather than with column 1 (like they do in Vim). (Really Emacs is the strange one; most CLI utilities seem to start with column 1 too...)
ID COLUMN WIDTH WHAT --------------------------------------------------- A 0 4 Blank spaces for indentation B 4 50 Flag, Number, Payee, Account, Tags C 54 2 Blank spaces for padding D 56 NA Entry
Omit the padding after column B if there is no entry; also omit columns C and D entirely if there is no Entry. (It is annoying to have extraneous blank space in a file).
This table is a bit of a lie, because the blank spaces for indentation are emitted either by the posting previous to this one (either after the posting itself or after its postingMemo) or by the TopLine.
Also emits an additional eight spaces after the trailing newline if the posting has a memo. That way the memo will be indented properly. (There are trailing spaces here, as opposed to leading spaces in the posting memo, because the latter would be inconsistent with the grammar.)
Emits an extra four spaces after the first line if the first paramter is True. However, this is overriden if there is a memo, in which case eight spaces will be emitted. (This allows the next posting to be indented properly.)
Transaction
:: Maybe (Amount Qty -> S3 Radix PeriodGrp CommaGrp) | If Just, render entries that are NOT inferred and that do not have a QtyRep. If Nothing, fail if an entry is NOT inferred and does not have a QtyRep. (Inferred entries are always rendered without an entry.) |
-> (TopLineCore, Ents PostingCore) | |
-> Maybe Text |
Item
:: Maybe (Amount Qty -> S3 Radix PeriodGrp CommaGrp) | If Just, render entries that are NOT inferred and that do not have a QtyRep. If Nothing, fail if an entry is NOT inferred and does not have a QtyRep. (Inferred entries are always rendered without an entry.) |
-> S4 (TopLineCore, Ents PostingCore) PricePoint Comment BlankLine | |
-> Maybe Text |