From e81430f05bc7b1f48348bfa06854f50d63550d35 Mon Sep 17 00:00:00 2001 From: Simon Michael Date: Fri, 15 Dec 2023 13:00:42 -1000 Subject: [PATCH] dev:web: rename makeFoundation* to makeApp* --- hledger-web/Hledger/Web/Application.hs | 40 ++++++++++++++------------ hledger-web/Hledger/Web/Test.hs | 4 +-- 2 files changed, 24 insertions(+), 20 deletions(-) diff --git a/hledger-web/Hledger/Web/Application.hs b/hledger-web/Hledger/Web/Application.hs index e2abbb0b7..d34803c59 100644 --- a/hledger-web/Hledger/Web/Application.hs +++ b/hledger-web/Hledger/Web/Application.hs @@ -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 - s <- staticSite - jref <- newIORef j' - return $ App conf s manager opts' jref +-- 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{ + settings = aconf + , getStatic = s + , httpManager = m + , appOpts = wopts + , appJournal = jref + } diff --git a/hledger-web/Hledger/Web/Test.hs b/hledger-web/Hledger/Web/Test.hs index c29bdbbbf..a868c02c0 100644 --- a/hledger-web/Hledger/Web/Test.hs +++ b/hledger-web/Hledger/Web/Test.hs @@ -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.