Commit 18592683c27243b1878b6cbb5863d9a482c5a327 Parent: 343385fd21bf0b47923028575a18ad17b97bb805 Author: mcol <mcol@posteo.net> Date: 2022-05-28 22:19:14 +0100 Committer: mcol <mcol@posteo.net> Committed: 2022-05-28 22:19:14 +0100 Move some ReaderT LgRepo IO functions to IO
src/Templates.hs Modified
@@ -8,13 +8,11 @@ ) where import Control.Monad.IO.Class (liftIO) -import Control.Monad.Trans.Reader (ReaderT) import qualified Data.HashMap.Strict as HashMap import Data.IORef (modifyIORef', newIORef, readIORef) import qualified Data.Text as T import Data.Text.Internal.Lazy (Text) import qualified Data.Text.Lazy.Builder as TB -import Git.Libgit2 (LgRepo) import Path (Abs, File, Path, Rel, filename, toFilePath) import System.IO.Error (tryIOError) import qualified Text.Ginger.AST as G @@ -59,7 +57,7 @@ generate :: Template -> HashMap.HashMap T.Text (GVal RunRepo) -> - ReaderT LgRepo IO Text + IO Text generate template context = do content <- liftIO . newIORef . TB.fromText $ ""
src/Repositories.hs Modified
@@ -139,7 +139,7 @@ liftIO . ensureDir $ output </> fileDir -- Run the generator -- - mapM_ (genRepo output scope) $ envRepoTemplates env + liftIO $ mapM_ (genRepo output scope) $ envRepoTemplates env let quiet = envQuiet env force = envForce env @@ -152,15 +152,15 @@ Path Abs Dir -> (t -> FilePath) -> t -> - ReaderT LgRepo IO () + IO () gen = genTarget scope quiet force - whenJust (envCommitTemplate env) \commitT -> do - output' <- liftIO . fmap (output </>) . parseRelDir $ "commit" + whenJust (envCommitTemplate env) \commitT -> liftIO do + output' <- fmap (output </>) . parseRelDir $ "commit" mapM_ (gen commitT "commit" output' commitHref) commits - whenJust (envFileTemplate env) \fileT -> do - output' <- liftIO . fmap (output </>) . parseRelDir $ "file" + whenJust (envFileTemplate env) \fileT -> liftIO do + output' <- fmap (output </>) . parseRelDir $ "file" mapM_ (gen fileT "file" output' fileHref) tree -- TODO: detect file changes -- Copy any static files/folders into the output folder -- @@ -369,7 +369,7 @@ Path Abs Dir -> HashMap.HashMap Text (GVal RunRepo) -> Template -> - ReaderT LgRepo IO () + IO () genRepo output scope template = do let output' = toFilePath (output </> templatePath template) result <- generate template scope @@ -401,13 +401,13 @@ Path Abs Dir -> (t -> FilePath) -> t -> - ReaderT LgRepo IO () + IO () genTarget scope quiet force template category output href target = do - output' <- liftIO . fmap (output </>) . parseRelFile . href $ target - exists <- liftIO . doesFileExist $ output' + output' <- fmap (output </>) . parseRelFile . href $ target + exists <- doesFileExist output' when (force || not exists) $ do let output'' = toFilePath output' - liftIO . unless quiet . putStrLn $ "Writing " <> output'' - liftIO . ignoringAbsence . removeFile $ output'' + unless quiet . putStrLn $ "Writing " <> output'' + ignoringAbsence . removeFile $ output'' result <- generate template $ HashMap.insert category (toGVal target) scope - liftIO $ TL.writeFile output'' result + TL.writeFile output'' result