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

Commit 993107b3a773d6db4272c3db0d75a93d3df4c9de
Parent: 4f438873fbc14a4f12794cdda78ee458a8ef7e4b
Author: mcol <mcol@posteo.net>
Date: 2022-04-14 19:24:12 +0100
Committer: mcol <mcol@posteo.net>
Committed: 2022-04-14 19:24:12 +0100

Narrow the scope of some Types helper functions

src/Types.hs Modified

@@ -176,6 +176,17 @@
     "lines" -> Just . toGVal . fmap makeLine . hunkLines $ hunk
     "header" -> Just . toGVal . bsToText . hunkHeader $ hunk
     _ -> Nothing
+  where
+    makeLine :: DiffLine -> Line
+    makeLine line =
+        let text = bsToText line
+         in Line text (cls . T.head $ text)
+
+    cls :: Char -> String
+    cls = \case
+        '+' -> "add"
+        '-' -> "sub"
+        _ -> "def"
 
 {-
 Wrap diff lines when accessed so that they can each get a class string indicating
@@ -187,16 +198,6 @@
     , lineClass :: String
     }
 
-makeLine :: DiffLine -> Line
-makeLine line = Line text (cls . T.head $ text)
-  where
-    text = bsToText line
-    cls :: Char -> String
-    cls = \case
-        '+' -> "add"
-        '-' -> "sub"
-        _ -> "def"
-
 instance ToGVal m Line where
     toGVal :: Line -> GVal m
     toGVal line =
@@ -237,20 +238,6 @@
 blobkindToMode Git.ExecutableBlob = ModeExecutable
 blobkindToMode Git.SymlinkBlob = ModeSymlink
 
-modeToOctal :: TreeEntryMode -> String
-modeToOctal ModeDirectory = "40000"
-modeToOctal ModePlain = "00644"
-modeToOctal ModeExecutable = "00755"
-modeToOctal ModeSymlink = "20000"
-modeToOctal ModeSubmodule = "60000"
-
-modeToSymbolic :: TreeEntryMode -> String
-modeToSymbolic ModeDirectory = "drwxr-xr-x"
-modeToSymbolic ModePlain = "-rw-r--r--"
-modeToSymbolic ModeExecutable = "-rwxr-xr-x"
-modeToSymbolic ModeSymlink = "l---------"
-modeToSymbolic ModeSubmodule = "git-module"
-
 {-
 This
 -}
@@ -308,26 +295,40 @@
     "is_binary" -> Just . toGVal . treeFileIsBinary $ treefile
     "is_directory" -> Just . toGVal . treeFileIsDirectory $ treefile
     _ -> Nothing
-
-treeFileGetTree :: Text -> TreeFileContents -> [TreeFile]
-treeFileGetTree parent (FolderContents fs) = filter atTop fs
   where
-    atTop = notElem FP.pathSeparator . drop 1 . T.unpack . fromMaybe "" . T.stripPrefix parent . treeFilePath
-treeFileGetTree _ _ = []
-
-treeFileGetTreeRecursive :: TreeFileContents -> [TreeFile]
-treeFileGetTreeRecursive (FolderContents fs) = fs
-treeFileGetTreeRecursive _ = []
-
-treeFileIsBinary :: TreeFile -> Bool
-treeFileIsBinary treefile = case treeFileContents treefile of
-    BinaryContents -> True
-    _ -> False
-
-treeFileIsDirectory :: TreeFile -> Bool
-treeFileIsDirectory treefile = case treeFileContents treefile of
-    FolderContents _ -> True
-    _ -> False
+    treeFileGetTree :: Text -> TreeFileContents -> [TreeFile]
+    treeFileGetTree parent (FolderContents fs) = filter atTop fs
+      where
+        atTop = notElem FP.pathSeparator . drop 1 . T.unpack . fromMaybe "" . T.stripPrefix parent . treeFilePath
+    treeFileGetTree _ _ = []
+
+    treeFileGetTreeRecursive :: TreeFileContents -> [TreeFile]
+    treeFileGetTreeRecursive (FolderContents fs) = fs
+    treeFileGetTreeRecursive _ = []
+
+    treeFileIsBinary :: TreeFile -> Bool
+    treeFileIsBinary treefile' = case treeFileContents treefile' of
+        BinaryContents -> True
+        _ -> False
+
+    treeFileIsDirectory :: TreeFile -> Bool
+    treeFileIsDirectory treefile' = case treeFileContents treefile' of
+        FolderContents _ -> True
+        _ -> False
+
+    modeToOctal :: TreeEntryMode -> String
+    modeToOctal ModeDirectory = "40000"
+    modeToOctal ModePlain = "00644"
+    modeToOctal ModeExecutable = "00755"
+    modeToOctal ModeSymlink = "20000"
+    modeToOctal ModeSubmodule = "60000"
+
+    modeToSymbolic :: TreeEntryMode -> String
+    modeToSymbolic ModeDirectory = "drwxr-xr-x"
+    modeToSymbolic ModePlain = "-rw-r--r--"
+    modeToSymbolic ModeExecutable = "-rwxr-xr-x"
+    modeToSymbolic ModeSymlink = "l---------"
+    modeToSymbolic ModeSubmodule = "git-module"
 
 {-
 Get the name of a tree file path's HTML file. Leading periods are dropped.