web: support wai-handler-devel for auto-rebuilding

Eg: hledger-web$ wai-handler-devel 5001 AppRun withWaiHandlerDevelApp
This commit is contained in:
Simon Michael 2011-06-03 22:35:22 +00:00
parent 6496c1ef61
commit d1447c984a

View File

@ -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