Commit 3aa05611b5515fb20c35dc72429c0eeecb73b6ce Parent: 2cdfc7332b46fe5d9a8c602e055e8a7239031024 Author: mcol <mcol@posteo.net> Date: 2021-11-24 22:28:43 +0000 Committer: mcol <mcol@posteo.net> Committed: 2021-11-24 22:28:43 +0000 add RunRepo type alias
src/Types.hs Modified
@@ -28,6 +28,11 @@ import Text.Ginger.Run (Run) {- +Convenience type alias for the ginger run monad with git repo context. +-} +type RunRepo = Run SourcePos (ReaderT LgRepo IO) Html + +{- GVal implementation for a repository, accessed in the scope of an individual repository, as well as in a list of all repositories in the index template. -} @@ -129,8 +134,8 @@ GVal implementations for data definitions above, allowing commits to be rendered in Ginger templates. -} -instance ToGVal (Run SourcePos (ReaderT LgRepo IO) Html) TreeFile where - toGVal :: TreeFile -> GVal (Run SourcePos (ReaderT LgRepo IO) Html) +instance ToGVal RunRepo TreeFile where + toGVal :: TreeFile -> GVal RunRepo toGVal treefile = def { asHtml = html . pack . toString . treeFilePath $ treefile @@ -139,8 +144,8 @@ , asBoolean = True -- Used for conditionally checking readme/license template variables. } -instance ToGVal (Run SourcePos (ReaderT LgRepo IO) Html) TreeFileContents where - toGVal :: TreeFileContents -> GVal (Run SourcePos (ReaderT LgRepo IO) Html) +instance ToGVal RunRepo TreeFileContents where + toGVal :: TreeFileContents -> GVal RunRepo toGVal (FileContents text) = toGVal text toGVal (FolderContents treeFiles) = def @@ -149,7 +154,7 @@ , asList = Just . fmap toGVal $ treeFiles } -treeAsLookup :: TreeFile -> Text -> Maybe (GVal (Run SourcePos (ReaderT LgRepo IO) Html)) +treeAsLookup :: TreeFile -> Text -> Maybe (GVal RunRepo) treeAsLookup treefile = \case "path" -> Just . toGVal . treeFilePath $ treefile "href" -> Just . toGVal . treePathToHref . treeFilePath $ treefile @@ -179,8 +184,8 @@ , refCommit :: Commit LgRepo } -instance ToGVal m Ref where - toGVal :: Ref -> GVal m +instance ToGVal RunRepo Ref where + toGVal :: Ref -> GVal RunRepo toGVal ref = def { asHtml = html . refName $ ref @@ -188,7 +193,7 @@ , asLookup = Just . refAsLookup $ ref } -refAsLookup :: Ref -> Text -> Maybe (GVal m) +refAsLookup :: Ref -> Text -> Maybe (GVal RunRepo) refAsLookup ref = \case "name" -> Just . toGVal . refName $ ref "commit" -> Just . toGVal . refCommit $ ref
src/Templates.hs Modified
@@ -36,9 +36,10 @@ import Text.Ginger.GVal (GVal) import Text.Ginger.Html (Html, htmlSource) import Text.Ginger.Parse (SourcePos, parseGingerFile, peErrorMessage) -import Text.Ginger.Run (Run, easyContext, runGingerT) +import Text.Ginger.Run (easyContext, runGingerT) import Config +import Types {- The Env data type represents all of the program's state, including user configuration @@ -88,7 +89,7 @@ -} generate :: FilePath -> - HashMap.HashMap Text (GVal (Run SourcePos (ReaderT LgRepo IO) Html)) -> + HashMap.HashMap Text (GVal RunRepo) -> Template -> ReaderT LgRepo IO () generate output context template = do
src/Repositories.hs Modified
@@ -26,9 +26,6 @@ import System.FilePath (takeFileName, (</>)) import System.IO.Error (tryIOError) import Text.Ginger.GVal (GVal, ToGVal, toGVal) -import Text.Ginger.Html (Html) -import Text.Ginger.Parse (SourcePos) -import Text.Ginger.Run (Run) import Config import Templates @@ -114,7 +111,7 @@ [TreeFile] -> [Ref] -> [Ref] -> - HashMap.HashMap Text (GVal (Run SourcePos (ReaderT LgRepo IO) Html)) + HashMap.HashMap Text (GVal RunRepo) package env name description commits tree tags branches = HashMap.fromList [ ("host", toGVal . host . envConfig $ env) @@ -194,7 +191,7 @@ let names'' = map (fromJust . stripPrefix ref) . catMaybes . zipWith dropName maybeCommits $ names' return . zipWith Ref names'' . catMaybes $ maybeCommits where - refObjToCommit :: Object r m -> ReaderT LgRepo IO (Maybe (Commit r)) + refObjToCommit :: Object r (ReaderT LgRepo IO) -> ReaderT LgRepo IO (Maybe (Commit r)) refObjToCommit (CommitObj obj) = return . Just $ obj refObjToCommit _ = return Nothing @@ -204,7 +201,7 @@ genRepo :: FilePath -> - HashMap.HashMap Text (GVal (Run SourcePos (ReaderT LgRepo IO) Html)) -> + HashMap.HashMap Text (GVal RunRepo) -> Template -> ReaderT LgRepo IO () genRepo output scope template = generate output' scope template @@ -221,7 +218,7 @@ commitTemplate. The Target class generalises how each target is represented so that genTarget can work on any target type. -} -class ToGVal (Run SourcePos (ReaderT LgRepo IO) Html) a => Target a where +class ToGVal RunRepo a => Target a where identify :: a -> FilePath category :: a -> FilePath @@ -236,7 +233,7 @@ genTarget :: Target a => FilePath -> - HashMap.HashMap Text (GVal (Run SourcePos (ReaderT LgRepo IO) Html)) -> + HashMap.HashMap Text (GVal RunRepo) -> Bool -> Maybe Template -> a ->