🐙 Templated web page generator for your git repositories
git clone https://github.com/m-col/gitja
Files | Refs | Readme | License

Commit 39841ff9c9d9643f7081141099f0a902d4f13dd7
Parent: e1bd7034724d08b208da2059208f37a5b2005785
Author: mcol <mcol@posteo.net>
Date: 2021-09-24 23:46:41 +0100
Committer: mcol <mcol@posteo.net>
Committed: 2021-09-24 23:46:41 +0100

Add GVal instance for tree items

src/Repositories.hs Modified

@@ -94,7 +94,7 @@
     , ("name", toGVal $ pack name)
     , ("description", toGVal description)
     , ("commits", toGVal commits)
-    , ("tree", toGVal ("tree" :: String))
+    , ("tree", toGVal tree)
     ]
 
 getCommits :: CommitOid LgRepo -> ReaderT LgRepo IO [Commit LgRepo]
@@ -121,8 +121,6 @@
 
 {-
 Here we define how commits can be accessed and represented in Ginger templates.
-
-This is an orphan instance but we can let it slide.
 -}
 instance ToGVal m (Commit LgRepo) where
     toGVal :: Commit LgRepo -> GVal m
@@ -145,3 +143,20 @@
     "committed" -> Just . toGVal . show . signatureWhen . commitCommitter $ commit
     "encoding" -> Just . toGVal . strip . commitEncoding $ commit
     _ -> Nothing
+
+
+{-
+Here we define how files in the tree can be accessed by Ginger templates.
+-}
+instance ToGVal m TreeFile where
+    toGVal :: TreeFile -> GVal m
+    toGVal treefile = def
+        { asHtml = html . pack . show . treeFilePath $ treefile
+        , asText = pack . show . treeFilePath $ treefile
+        , asLookup = Just . treeAsLookup $ treefile
+        }
+
+treeAsLookup :: TreeFile -> Text -> Maybe (GVal m)
+treeAsLookup treefile = \case
+    "path" -> Just . toGVal . treeFilePath $ treefile
+    _ -> Nothing