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 module Hledger.Web.Application
( makeApplication ( makeApplication
, makeFoundation , makeApp
, makeFoundationWith , makeAppWith
) where ) where
import Data.IORef (newIORef, writeIORef) import Data.IORef (newIORef, writeIORef)
@ -37,25 +37,29 @@ mkYesodDispatch "App" resourcesApp
-- migrations handled by Yesod. -- migrations handled by Yesod.
makeApplication :: WebOpts -> Journal -> AppConfig DefaultEnv Extra -> IO Application makeApplication :: WebOpts -> Journal -> AppConfig DefaultEnv Extra -> IO Application
makeApplication opts' j' conf' = do makeApplication opts' j' conf' = do
foundation <- makeFoundation conf' opts' app <- makeApp conf' opts'
writeIORef (appJournal foundation) j' writeIORef (appJournal app) j'
(logWare . (corsPolicy opts')) <$> toWaiApp foundation (logWare . (corsPolicy opts')) <$> toWaiApp app
where where
logWare | development = logStdoutDev logWare | development = logStdoutDev
| serve_ opts' || serve_api_ opts' = logStdout | serve_ opts' || serve_api_ opts' = logStdout
| otherwise = id | otherwise = id
makeFoundation :: AppConfig DefaultEnv Extra -> WebOpts -> IO App makeApp :: AppConfig DefaultEnv Extra -> WebOpts -> IO App
makeFoundation conf opts' = do makeApp = makeAppWith nulljournal
manager <- newManager defaultManagerSettings
s <- staticSite
jref <- newIORef nulljournal
return $ App conf s manager opts' jref
-- Make a Foundation with the given Journal as its state. -- Make an "App" (defined in App.hs),
makeFoundationWith :: Journal -> AppConfig DefaultEnv Extra -> WebOpts -> IO App -- with the given Journal as its state
makeFoundationWith j' conf opts' = do -- and the given "AppConfig" and "WebOpts" as its configuration.
manager <- newManager defaultManagerSettings makeAppWith :: Journal -> AppConfig DefaultEnv Extra -> WebOpts -> IO App
s <- staticSite makeAppWith j' aconf wopts = do
jref <- newIORef j' s <- staticSite
return $ App conf s manager opts' jref m <- newManager defaultManagerSettings
jref <- newIORef j'
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.Default.Config
import Yesod.Test import Yesod.Test
import Hledger.Web.Application ( makeFoundationWith ) import Hledger.Web.Application ( makeAppWith )
import Hledger.Web.WebOptions -- ( WebOpts(..), defwebopts, prognameandversion ) import Hledger.Web.WebOptions -- ( WebOpts(..), defwebopts, prognameandversion )
import Hledger.Web.Import hiding (get, j) import Hledger.Web.Import hiding (get, j)
import Hledger.Cli hiding (prognameandversion) import Hledger.Cli hiding (prognameandversion)
@ -82,7 +82,7 @@ runTests testsdesc rawopts j tests = do
, extraStaticRoot = T.pack <$> file_url_ wopts , 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 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. -- | Run hledger-web's built-in tests using the hspec test runner.