diff --git a/.travis.yml b/.travis.yml index 7a5ea5437..d2731e6d8 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,3 +1,5 @@ +# http://docs.haskellstack.org/en/stable/travis_ci.html + language: haskell branches: @@ -19,7 +21,7 @@ cache: before_install: - mkdir -p ~/.local/bin - export PATH=~/.local/bin:$PATH - - travis_retry curl -L https://github.com/commercialhaskell/stack/releases/download/v0.1.3.1/stack-0.1.3.1-x86_64-linux.gz | gunzip > ~/.local/bin/stack + - travis_retry curl -L https://www.stackage.org/stack/linux-x86_64 | tar xz --wildcards --strip-components=1 -C ~/.local/bin '*/stack' - chmod a+x ~/.local/bin/stack install: diff --git a/Makefile b/Makefile index 629177db4..542be015f 100644 --- a/Makefile +++ b/Makefile @@ -1273,13 +1273,12 @@ tagrelease: \ # @darcs changes --from-tag $(FROMTAG) |grep '^\w' |cut -c 31- |sort |uniq # @echo -# showloc: \ -# $(call def-help,showloc,\ -# \ -# ) -# @echo Current lines of code including tests: -# @sloccount `ls $(SOURCEFILES)` | grep haskell: -# @echo +cloc: \ + $(call def-help,cloc, count lines of source code ) + @echo Lines of code including tests: + @cloc --exclude-lang=HTML --exclude-dir=.stack-work,.idea,dist,old,bin,doc,site,.tutorial-data . + @echo +# `ls $(SOURCEFILES)` # sloc: \ # $(call def-help,sloc,\ diff --git a/hledger-api/hledger-api.hs b/hledger-api/hledger-api.hs index d7b22a909..e6fcf5a41 100644 --- a/hledger-api/hledger-api.hs +++ b/hledger-api/hledger-api.hs @@ -8,10 +8,12 @@ -- {-# LANGUAGE TypeSynonymInstances #-} {-# LANGUAGE FlexibleInstances #-} {-# LANGUAGE RecordWildCards #-} +{-# LANGUAGE ScopedTypeVariables #-} module Main where import Control.Monad +import Control.Monad.IO.Class import Control.Monad.Trans.Either import Control.Monad.Trans.Reader import Data.Aeson @@ -19,7 +21,7 @@ import Data.Decimal import qualified Data.Map as M import Data.Monoid import Data.Proxy -import Data.Text +import Data.Text hiding (map,reverse) import GHC.Generics import Network.Wai as Wai import Network.Wai.Handler.Warp as Warp @@ -31,6 +33,7 @@ import System.Exit import System.IO import Text.Printf +import Hledger.Query import Hledger.Cli hiding (Reader, version) version="0.27.98" @@ -68,42 +71,57 @@ main = do serveApi :: FilePath -> Int -> Journal -> IO () serveApi f p j = do - printf "Starting web api for %s on port %d\nPress ctrl-c to quit\n" f p >> hFlush stdout + printf "Starting web api for %s on port %d\nPress ctrl-c to quit\n" f p Warp.run p $ hledgerApiApp j -hledgerApiApp :: Journal -> Wai.Application -hledgerApiApp j = Servant.serve hledgerApi hledgerApiServer - where - hledgerApi :: Proxy HledgerApi - hledgerApi = Proxy - - hledgerApiServer :: Servant.Server HledgerApi - hledgerApiServer = Servant.enter readerToEither hledgerServerT - where - readerToEither :: Reader Journal :~> EitherT ServantErr IO - readerToEither = Nat $ \r -> return (runReader r j) - type HledgerApi = - "accounts" :> Get '[JSON] [AccountName] + "accountnames" :> Get '[JSON] [AccountName] :<|> "transactions" :> Get '[JSON] [Transaction] - :<|> "prices" :> Get '[JSON] [MarketPrice] - :<|> "commodities" :> Get '[JSON] [Commodity] + :<|> "prices" :> Get '[JSON] [MarketPrice] + :<|> "commodities" :> Get '[JSON] [Commodity] + :<|> "accounts" :> Get '[JSON] [Account] + :<|> "reports" :> + "accounttransactions" :> Capture "acct" AccountName :> Get '[JSON] AccountTransactionsReport + :<|> Raw -hledgerServerT :: ServerT HledgerApi (Reader Journal) -hledgerServerT = - accountsH - :<|> transactionsH - :<|> pricesH - :<|> commoditiesH +hledgerApiApp :: Journal -> Wai.Application +hledgerApiApp j = Servant.serve api server where - accountsH = journalAccountNames <$> ask - transactionsH = jtxns <$> ask - pricesH = jmarketprices <$> ask - commoditiesH = (M.keys . jcommoditystyles) <$> ask + api :: Proxy HledgerApi + api = Proxy + server :: Server HledgerApi + server = + accountnamesH + :<|> transactionsH + :<|> pricesH + :<|> commoditiesH + :<|> accountsH + :<|> accounttransactionsH + :<|> serveDirectory "static" + where + accountnamesH = return $ journalAccountNames j + transactionsH = return $ jtxns j + pricesH = return $ jmarketprices j + commoditiesH = return $ (M.keys . jcommoditystyles) j + accountsH = return $ laccounts $ ledgerFromJournal Hledger.Cli.Any j + accounttransactionsH (a::AccountName) = do + -- d <- liftIO getCurrentDay + let + ropts = defreportopts + -- ropts' = ropts {depth_=Nothing + -- ,balancetype_=HistoricalBalance + -- } + q = Hledger.Query.Any --filterQuery (not . queryIsDepth) $ queryFromOpts d ropts' + thisacctq = Acct $ accountNameToAccountRegex a -- includes subs + return $ accountTransactionsReport ropts j q thisacctq -instance ToJSON ClearedStatus where toJSON = genericToJSON defaultOptions -- avoid https://github.com/bos/aeson/issues/290 +-- brief toJSON definitions included to avoid https://github.com/bos/aeson/issues/290 +-- use toEncoding = genericToEncoding defaultOptions instead ? +instance ToJSON ClearedStatus where toJSON = genericToJSON defaultOptions instance ToJSON GenericSourcePos where toJSON = genericToJSON defaultOptions +instance ToJSON Decimal where + toJSON = toJSON . show instance ToJSON Amount where toJSON = genericToJSON defaultOptions instance ToJSON AmountStyle where toJSON = genericToJSON defaultOptions instance ToJSON Side where toJSON = genericToJSON defaultOptions @@ -111,27 +129,31 @@ instance ToJSON DigitGroupStyle where toJSON = genericToJSON defaultOptions instance ToJSON MixedAmount where toJSON = genericToJSON defaultOptions instance ToJSON Price where toJSON = genericToJSON defaultOptions instance ToJSON MarketPrice where toJSON = genericToJSON defaultOptions -instance ToJSON Posting - where - toJSON Posting{..} = - object - ["pdate" .= toJSON pdate - ,"pdate2" .= toJSON pdate2 - ,"pstatus" .= toJSON pstatus - ,"paccount" .= toJSON paccount - ,"pamount" .= toJSON pamount - ,"pcomment" .= toJSON pcomment - ,"ptype" .= toJSON ptype - ,"ptags" .= toJSON ptags - ,"pbalanceassertion" .= toJSON pbalanceassertion - -- just show parent transaction's index - ,"ptransaction" .= toJSON (maybe "" (show.tindex) ptransaction) - ] instance ToJSON PostingType where toJSON = genericToJSON defaultOptions +instance ToJSON Posting where + toJSON Posting{..} = + object + ["pdate" .= toJSON pdate + ,"pdate2" .= toJSON pdate2 + ,"pstatus" .= toJSON pstatus + ,"paccount" .= toJSON paccount + ,"pamount" .= toJSON pamount + ,"pcomment" .= toJSON pcomment + ,"ptype" .= toJSON ptype + ,"ptags" .= toJSON ptags + ,"pbalanceassertion" .= toJSON pbalanceassertion + ,"ptransactionidx" .= toJSON (maybe "" (show.tindex) ptransaction) + ] instance ToJSON Transaction where toJSON = genericToJSON defaultOptions -instance ToJSON Decimal - where - -- toJSON (Decimal decimalPlaces decimalMantissa) = - -- object ["places" .= decimalPlaces, "mantissa" .= decimalMantissa] - -- toEncoding = genericToEncoding defaultOptions - toJSON d = toJSON $ show d +instance ToJSON Account where + toJSON a = + object + ["aname" .= toJSON (aname a) + ,"aebalance" .= toJSON (aebalance a) + ,"aibalance" .= toJSON (aibalance a) + ,"anumpostings" .= toJSON (anumpostings a) + ,"aboring" .= toJSON (aboring a) + ,"aparentname" .= toJSON (maybe "" aname $ aparent a) + ,"asubs" .= toJSON (map toJSON $ asubs a) + ] +instance ToJSON AccountTransactionsReport where toJSON = genericToJSON defaultOptions diff --git a/hledger-api/static/README.txt b/hledger-api/static/README.txt new file mode 100644 index 000000000..2b8913edb --- /dev/null +++ b/hledger-api/static/README.txt @@ -0,0 +1 @@ +Files under this directory are served by hledger-api when no other API route is matched. diff --git a/hledger-ui/CHANGES b/hledger-ui/CHANGES index 90eae4f14..659ad041f 100644 --- a/hledger-ui/CHANGES +++ b/hledger-ui/CHANGES @@ -1,6 +1,10 @@ User-visible changes in hledger-ui. See also hledger's change log. +0.27.3 (2016/1/12) + +- allow brick 0.4 + 0.27.2 (2016/1/11) - allow brick 0.3.x diff --git a/hledger-ui/hledger-ui.cabal b/hledger-ui/hledger-ui.cabal index 3c6aab7b6..0ece2e898 100644 --- a/hledger-ui/hledger-ui.cabal +++ b/hledger-ui/hledger-ui.cabal @@ -3,7 +3,7 @@ -- see: https://github.com/sol/hpack name: hledger-ui -version: 0.27.2 +version: 0.27.3 stability: beta category: Finance, Console synopsis: Curses-style user interface for the hledger accounting tool @@ -25,7 +25,7 @@ homepage: http://hledger.org bug-reports: http://bugs.hledger.org cabal-version: >= 1.10 build-type: Simple -tested-with: GHC==7.8.4, GHC==7.10.2 +tested-with: GHC==7.8.4, GHC==7.10.3 extra-source-files: CHANGES @@ -54,13 +54,13 @@ executable hledger-ui ghc-options: -Wall -fno-warn-unused-do-bind -fno-warn-name-shadowing -fno-warn-missing-signatures -fno-warn-type-defaults -fno-warn-orphans if flag(threaded) ghc-options: -threaded - cpp-options: -DVERSION="0.27.2" + cpp-options: -DVERSION="0.27.3" build-depends: hledger >= 0.27 && < 0.28 , hledger-lib >= 0.27 && < 0.28 , base >= 3 && < 5 , base-compat >= 0.8.1 - , brick >= 0.2 && < 0.4 + , brick >= 0.2 && < 0.5 , cmdargs >= 0.8 , containers , data-default diff --git a/hledger-ui/package.yaml b/hledger-ui/package.yaml index e3daa9177..058970b3a 100644 --- a/hledger-ui/package.yaml +++ b/hledger-ui/package.yaml @@ -9,7 +9,7 @@ # - conditional blocks name : hledger-ui -version : '0.27.2' +version : '0.27.3' stability : beta category : Finance, Console synopsis : Curses-style user interface for the hledger accounting tool @@ -31,7 +31,7 @@ github : simonmichael/hledger homepage : http://hledger.org bug-reports : http://bugs.hledger.org # XXX not supported -tested-with : GHC==7.10.2 +tested-with : GHC==7.10.3 extra-source-files: - CHANGES @@ -54,7 +54,7 @@ ghc-options: -fno-warn-type-defaults -fno-warn-orphans -cpp-options: -DVERSION="0.27.2" +cpp-options: -DVERSION="0.27.3" executables: hledger-ui: @@ -69,7 +69,7 @@ executables: - hledger-lib >= 0.27 && < 0.28 - base >= 3 && < 5 - base-compat >= 0.8.1 - - brick >= 0.2 && < 0.4 + - brick >= 0.2 && < 0.5 - cmdargs >= 0.8 - containers - data-default diff --git a/site/download.md b/site/download.md index 528f26212..4b73952d4 100644 --- a/site/download.md +++ b/site/download.md @@ -98,9 +98,7 @@ This is a quick way to help the project and your fellow users! 2. `stack setup` (if you need GHC installed. If you're not sure, run the next command and it will tell you.) -3. `stack --resolver nightly-2015-11-04 install hledger [hledger-web]` \ - - *2015/11/3: hledger-ui has [not yet reached stackage](https://github.com/fpco/stackage/issues/938); you must install it from source or with cabal, see below.* +3. `stack --resolver lts-4 install hledger [hledger-ui] [hledger-web]` 4. Ensure `~/.local/bin` or the Windows equivalent is in your `$PATH`, so that you can just type `hledger` to run it. (stack will show the proper directory and will tell you if it is not in $PATH).