From c948cc39327ea4fe829f97456b84f14d8642d7e9 Mon Sep 17 00:00:00 2001 From: Profpatsch Date: Wed, 2 Apr 2025 20:11:51 +0200 Subject: [PATCH] State: Remove unnecessary templates state field MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The templates are directly pulled out of the config and then never changed, so no reason to put the field in state. There’s also no way to generate or change the state through some other mechanism as far as I can see. --- gitit.hs | 2 +- src/Network/Gitit.hs | 6 +++--- src/Network/Gitit/Initialize.hs | 8 +++----- src/Network/Gitit/State.hs | 1 - src/Network/Gitit/Types.hs | 1 - 5 files changed, 7 insertions(+), 11 deletions(-) diff --git a/gitit.hs b/gitit.hs index 2f9d6203e..47b8d45d6 100644 --- a/gitit.hs +++ b/gitit.hs @@ -105,7 +105,7 @@ main = do -- start the server simpleHTTPWithSocket sock serverConf $ msum [ wiki conf - , dir "_reloadTemplates" reloadTemplates + , dir "_reloadTemplates" (reloadTemplates conf) ] data ExitOpt diff --git a/src/Network/Gitit.hs b/src/Network/Gitit.hs index 57d8f2270..fc1f293ba 100644 --- a/src/Network/Gitit.hs +++ b/src/Network/Gitit.hs @@ -210,9 +210,9 @@ wikiHandlers = ] -- | Recompiles the gitit templates. -reloadTemplates :: ServerPart Response -reloadTemplates = do - liftIO recompilePageTemplate +reloadTemplates :: Config -> ServerPart Response +reloadTemplates cfg = do + liftIO $ recompilePageTemplate cfg ok $ toResponse "Page templates have been recompiled." -- | Converts a gitit Handler into a standard happstack ServerPart. diff --git a/src/Network/Gitit/Initialize.hs b/src/Network/Gitit/Initialize.hs index 2cedef75a..009e5a41f 100644 --- a/src/Network/Gitit/Initialize.hs +++ b/src/Network/Gitit/Initialize.hs @@ -63,15 +63,13 @@ initializeGititState conf = do updateGititState $ \s -> s { sessions = Sessions M.empty , users = users' - , templatesPath = templatesDir conf , renderPage = defaultRenderPage templ , plugins = plugins' } -- | Recompile the page template. -recompilePageTemplate :: IO () -recompilePageTemplate = do - tempsDir <- queryGititState templatesPath - ct <- compilePageTemplate tempsDir +recompilePageTemplate :: Config -> IO () +recompilePageTemplate cfg = do + ct <- compilePageTemplate (templatesDir cfg) updateGititState $ \st -> st{renderPage = defaultRenderPage ct} --- | Compile a master page template named @page.st@ in the directory specified. diff --git a/src/Network/Gitit/State.hs b/src/Network/Gitit/State.hs index aef2e3ea3..41d0fb261 100644 --- a/src/Network/Gitit/State.hs +++ b/src/Network/Gitit/State.hs @@ -39,7 +39,6 @@ import Network.Gitit.Types gititstate :: IORef GititState gititstate = unsafePerformIO $ newIORef GititState { sessions = undefined , users = undefined - , templatesPath = undefined , renderPage = undefined , plugins = undefined } diff --git a/src/Network/Gitit/Types.hs b/src/Network/Gitit/Types.hs index 4b95759cb..793cd5d6c 100644 --- a/src/Network/Gitit/Types.hs +++ b/src/Network/Gitit/Types.hs @@ -263,7 +263,6 @@ data User = User { data GititState = GititState { sessions :: Sessions SessionData, users :: M.Map String User, - templatesPath :: FilePath, renderPage :: PageLayout -> Html -> Handler, plugins :: [Plugin] }