diff --git a/hledger-web/AppRun.hs b/hledger-web/AppRun.hs index 0a75c823e..ef66aa1c5 100644 --- a/hledger-web/AppRun.hs +++ b/hledger-web/AppRun.hs @@ -5,14 +5,17 @@ module AppRun ( withApp ,withDevelApp + ,withWaiHandlerDevelApp ) where import Data.Dynamic (Dynamic, toDyn) import Network.Wai (Application) +import System.IO.Storage (withStore, putValue) import Yesod.Helpers.Static -import Hledger.Data (nulljournal) +import Hledger +import Hledger.Cli import App import Handlers @@ -30,6 +33,7 @@ mkYesodDispatch "App" resourcesApp withApp :: App -> (Application -> IO a) -> IO a withApp a f = toWaiApp a >>= f +-- Called by yesod devel. withDevelApp :: Dynamic withDevelApp = toDyn (withApp a :: (Application -> IO ()) -> IO ()) where a = App{ @@ -39,3 +43,21 @@ withDevelApp = toDyn (withApp a :: (Application -> IO ()) -> IO ()) ,appArgs=[] ,appJournal=nulljournal } + +-- Called by wai-handler-devel. +-- Eg: cabal-dev/bin/wai-handler-devel 5001 AppRun withWaiHandlerDevelApp +withWaiHandlerDevelApp :: (Application -> IO ()) -> IO () +withWaiHandlerDevelApp func = do + let f = "/repos/hledger/hledger-web/demo.journal" + ej <- readJournalFile Nothing f + let Right j = ej + let a = App{ + getStatic=static Settings.staticdir + ,appRoot=Settings.defapproot + ,appOpts=[File f] + ,appArgs=[] + ,appJournal=j + } + withStore "hledger" $ do + putValue "hledger" "journal" j + withApp a func