From dfbe801fbcbe9491507f3fd5c93c8160d5d8687d Mon Sep 17 00:00:00 2001 From: Simon Michael Date: Sat, 3 May 2014 14:53:32 -0700 Subject: [PATCH 01/18] csv: don't count fields in skipped lines (fixes #177) --- hledger-lib/Hledger/Read/CsvReader.hs | 29 +++++++++++++-------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/hledger-lib/Hledger/Read/CsvReader.hs b/hledger-lib/Hledger/Read/CsvReader.hs index 482e234c4..a7a37224e 100644 --- a/hledger-lib/Hledger/Read/CsvReader.hs +++ b/hledger-lib/Hledger/Read/CsvReader.hs @@ -83,17 +83,9 @@ readJournalFromCsv mrulesfile csvfile csvdata = handle (\e -> return $ Left $ show (e :: IOException)) $ do let throwerr = throw.userError - -- parse csv - records <- (either throwerr id . validateCsv) `fmap` parseCsv csvfile csvdata - return $ dbg "" $ take 3 records - - -- identify header lines - -- let (headerlines, datalines) = identifyHeaderLines records - -- mfieldnames = lastMay headerlines - -- parse rules let rulesfile = fromMaybe (rulesFileFor csvfile) mrulesfile - created <- records `seq` ensureRulesFileExists rulesfile + created <- ensureRulesFileExists rulesfile if created then hPrintf stderr "creating default conversion rules file %s, edit this file for better results\n" rulesfile else hPrintf stderr "using conversion rules file %s\n" rulesfile @@ -101,14 +93,21 @@ readJournalFromCsv mrulesfile csvfile csvdata = return $ dbg "" rules -- apply skip directive - let headerlines = maybe 0 oneorerror $ getDirective "skip" rules + let skip = maybe 0 oneorerror $ getDirective "skip" rules where oneorerror "" = 1 oneorerror s = readDef (throwerr $ "could not parse skip value: " ++ show s) s - records' = drop headerlines records + + -- parse csv + records <- (either throwerr id . validateCsv skip) `fmap` parseCsv csvfile csvdata + dbgAtM 1 "" $ take 3 records + + -- identify header lines + -- let (headerlines, datalines) = identifyHeaderLines records + -- mfieldnames = lastMay headerlines -- convert to transactions and return as a journal - let txns = map (transactionFromCsvRecord rules) records' + let txns = map (transactionFromCsvRecord rules) records return $ Right nulljournal{jtxns=sortBy (comparing tdate) txns} parseCsv :: FilePath -> String -> IO (Either ParseError CSV) @@ -118,9 +117,9 @@ parseCsv path csvdata = _ -> return $ parseCSV path csvdata -- | Return the cleaned up and validated CSV data, or an error. -validateCsv :: Either ParseError CSV -> Either String [CsvRecord] -validateCsv (Left e) = Left $ show e -validateCsv (Right rs) = validate $ filternulls rs +validateCsv :: Int -> Either ParseError CSV -> Either String [CsvRecord] +validateCsv _ (Left e) = Left $ show e +validateCsv numhdrlines (Right rs) = validate $ drop numhdrlines $ filternulls rs where filternulls = filter (/=[""]) validate [] = Left "no CSV records found" From 1fb1ad6df2734e9478df29530d880dc080abbbfc Mon Sep 17 00:00:00 2001 From: Simon Michael Date: Sat, 3 May 2014 15:05:35 -0700 Subject: [PATCH 02/18] csv: allow an empty first name in fields list (fixes #178) --- hledger-lib/Hledger/Read/CsvReader.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hledger-lib/Hledger/Read/CsvReader.hs b/hledger-lib/Hledger/Read/CsvReader.hs index a7a37224e..f3cb1a262 100644 --- a/hledger-lib/Hledger/Read/CsvReader.hs +++ b/hledger-lib/Hledger/Read/CsvReader.hs @@ -408,8 +408,8 @@ fieldnamelist = (do string "fields" optional $ char ':' many1 spacenonewline - f <- fieldname let separator = many spacenonewline >> char ',' >> many spacenonewline + f <- fromMaybe "" <$> optionMaybe fieldname fs <- many1 $ (separator >> fromMaybe "" <$> optionMaybe fieldname) restofline return $ map (map toLower) $ f:fs From 09ebd3e0492f671c0e05574f08aa99cfc5121899 Mon Sep 17 00:00:00 2001 From: Simon Michael Date: Sat, 3 May 2014 15:26:51 -0700 Subject: [PATCH 03/18] cli: options before the add-on are also passed to it (fixes #182) --- hledger/Hledger/Cli/Main.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hledger/Hledger/Cli/Main.hs b/hledger/Hledger/Cli/Main.hs index 6c0405885..370c77f51 100644 --- a/hledger/Hledger/Cli/Main.hs +++ b/hledger/Hledger/Cli/Main.hs @@ -265,7 +265,7 @@ main = do -- an external command | isExternalCommand = do - let externalargs = filter (not.(=="--")) argsaftercmd + let externalargs = argsbeforecmd ++ filter (not.(=="--")) argsaftercmd let shellcmd = printf "%s-%s %s" progname cmd (unwords' externalargs) :: String dbgM "external command selected" cmd dbgM "external command arguments" (map quoteIfNeeded externalargs) From 120b3b83777cf84df3118b7cb7eba580d0b93c48 Mon Sep 17 00:00:00 2001 From: Simon Michael Date: Sat, 3 May 2014 15:48:20 -0700 Subject: [PATCH 04/18] add: don't apply a default commodity to amounts on entry (fixes #138) --- hledger/Hledger/Cli/Add.hs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/hledger/Hledger/Cli/Add.hs b/hledger/Hledger/Cli/Add.hs index 6ec2da033..40073fe33 100644 --- a/hledger/Hledger/Cli/Add.hs +++ b/hledger/Hledger/Cli/Add.hs @@ -265,7 +265,8 @@ amountAndCommentWizard EntryState{..} = do maybeRestartTransaction $ line $ green $ printf "Amount %d%s: " pnum (showDefault def) where - parseAmountAndComment = either (const Nothing) Just . parseWithCtx (jContext esJournal) amountandcommentp + parseAmountAndComment = either (const Nothing) Just . parseWithCtx nodefcommodityctx amountandcommentp + nodefcommodityctx = (jContext esJournal){ctxCommodityAndStyle=Nothing} amountandcommentp = do a <- amountp many spacenonewline From beeed4c10c3bb9b6d91a6176a0773a516abdcb6c Mon Sep 17 00:00:00 2001 From: Simon Michael Date: Tue, 6 May 2014 21:36:04 -0700 Subject: [PATCH 05/18] aregister: fix date filtering with disordered txns (fixes #184) Fix a refactoring-related regression that the tests missed: if transactions were not ordered by date in the journal, register could include postings before the report start date in the output. --- hledger-lib/Hledger/Reports/PostingsReport.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hledger-lib/Hledger/Reports/PostingsReport.hs b/hledger-lib/Hledger/Reports/PostingsReport.hs index 00f4a093a..f44e81d75 100644 --- a/hledger-lib/Hledger/Reports/PostingsReport.hs +++ b/hledger-lib/Hledger/Reports/PostingsReport.hs @@ -66,7 +66,7 @@ postingsReport opts q j = (totallabel, items) dbg "ps3" $ (if related_ opts then concatMap relatedPostings else id) $ -- with -r, replace each with its sibling postings dbg "ps2" $ filter (reportq `matchesPosting`) $ -- filter postings by the query, including before the report start date, ignoring depth dbg "ps1" $ journalPostings $ journalSelectingAmountFromOpts opts j - (precedingps, reportps) = dbg "precedingps, reportps" $ span (beforestartq `matchesPosting`) pstoend + (precedingps, reportps) = dbg "precedingps, reportps" $ partition (beforestartq `matchesPosting`) pstoend empty = queryEmpty q -- displayexpr = display_ opts -- XXX From 6d6aae3cc98cde728a160958c8e126135bbd6d9b Mon Sep 17 00:00:00 2001 From: Simon Michael Date: Wed, 7 May 2014 16:43:32 -0700 Subject: [PATCH 06/18] update changelog --- hledger/CHANGES | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/hledger/CHANGES b/hledger/CHANGES index 0ccc06aeb..5ae0b5a85 100644 --- a/hledger/CHANGES +++ b/hledger/CHANGES @@ -1,3 +1,15 @@ +0.23.1 (2014/5/7) + +- register: fix a refactoring-related regression that the tests + missed: if transactions were not ordered by date in the journal, + register could include postings before the report start date in the + output. (#184) +- add: don't apply a default commodity to amounts on entry (#138) +- cli: options before the add-on command name are now also passed to it (#182) +- csv: allow the first name in a fields list to be empty (#178) +- csv: don't validate fields count in skipped lines (#177) + + 0.23 (2014/5/1) Journal format: From 4b1714a9e0c4466a33305b70627ceafce070c9de Mon Sep 17 00:00:00 2001 From: Simon Michael Date: Wed, 7 May 2014 16:44:44 -0700 Subject: [PATCH 07/18] bump version to 0.23.1 --- .version | 2 +- hledger-lib/hledger-lib.cabal | 2 +- hledger-web/hledger-web.cabal | 14 +++++++------- hledger/hledger.cabal | 10 +++++----- 4 files changed, 14 insertions(+), 14 deletions(-) diff --git a/.version b/.version index 39010d220..610e28725 100644 --- a/.version +++ b/.version @@ -1 +1 @@ -0.23 +0.23.1 diff --git a/hledger-lib/hledger-lib.cabal b/hledger-lib/hledger-lib.cabal index 64860432a..0813fa8b9 100644 --- a/hledger-lib/hledger-lib.cabal +++ b/hledger-lib/hledger-lib.cabal @@ -1,5 +1,5 @@ name: hledger-lib -version: 0.23 +version: 0.23.1 stability: stable category: Finance, Console synopsis: Core data types, parsers and utilities for the hledger accounting tool. diff --git a/hledger-web/hledger-web.cabal b/hledger-web/hledger-web.cabal index 0372dc8e3..eb42e13ee 100644 --- a/hledger-web/hledger-web.cabal +++ b/hledger-web/hledger-web.cabal @@ -1,5 +1,5 @@ name: hledger-web -version: 0.23 +version: 0.23.1 stability: stable category: Finance synopsis: A web interface for the hledger accounting tool. @@ -71,7 +71,7 @@ flag library-only Default: False library - cpp-options: -DVERSION="0.23" + cpp-options: -DVERSION="0.23.1" if flag(dev) || flag(library-only) cpp-options: -DDEVELOPMENT @@ -114,8 +114,8 @@ library Hledger.Web.Options -- Setup -- stops yesod devel complaining, requires build-depends: Cabal build-depends: - hledger == 0.23 - , hledger-lib == 0.23 + hledger == 0.23.1 + , hledger-lib == 0.23.1 , base >= 4 && < 5 , bytestring , clientsession @@ -172,7 +172,7 @@ executable hledger-web if flag(library-only) Buildable: False - cpp-options: -DVERSION="0.23" + cpp-options: -DVERSION="0.23.1" if flag(dev) cpp-options: -DDEVELOPMENT @@ -214,8 +214,8 @@ executable hledger-web Hledger.Web.Options build-depends: - hledger == 0.23 - , hledger-lib == 0.23 + hledger == 0.23.1 + , hledger-lib == 0.23.1 , base >= 4 && < 5 , bytestring , clientsession diff --git a/hledger/hledger.cabal b/hledger/hledger.cabal index 245892cbd..0c446f0b0 100644 --- a/hledger/hledger.cabal +++ b/hledger/hledger.cabal @@ -1,5 +1,5 @@ name: hledger -version: 0.23 +version: 0.23.1 stability: stable category: Finance, Console synopsis: The main command-line interface for the hledger accounting tool. @@ -42,7 +42,7 @@ flag threaded Default: True library - cpp-options: -DVERSION="0.23" + cpp-options: -DVERSION="0.23.1" ghc-options: -W default-language: Haskell2010 -- should be the same as below @@ -65,7 +65,7 @@ library Hledger.Cli.Stats -- should be the same as below build-depends: - hledger-lib == 0.23 + hledger-lib == 0.23.1 ,base >= 4.3 && < 5 -- ,cabal-file-th ,containers @@ -128,14 +128,14 @@ executable hledger Hledger.Cli.Print Hledger.Cli.Register Hledger.Cli.Stats - cpp-options: -DVERSION="0.23" + cpp-options: -DVERSION="0.23.1" ghc-options: -W if flag(threaded) ghc-options: -threaded -- should be the same as above default-language: Haskell2010 build-depends: - hledger-lib == 0.23 + hledger-lib == 0.23.1 ,base >= 4.3 && < 5 ,containers ,cmdargs >= 0.10 && < 0.11 From 6080d7eaf494f21d20f6269a58c9f21f6645e0ea Mon Sep 17 00:00:00 2001 From: Simon Michael Date: Tue, 6 May 2014 20:04:01 -0700 Subject: [PATCH 08/18] add: drop an obsolete functional test --- tests/add.test | 19 ++----------------- 1 file changed, 2 insertions(+), 17 deletions(-) diff --git a/tests/add.test b/tests/add.test index 16bc8c6ab..8f2a15c87 100644 --- a/tests/add.test +++ b/tests/add.test @@ -86,22 +86,7 @@ b >>> /a +\$1000\.00/ >>>=0 -# 8. no commodity entered, the (most recent) default commodity should be applied -# (and a non-ascii commodity symbol should work) - printf 'D $1000.0\nD £1,000.00\n' >t$$.j; hledgerdev -f t$$.j add; cat t$$.j; rm -f t$$.j -<<< -2010/1/1 - -a -1000 -b - -. - ->>> /a +£1,000.00/ ->>>=0 - -# 9. default amounts should not fail to balance due to precision +# 8. default amounts should not fail to balance due to precision rm -f nosuch.journal; hledgerdev -f nosuch.journal add; rm -f nosuch.journal <<< 2010/1/1 @@ -114,7 +99,7 @@ c >>> /Amount 3 \[-0.75\]:/ >>>=0 -## 10. shouldn't add decimals if there aren't any +## 9. shouldn't add decimals if there aren't any ## printf '\n\na\n1\nb\n' | hledgerdev -f /dev/null add # hledgerdev -f /dev/null add # <<< From 2447fc6a475f290b19341f96ef6509c597c55651 Mon Sep 17 00:00:00 2001 From: Simon Michael Date: Thu, 8 May 2014 13:19:36 -0700 Subject: [PATCH 09/18] sync README with website --- README.md | 55 ++++++++++++++++--------------------------------------- 1 file changed, 16 insertions(+), 39 deletions(-) diff --git a/README.md b/README.md index d97d35e65..66635d9ed 100644 --- a/README.md +++ b/README.md @@ -1,50 +1,27 @@ -# hledger +# hledger -## command-line and web accounting tools +## lightweight, portable, dependable accounting tools -hledger is a computer program for easily tracking money, time, or other -commodities, inspired by and compatible with [ledger](http://ledger-cli.org). +hledger is a computer program for easily tracking money, time, or other commodities, +on unix, mac and windows (and web-capable mobile devices, to some extent). -hledger is first a command-line tool, but also provides a [web interface](http://demo.hledger.org). -Though limited in features, it is lightweight, usable and reliable. -For some, it is a simpler, less distracting, less costly alternative to Quicken or GnuCash. -It is free software available under the GNU General Public License. +It is first a command-line tool, but there is also a web interface +and a Haskell library (http://hackage.haskell.org/package/hledger-lib) for +building your own programs and scripts (hledger is written in Haskell). +hledger was inspired by and is largely compatible with [[FAQ#hledger-and-ledger|Ledger]]. +hledger is free software available under the GNU General Public License v3+. -hledger aims to help both computer experts and regular folks gain clarity -in their finances and time management, but currently it is a little more -suited to techies. I use it every day to: +hledger aims to help both computer experts and regular folks +to gain clarity and control in their finances and time management, +but currently it is a bit more suited to techies. +I use it every day to: - track spending and income - see time reports by day/week/month/project - get accurate numbers for client billing and tax filing - track invoices -Read the docs to learn more, including -[how we are different from ledger](FAQ.html#how-does-hledger-relate-to-ledger), -and get started tracking your numbers! +Though limited in features, hledger is lightweight, usable and reliable. +For some, it is a simpler, less distracting, more future-proof alternative to Quicken or GnuCash. - - -\ -**Mail list:** [hledger.org/list](http://hledger.org/list). For general *ledger topics, - there's also [ledger's list](http://list.ledger-cli.org) - -**IRC chat:** [#ledger on irc.freenode.net](irc://irc.freenode.net/#ledger), shared with ledger - -**Bug tracker:** [hledger.org/bugs](http://hledger.org/bugs) -**and planning board:** [hledger.org/trello](http://hledger.org/trello) - -**Code:** [hledger.org/code](http://hledger.org/code) - ([recent commits](https://github.com/simonmichael/hledger/commits/master), - [all activity](https://github.com/simonmichael/hledger/graphs/contributors)) - - - - - - - - +For more, see http://hledger.org. From 6512233ac1b42780e92365744bb58798d84d2bd8 Mon Sep 17 00:00:00 2001 From: Simon Michael Date: Thu, 8 May 2014 13:20:22 -0700 Subject: [PATCH 10/18] remove another old link --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 66635d9ed..1d9941fed 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ on unix, mac and windows (and web-capable mobile devices, to some extent). It is first a command-line tool, but there is also a web interface and a Haskell library (http://hackage.haskell.org/package/hledger-lib) for building your own programs and scripts (hledger is written in Haskell). -hledger was inspired by and is largely compatible with [[FAQ#hledger-and-ledger|Ledger]]. +hledger was inspired by and is largely compatible with Ledger. hledger is free software available under the GNU General Public License v3+. hledger aims to help both computer experts and regular folks From c528a4c14fed12788b7654d973d456a7ce69b7fe Mon Sep 17 00:00:00 2001 From: Simon Michael Date: Thu, 8 May 2014 14:20:12 -0700 Subject: [PATCH 11/18] register: also fix date (or date2) sorting of postings (#184) --- hledger-lib/Hledger/Reports/PostingsReport.hs | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/hledger-lib/Hledger/Reports/PostingsReport.hs b/hledger-lib/Hledger/Reports/PostingsReport.hs index f44e81d75..f00f842f1 100644 --- a/hledger-lib/Hledger/Reports/PostingsReport.hs +++ b/hledger-lib/Hledger/Reports/PostingsReport.hs @@ -18,6 +18,7 @@ where import Data.List import Data.Maybe +import Data.Ord (comparing) import Data.Time.Calendar import Safe (headMay, lastMay) import Test.HUnit @@ -50,7 +51,8 @@ postingsReport opts q j = (totallabel, items) depth = queryDepth q depthless = filterQuery (not . queryIsDepth) datelessq = filterQuery (not . queryIsDate) q - dateqcons = if date2_ opts then Date2 else Date + (dateqcons,pdate) | date2_ opts = (Date2, postingDate2) + | otherwise = (Date, postingDate) requestedspan = dbg "requestedspan" $ queryDateSpan (date2_ opts) q -- span specified by -b/-e/-p options and query args requestedspan' = dbg "requestedspan'" $ requestedspan `spanDefaultsFrom` journalDateSpan (date2_ opts) j -- if open-ended, close it using the journal's end dates intervalspans = dbg "intervalspans" $ splitSpan (intervalFromOpts opts) requestedspan' -- interval spans enclosing it @@ -62,11 +64,12 @@ postingsReport opts q j = (totallabel, items) reportq = dbg "reportq" $ depthless $ And [datelessq, beforeendq] -- user's query with no start date, end date on an interval boundary and no depth limit pstoend = - dbg "ps4" $ map (filterPostingAmount symq) $ -- remove amount parts which the query's cur: terms would exclude - dbg "ps3" $ (if related_ opts then concatMap relatedPostings else id) $ -- with -r, replace each with its sibling postings - dbg "ps2" $ filter (reportq `matchesPosting`) $ -- filter postings by the query, including before the report start date, ignoring depth - dbg "ps1" $ journalPostings $ journalSelectingAmountFromOpts opts j - (precedingps, reportps) = dbg "precedingps, reportps" $ partition (beforestartq `matchesPosting`) pstoend + dbg "ps4" $ sortBy (comparing pdate) $ -- sort postings by date (or date2) + dbg "ps3" $ map (filterPostingAmount symq) $ -- remove amount parts which the query's cur: terms would exclude + dbg "ps2" $ (if related_ opts then concatMap relatedPostings else id) $ -- with -r, replace each with its sibling postings + dbg "ps1" $ filter (reportq `matchesPosting`) $ -- filter postings by the query, including before the report start date, ignoring depth + journalPostings $ journalSelectingAmountFromOpts opts j + (precedingps, reportps) = dbg "precedingps, reportps" $ span (beforestartq `matchesPosting`) pstoend empty = queryEmpty q -- displayexpr = display_ opts -- XXX From 6d93fe15d37d74a56061c9fb0c18c2c2441e0f66 Mon Sep 17 00:00:00 2001 From: Simon Michael Date: Thu, 8 May 2014 14:32:06 -0700 Subject: [PATCH 12/18] update changelogs --- hledger-lib/CHANGES | 9 +++++++++ hledger-web/CHANGES | 8 ++++++++ hledger/CHANGES | 4 ++++ 3 files changed, 21 insertions(+) diff --git a/hledger-lib/CHANGES b/hledger-lib/CHANGES index a5886ee49..cf2e9a21e 100644 --- a/hledger-lib/CHANGES +++ b/hledger-lib/CHANGES @@ -1,5 +1,14 @@ API-ish changes in hledger-lib. For user-visible changes, see the hledger changelog. +0.23.2 (2014/5/8) + +- postingsReport: also fix date sorting of displayed postings (#184) + +0.23.1 (2014/5/7) + +- postingsReport: with disordered journal entries, postings before the + report start date could get wrongly included. (#184) + 0.23 (2014/5/1) - orDatesFrom -> spanDefaultsFrom diff --git a/hledger-web/CHANGES b/hledger-web/CHANGES index 289d8a29c..6bce5c12f 100644 --- a/hledger-web/CHANGES +++ b/hledger-web/CHANGES @@ -1,5 +1,13 @@ See also the hledger changelog. +0.23.2 (2014/5/8) + +- depend on latest hledger + +0.23.1 (2014/5/7) + +- depend on latest hledger + 0.23 (2014/5/1) - The --static-root flag has been renamed to --file-url. diff --git a/hledger/CHANGES b/hledger/CHANGES index 5ae0b5a85..015ee0457 100644 --- a/hledger/CHANGES +++ b/hledger/CHANGES @@ -1,3 +1,7 @@ +0.23.2 (2014/5/8) + +- register: also fix date sorting of postings (#184) + 0.23.1 (2014/5/7) - register: fix a refactoring-related regression that the tests From 3113e09a624b6945d9bfd876ad491cd383a6a6a7 Mon Sep 17 00:00:00 2001 From: Simon Michael Date: Thu, 8 May 2014 14:32:29 -0700 Subject: [PATCH 13/18] bump version to 0.23.2 --- .version | 2 +- hledger-lib/hledger-lib.cabal | 2 +- hledger-web/hledger-web.cabal | 14 +++++++------- hledger/hledger.cabal | 10 +++++----- 4 files changed, 14 insertions(+), 14 deletions(-) diff --git a/.version b/.version index 610e28725..fda96dcf6 100644 --- a/.version +++ b/.version @@ -1 +1 @@ -0.23.1 +0.23.2 diff --git a/hledger-lib/hledger-lib.cabal b/hledger-lib/hledger-lib.cabal index 0813fa8b9..7b1a49816 100644 --- a/hledger-lib/hledger-lib.cabal +++ b/hledger-lib/hledger-lib.cabal @@ -1,5 +1,5 @@ name: hledger-lib -version: 0.23.1 +version: 0.23.2 stability: stable category: Finance, Console synopsis: Core data types, parsers and utilities for the hledger accounting tool. diff --git a/hledger-web/hledger-web.cabal b/hledger-web/hledger-web.cabal index eb42e13ee..8f0ffd8c5 100644 --- a/hledger-web/hledger-web.cabal +++ b/hledger-web/hledger-web.cabal @@ -1,5 +1,5 @@ name: hledger-web -version: 0.23.1 +version: 0.23.2 stability: stable category: Finance synopsis: A web interface for the hledger accounting tool. @@ -71,7 +71,7 @@ flag library-only Default: False library - cpp-options: -DVERSION="0.23.1" + cpp-options: -DVERSION="0.23.2" if flag(dev) || flag(library-only) cpp-options: -DDEVELOPMENT @@ -114,8 +114,8 @@ library Hledger.Web.Options -- Setup -- stops yesod devel complaining, requires build-depends: Cabal build-depends: - hledger == 0.23.1 - , hledger-lib == 0.23.1 + hledger == 0.23.2 + , hledger-lib == 0.23.2 , base >= 4 && < 5 , bytestring , clientsession @@ -172,7 +172,7 @@ executable hledger-web if flag(library-only) Buildable: False - cpp-options: -DVERSION="0.23.1" + cpp-options: -DVERSION="0.23.2" if flag(dev) cpp-options: -DDEVELOPMENT @@ -214,8 +214,8 @@ executable hledger-web Hledger.Web.Options build-depends: - hledger == 0.23.1 - , hledger-lib == 0.23.1 + hledger == 0.23.2 + , hledger-lib == 0.23.2 , base >= 4 && < 5 , bytestring , clientsession diff --git a/hledger/hledger.cabal b/hledger/hledger.cabal index 0c446f0b0..4b3c57a55 100644 --- a/hledger/hledger.cabal +++ b/hledger/hledger.cabal @@ -1,5 +1,5 @@ name: hledger -version: 0.23.1 +version: 0.23.2 stability: stable category: Finance, Console synopsis: The main command-line interface for the hledger accounting tool. @@ -42,7 +42,7 @@ flag threaded Default: True library - cpp-options: -DVERSION="0.23.1" + cpp-options: -DVERSION="0.23.2" ghc-options: -W default-language: Haskell2010 -- should be the same as below @@ -65,7 +65,7 @@ library Hledger.Cli.Stats -- should be the same as below build-depends: - hledger-lib == 0.23.1 + hledger-lib == 0.23.2 ,base >= 4.3 && < 5 -- ,cabal-file-th ,containers @@ -128,14 +128,14 @@ executable hledger Hledger.Cli.Print Hledger.Cli.Register Hledger.Cli.Stats - cpp-options: -DVERSION="0.23.1" + cpp-options: -DVERSION="0.23.2" ghc-options: -W if flag(threaded) ghc-options: -threaded -- should be the same as above default-language: Haskell2010 build-depends: - hledger-lib == 0.23.1 + hledger-lib == 0.23.2 ,base >= 4.3 && < 5 ,containers ,cmdargs >= 0.10 && < 0.11 From 342bae8c3520d7f9e310461021fe2309bb1bb5ec Mon Sep 17 00:00:00 2001 From: Ryan Desfosses Date: Sun, 11 May 2014 19:27:39 -0400 Subject: [PATCH 14/18] Histogram: cabal test and hlint warnings --- hledger/Hledger/Cli/Histogram.hs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/hledger/Hledger/Cli/Histogram.hs b/hledger/Hledger/Cli/Histogram.hs index af88305b5..aebc36618 100644 --- a/hledger/Hledger/Cli/Histogram.hs +++ b/hledger/Hledger/Cli/Histogram.hs @@ -6,6 +6,7 @@ Print a histogram report. (The "activity" command). module Hledger.Cli.Histogram where + import Data.List import Data.Maybe import Data.Ord @@ -19,8 +20,8 @@ import Hledger.Query import Prelude hiding (putStr) import Hledger.Utils.UTF8IOCompat (putStr) - -activitymode = (defCommandMode $ ["activity"] ++ aliases) { +activitymode :: Mode RawOpts +activitymode = (defCommandMode $ ["activity"] : aliases) { modeHelp = "show an ascii barchart of posting counts per interval (default: daily)" `withAliases` aliases ,modeHelpSuffix = [] ,modeGroupFlags = Group { @@ -31,6 +32,7 @@ activitymode = (defCommandMode $ ["activity"] ++ aliases) { } where aliases = [] +barchar :: Char barchar = '*' -- | Print a histogram of some statistic per reporting interval, such as @@ -46,8 +48,8 @@ showHistogram opts q j = concatMap (printDayWith countBar) spanps i = intervalFromOpts opts interval | i == NoInterval = Days 1 | otherwise = i - span = queryDateSpan (date2_ opts) q `spanDefaultsFrom` journalDateSpan (date2_ opts) j - spans = filter (DateSpan Nothing Nothing /=) $ splitSpan interval span + span' = queryDateSpan (date2_ opts) q `spanDefaultsFrom` journalDateSpan (date2_ opts) j + spans = filter (DateSpan Nothing Nothing /=) $ splitSpan interval span' spanps = [(s, filter (isPostingInDateSpan s) ps) | s <- spans] -- same as Register -- should count transactions, not postings ? From 47853d6df6a0966f644b8039b5c4e7d6dcabf9a8 Mon Sep 17 00:00:00 2001 From: Ryan Desfosses Date: Sun, 11 May 2014 20:19:36 -0400 Subject: [PATCH 15/18] Cli: cabal test and hlint warnings --- hledger/Hledger/Cli.hs | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/hledger/Hledger/Cli.hs b/hledger/Hledger/Cli.hs index 8f3f821ee..21fca23bc 100644 --- a/hledger/Hledger/Cli.hs +++ b/hledger/Hledger/Cli.hs @@ -97,8 +97,8 @@ tests_Hledger_Cli = TestList ,"account directive should preserve \"virtual\" posting type" ~: do j <- readJournal Nothing Nothing Nothing "!account test\n2008/12/07 One\n (from) $-1\n (to) $1\n" >>= either error' return let p = head $ tpostings $ head $ jtxns j - assertBool "" $ (paccount p) == "test:from" - assertBool "" $ (ptype p) == VirtualPosting + assertBool "" $ paccount p == "test:from" + assertBool "" $ ptype p == VirtualPosting ] @@ -188,6 +188,7 @@ sample_journal_str = unlines ] -} +defaultyear_journal_str :: String defaultyear_journal_str = unlines ["Y2009" ,"" @@ -337,9 +338,10 @@ defaultyear_journal_str = unlines -- ,"" -- ] +journal7 :: Journal journal7 = nulljournal {jtxns = [ - txnTieKnot $ Transaction { + txnTieKnot Transaction { tdate=parsedate "2007/01/01", tdate2=Nothing, tstatus=False, @@ -354,7 +356,7 @@ journal7 = nulljournal {jtxns = tpreceding_comment_lines="" } , - txnTieKnot $ Transaction { + txnTieKnot Transaction { tdate=parsedate "2007/02/01", tdate2=Nothing, tstatus=False, @@ -369,7 +371,7 @@ journal7 = nulljournal {jtxns = tpreceding_comment_lines="" } , - txnTieKnot $ Transaction { + txnTieKnot Transaction { tdate=parsedate "2007/01/02", tdate2=Nothing, tstatus=False, @@ -384,7 +386,7 @@ journal7 = nulljournal {jtxns = tpreceding_comment_lines="" } , - txnTieKnot $ Transaction { + txnTieKnot Transaction { tdate=parsedate "2007/01/03", tdate2=Nothing, tstatus=False, @@ -399,7 +401,7 @@ journal7 = nulljournal {jtxns = tpreceding_comment_lines="" } , - txnTieKnot $ Transaction { + txnTieKnot Transaction { tdate=parsedate "2007/01/03", tdate2=Nothing, tstatus=False, @@ -414,7 +416,7 @@ journal7 = nulljournal {jtxns = tpreceding_comment_lines="" } , - txnTieKnot $ Transaction { + txnTieKnot Transaction { tdate=parsedate "2007/01/03", tdate2=Nothing, tstatus=False, @@ -431,4 +433,5 @@ journal7 = nulljournal {jtxns = ] } +ledger7 :: Ledger ledger7 = ledgerFromJournal Any journal7 From 3182f2c69a6a9dd269a7092f69dbcc388bcdc960 Mon Sep 17 00:00:00 2001 From: Ryan Desfosses Date: Wed, 14 May 2014 11:58:38 -0400 Subject: [PATCH 16/18] Common: Added Register link to sidebar --- hledger-web/Handler/Common.hs | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/hledger-web/Handler/Common.hs b/hledger-web/Handler/Common.hs index dbf2a1c9b..c6ae14ded 100644 --- a/hledger-web/Handler/Common.hs +++ b/hledger-web/Handler/Common.hs @@ -181,7 +181,7 @@ addform _ vd@VD{..} = [hamlet| acctnames = sort $ journalAccountNamesUsed j -- Construct data for select2. Text must be quoted in a json string. toSelectData as = preEscapedString $ encode $ JSArray $ map (\a -> JSObject $ toJSObject [("text", showJSON a)]) as - manyfiles = (length $ files j) > 1 + manyfiles = length (files j) > 1 postingfields :: ViewData -> Int -> HtmlUrl AppRoute postingfields _ n = [hamlet| @@ -247,7 +247,7 @@ editform VD{..} = [hamlet| |] where title = "Edit journal" :: String - manyfiles = (length $ files j) > 1 + manyfiles = length (files j) > 1 formathelp = helplink "file-format" "file format help" -- | Import journal form. @@ -293,10 +293,10 @@ balanceReportAsHtml _ vd@VD{..} (items',total) = [+] - - + +
- Add a transaction.. + Register @@ -309,6 +309,11 @@ balanceReportAsHtml _ vd@VD{..} (items',total) = edit + + +
+ Add a transaction.. +
@@ -527,7 +532,7 @@ numberTransactionsReportItems items = number 0 nulldate items where number :: Int -> Day -> [TransactionsReportItem] -> [(Int,Bool,Bool,Bool,TransactionsReportItem)] number _ _ [] = [] - number n prevd (i@(Transaction{tdate=d},_,_,_,_,_):rest) = (n+1,newday,newmonth,newyear,i):(number (n+1) d rest) + number n prevd (i@(Transaction{tdate=d},_,_,_,_,_):rest) = (n+1,newday,newmonth,newyear,i): number (n+1) d rest where newday = d/=prevd newmonth = dm/=prevdm || dy/=prevdy From 38f977fa48f7411e8a84351a8953df6ee1746b48 Mon Sep 17 00:00:00 2001 From: Ryan Desfosses Date: Wed, 14 May 2014 12:18:50 -0400 Subject: [PATCH 17/18] Histogram: fixes previous change change made in Histogram:cabal test and hlint warning --- hledger/Hledger/Cli/Histogram.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hledger/Hledger/Cli/Histogram.hs b/hledger/Hledger/Cli/Histogram.hs index aebc36618..97693ce5a 100644 --- a/hledger/Hledger/Cli/Histogram.hs +++ b/hledger/Hledger/Cli/Histogram.hs @@ -21,7 +21,7 @@ import Prelude hiding (putStr) import Hledger.Utils.UTF8IOCompat (putStr) activitymode :: Mode RawOpts -activitymode = (defCommandMode $ ["activity"] : aliases) { +activitymode = (defCommandMode $ ["activity"] ++ aliases) { modeHelp = "show an ascii barchart of posting counts per interval (default: daily)" `withAliases` aliases ,modeHelpSuffix = [] ,modeGroupFlags = Group { From b60da5138630351ade38d5be4e6005304e3e647d Mon Sep 17 00:00:00 2001 From: Ryan Desfosses Date: Wed, 21 May 2014 07:30:54 -0400 Subject: [PATCH 18/18] made the following changes to resolve deprecated warnings: replaced hamletToRepHtml with giveUrlRenderer updated type RepHtml to Html replaced settingsPort with setPort --- hledger-web/Foundation.hs | 2 +- hledger-web/Handler/JournalEditR.hs | 4 ++-- hledger-web/Handler/JournalEntriesR.hs | 4 ++-- hledger-web/Handler/JournalR.hs | 4 ++-- hledger-web/Handler/Post.hs | 8 ++++---- hledger-web/Handler/RegisterR.hs | 4 ++-- hledger-web/Handler/RootR.hs | 2 +- hledger-web/Hledger/Web/Main.hs | 10 +++++----- hledger/hledger.cabal | 18 ++++++++++++++++++ 9 files changed, 37 insertions(+), 19 deletions(-) diff --git a/hledger-web/Foundation.hs b/hledger-web/Foundation.hs index ebedca187..05348014e 100644 --- a/hledger-web/Foundation.hs +++ b/hledger-web/Foundation.hs @@ -115,7 +115,7 @@ instance Yesod App where addScript $ StaticR hledger_js $(widgetFile "default-layout") - hamletToRepHtml $(hamletFile "templates/default-layout-wrapper.hamlet") + giveUrlRenderer $(hamletFile "templates/default-layout-wrapper.hamlet") -- This is done to provide an optimization for serving static files from -- a separate domain. Please see the staticRoot setting in Settings.hs diff --git a/hledger-web/Handler/JournalEditR.hs b/hledger-web/Handler/JournalEditR.hs index 6ef40517a..4d890c6dd 100644 --- a/hledger-web/Handler/JournalEditR.hs +++ b/hledger-web/Handler/JournalEditR.hs @@ -10,12 +10,12 @@ import Handler.Utils -- | The journal editform, no sidebar. -getJournalEditR :: Handler RepHtml +getJournalEditR :: Handler Html getJournalEditR = do vd <- getViewData defaultLayout $ do setTitle "hledger-web journal edit form" toWidget $ editform vd -postJournalEditR :: Handler RepHtml +postJournalEditR :: Handler Html postJournalEditR = handlePost diff --git a/hledger-web/Handler/JournalEntriesR.hs b/hledger-web/Handler/JournalEntriesR.hs index 56fb8f6db..127d137cc 100644 --- a/hledger-web/Handler/JournalEntriesR.hs +++ b/hledger-web/Handler/JournalEntriesR.hs @@ -16,7 +16,7 @@ import Hledger.Web.Options -- | The journal entries view, with sidebar. -getJournalEntriesR :: Handler RepHtml +getJournalEntriesR :: Handler Html getJournalEntriesR = do vd@VD{..} <- getViewData staticRootUrl <- (staticRoot . settings) <$> getYesod @@ -41,6 +41,6 @@ getJournalEntriesR = do ^{importform} |] -postJournalEntriesR :: Handler RepHtml +postJournalEntriesR :: Handler Html postJournalEntriesR = handlePost diff --git a/hledger-web/Handler/JournalR.hs b/hledger-web/Handler/JournalR.hs index 1cbd10e29..7c9276e47 100644 --- a/hledger-web/Handler/JournalR.hs +++ b/hledger-web/Handler/JournalR.hs @@ -14,7 +14,7 @@ import Hledger.Cli.Options import Hledger.Web.Options -- | The formatted journal view, with sidebar. -getJournalR :: Handler RepHtml +getJournalR :: Handler Html getJournalR = do vd@VD{..} <- getViewData staticRootUrl <- (staticRoot . settings) <$> getYesod @@ -48,6 +48,6 @@ getJournalR = do ^{importform} |] -postJournalR :: Handler RepHtml +postJournalR :: Handler Html postJournalR = handlePost diff --git a/hledger-web/Handler/Post.hs b/hledger-web/Handler/Post.hs index dae62f597..f46403538 100644 --- a/hledger-web/Handler/Post.hs +++ b/hledger-web/Handler/Post.hs @@ -20,7 +20,7 @@ import Hledger.Cli -- | Handle a post from any of the edit forms. -handlePost :: Handler RepHtml +handlePost :: Handler Html handlePost = do action <- lookupPostParam "action" case action of Just "add" -> handleAdd @@ -29,7 +29,7 @@ handlePost = do _ -> invalidArgs ["invalid action"] -- | Handle a post from the transaction add form. -handleAdd :: Handler RepHtml +handleAdd :: Handler Html handleAdd = do VD{..} <- getViewData -- get form input values. M means a Maybe value. @@ -91,7 +91,7 @@ handleAdd = do redirect (RegisterR, [("add","1")]) -- | Handle a post from the journal edit form. -handleEdit :: Handler RepHtml +handleEdit :: Handler Html handleEdit = do VD{..} <- getViewData -- get form input values, or validation errors. @@ -137,7 +137,7 @@ handleEdit = do jE -- | Handle a post from the journal import form. -handleImport :: Handler RepHtml +handleImport :: Handler Html handleImport = do setMessage "can't handle file upload yet" redirect JournalR diff --git a/hledger-web/Handler/RegisterR.hs b/hledger-web/Handler/RegisterR.hs index 2b91cf4bd..9addca3b2 100644 --- a/hledger-web/Handler/RegisterR.hs +++ b/hledger-web/Handler/RegisterR.hs @@ -16,7 +16,7 @@ import Hledger.Cli.Options import Hledger.Web.Options -- | The main journal/account register view, with accounts sidebar. -getRegisterR :: Handler RepHtml +getRegisterR :: Handler Html getRegisterR = do vd@VD{..} <- getViewData staticRootUrl <- (staticRoot . settings) <$> getYesod @@ -46,5 +46,5 @@ getRegisterR = do ^{importform} |] -postRegisterR :: Handler RepHtml +postRegisterR :: Handler Html postRegisterR = handlePost diff --git a/hledger-web/Handler/RootR.hs b/hledger-web/Handler/RootR.hs index 2d9c64044..5437efd9e 100644 --- a/hledger-web/Handler/RootR.hs +++ b/hledger-web/Handler/RootR.hs @@ -4,5 +4,5 @@ module Handler.RootR where import Import -getRootR :: Handler RepHtml +getRootR :: Handler Html getRootR = redirect defaultroute where defaultroute = RegisterR diff --git a/hledger-web/Hledger/Web/Main.hs b/hledger-web/Hledger/Web/Main.hs index 3eba8f72c..af0100a6e 100644 --- a/hledger-web/Hledger/Web/Main.hs +++ b/hledger-web/Hledger/Web/Main.hs @@ -16,8 +16,8 @@ import Yesod.Default.Config --(fromArgs) import Settings -- (parseExtra) import Application (makeApplication) import Data.String -import Data.Conduit.Network -import Network.Wai.Handler.Warp (runSettings, defaultSettings, settingsPort) +import Data.Conduit.Network hiding (setPort) +import Network.Wai.Handler.Warp (runSettings, defaultSettings, setPort) import Network.Wai.Handler.Launch (runUrlPort) -- import Prelude hiding (putStrLn) @@ -61,19 +61,19 @@ web opts j = do let j' = filterJournalTransactions (queryFromOpts d $ reportopts_ $ cliopts_ opts) j p = port_ opts u = base_url_ opts - staticRoot = pack <$> static_root_ opts + staticRoot' = pack <$> static_root_ opts _ <- printf "Starting web app on port %d with base url %s\n" p u app <- makeApplication opts j' AppConfig{appEnv = Development ,appPort = p ,appRoot = pack u ,appHost = fromString "*4" - ,appExtra = Extra "" Nothing staticRoot + ,appExtra = Extra "" Nothing staticRoot' } if server_ opts then do putStrLn "Press ctrl-c to quit" hFlush stdout - runSettings defaultSettings{settingsPort=p} app + runSettings (setPort p defaultSettings) app else do putStrLn "Starting web browser if possible" putStrLn "Web app will auto-exit after a few minutes with no browsers (or press ctrl-c)" diff --git a/hledger/hledger.cabal b/hledger/hledger.cabal index 4b3c57a55..1a7a4f4b6 100644 --- a/hledger/hledger.cabal +++ b/hledger/hledger.cabal @@ -197,3 +197,21 @@ test-suite tests , wizards == 1.0.* if impl(ghc >= 7.4) build-depends: pretty-show >= 1.6.4 + +benchmark bench + type: exitcode-stdio-1.0 +-- hs-source-dirs: src + main-is: ../tools/simplebench.hs + ghc-options: -Wall + default-language: Haskell2010 + build-depends: hledger-lib, + hledger, + base >= 4.3 && < 5, + old-locale, + time, + html, + tabular >= 0.2 && < 0.3, + process, + filepath, + directory +