dev:web: rename makeFoundation* to makeApp*

This commit is contained in:
Simon Michael 2023-12-15 13:00:42 -10:00
parent 8e0370bd58
commit e81430f05b
2 changed files with 24 additions and 20 deletions

View File

@ -5,8 +5,8 @@
module Hledger.Web.Application
( makeApplication
, makeFoundation
, makeFoundationWith
, makeApp
, makeAppWith
) where
import Data.IORef (newIORef, writeIORef)
@ -37,25 +37,29 @@ mkYesodDispatch "App" resourcesApp
-- migrations handled by Yesod.
makeApplication :: WebOpts -> Journal -> AppConfig DefaultEnv Extra -> IO Application
makeApplication opts' j' conf' = do
foundation <- makeFoundation conf' opts'
writeIORef (appJournal foundation) j'
(logWare . (corsPolicy opts')) <$> toWaiApp foundation
app <- makeApp conf' opts'
writeIORef (appJournal app) j'
(logWare . (corsPolicy opts')) <$> toWaiApp app
where
logWare | development = logStdoutDev
| serve_ opts' || serve_api_ opts' = logStdout
| otherwise = id
makeFoundation :: AppConfig DefaultEnv Extra -> WebOpts -> IO App
makeFoundation conf opts' = do
manager <- newManager defaultManagerSettings
s <- staticSite
jref <- newIORef nulljournal
return $ App conf s manager opts' jref
makeApp :: AppConfig DefaultEnv Extra -> WebOpts -> IO App
makeApp = makeAppWith nulljournal
-- Make a Foundation with the given Journal as its state.
makeFoundationWith :: Journal -> AppConfig DefaultEnv Extra -> WebOpts -> IO App
makeFoundationWith j' conf opts' = do
manager <- newManager defaultManagerSettings
-- Make an "App" (defined in App.hs),
-- with the given Journal as its state
-- and the given "AppConfig" and "WebOpts" as its configuration.
makeAppWith :: Journal -> AppConfig DefaultEnv Extra -> WebOpts -> IO App
makeAppWith j' aconf wopts = do
s <- staticSite
m <- newManager defaultManagerSettings
jref <- newIORef j'
return $ App conf s manager opts' jref
return App{
settings = aconf
, getStatic = s
, httpManager = m
, appOpts = wopts
, appJournal = jref
}

View File

@ -48,7 +48,7 @@ import Test.Hspec (hspec)
import Yesod.Default.Config
import Yesod.Test
import Hledger.Web.Application ( makeFoundationWith )
import Hledger.Web.Application ( makeAppWith )
import Hledger.Web.WebOptions -- ( WebOpts(..), defwebopts, prognameandversion )
import Hledger.Web.Import hiding (get, j)
import Hledger.Cli hiding (prognameandversion)
@ -82,7 +82,7 @@ runTests testsdesc rawopts j tests = do
, extraStaticRoot = T.pack <$> file_url_ wopts
}
}
app <- makeFoundationWith j yconf wopts
app <- makeAppWith j yconf wopts
hspec $ yesodSpec app $ ydescribe testsdesc tests -- https://hackage.haskell.org/package/yesod-test/docs/Yesod-Test.html
-- | Run hledger-web's built-in tests using the hspec test runner.