mirror of
https://github.com/simonmichael/hledger.git
synced 2024-11-14 13:03:56 +03:00
ec51d28839
- the web UI has been streamlined; edit form, raw & entries views dropped - we now remember whether sidebar is open or closed - better help dialog - keyboard shortcuts are now available - better add form - more bootstrap styling - static file cleanups - report filtering fixes - upgrade jquery to 2.1.1, bootstrap to 3.1.1, drop select2, add typeahead, cookie, hotkeys - clarify debug helpers a little - refactoring
86 lines
2.7 KiB
Haskell
86 lines
2.7 KiB
Haskell
{-# OPTIONS_GHC -fno-warn-orphans #-}
|
|
module Application
|
|
( makeApplication
|
|
, getApplicationDev
|
|
, makeFoundation
|
|
) where
|
|
|
|
import Data.IORef
|
|
import Import
|
|
import Yesod.Default.Config
|
|
import Yesod.Default.Main
|
|
import Yesod.Default.Handlers
|
|
import Network.Wai.Middleware.RequestLogger (logStdoutDev, logStdout)
|
|
import Network.HTTP.Conduit (newManager)
|
|
|
|
-- adapt to http-conduit 1.x or 2.x when cabal macros are available, otherwise assume 2.x
|
|
#ifdef MIN_VERSION_http_conduit
|
|
#if MIN_VERSION_http_conduit(2,0,0)
|
|
#define http_conduit_2
|
|
#endif
|
|
#else
|
|
#define http_conduit_2
|
|
#endif
|
|
#ifdef http_conduit_2
|
|
import Network.HTTP.Client (defaultManagerSettings)
|
|
#else
|
|
import Network.HTTP.Conduit (def)
|
|
#endif
|
|
|
|
-- Import all relevant handler modules here.
|
|
-- Don't forget to add new modules to your cabal file!
|
|
import Handler.RootR
|
|
import Handler.JournalR
|
|
import Handler.RegisterR
|
|
import Handler.SidebarR
|
|
|
|
import Hledger.Web.Options (WebOpts(..), defwebopts)
|
|
import Hledger.Data (Journal, nulljournal)
|
|
import Hledger.Read (readJournalFile)
|
|
import Hledger.Utils (error')
|
|
import Hledger.Cli.Options (defcliopts, journalFilePathFromOpts)
|
|
|
|
-- This line actually creates our YesodDispatch instance. It is the second half
|
|
-- of the call to mkYesodData which occurs in Foundation.hs. Please see the
|
|
-- comments there for more details.
|
|
mkYesodDispatch "App" resourcesApp
|
|
|
|
-- This function allocates resources (such as a database connection pool),
|
|
-- performs initialization and creates a WAI application. This is also the
|
|
-- place to put your migrate statements to have automatic database
|
|
-- migrations handled by Yesod.
|
|
makeApplication :: WebOpts -> Journal -> AppConfig DefaultEnv Extra -> IO Application
|
|
makeApplication opts j conf = do
|
|
foundation <- makeFoundation conf
|
|
writeIORef (appJournal foundation) j
|
|
app <- toWaiAppPlain foundation
|
|
return $ logWare app
|
|
where
|
|
logWare | development = logStdoutDev
|
|
| server_ opts = logStdout
|
|
| otherwise = id
|
|
|
|
makeFoundation :: AppConfig DefaultEnv Extra -> IO App
|
|
makeFoundation conf = do
|
|
manager <- newManager
|
|
#ifdef http_conduit_2
|
|
defaultManagerSettings
|
|
#else
|
|
def
|
|
#endif
|
|
s <- staticSite
|
|
jref <- newIORef nulljournal
|
|
return $ App conf s manager defwebopts jref
|
|
|
|
-- for yesod devel
|
|
-- uses the journal specified by the LEDGER_FILE env var, or ~/.hledger.journal
|
|
getApplicationDev :: IO (Int, Application)
|
|
getApplicationDev = do
|
|
f <- journalFilePathFromOpts defcliopts
|
|
j <- either error' id `fmap` readJournalFile Nothing Nothing f
|
|
defaultDevelApp loader (makeApplication defwebopts j)
|
|
where
|
|
loader = Yesod.Default.Config.loadConfig (configSettings Development)
|
|
{ csParseExtra = parseExtra
|
|
}
|