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

Commit 7260b794051d413c4975cd91554e4b72facb11fa
Parent: 2dabf0478cfe0a5a9c18d31ee955dfc2ebabaf93
Author: mcol <mcol@posteo.net>
Date: 2021-11-26 01:30:28 +0000
Committer: mcol <mcol@posteo.net>
Committed: 2021-11-26 01:30:28 +0000

complete test for file test

test/templates/repo/file.html Modified

@@ -2,5 +2,14 @@
 {%- block title -%}{{ file.path }}{%- endblock -%}
 
 {% block body %}
-file
+scope: file
+file: {{ file }}
+file.path: {{ file.path }}
+file.href: {{ file.href }}
+file.contents: {{ file.contents }}
+file.mode: {{ file.mode }}
+file.mode_octal: {{ file.mode_octal }}
+file.mode_symbolic: {{ file.mode_symbolic }}
+if file.is_directory then "directory" else "file":
+	{%- if file.is_directory %} "directory"{% else %} "file"{% endif %}
 {% endblock %}

test/expected/gitserve/file/test.templates.style.css.html Modified

@@ -1,2 +1,10 @@
 test/templates/style.css
-file
+scope: file
+file: test/templates/style.css
+file.path: test/templates/style.css
+file.href: test.templates.style.css.html
+file.contents: 👄
+file.mode: Plain
+file.mode_octal: 00644
+file.mode_symbolic: -rw-r--r--
+if file.is_directory then "directory" else "file": "file"
\ No newline at end of file

test/expected/gitserve/file/test.templates.html Added

@@ -0,0 +1,10 @@
+test/templates
+scope: file
+file: test/templates
+file.path: test/templates
+file.href: test.templates.html
+file.contents: [&quot;test/templates/index.html&quot;,&quot;test/templates/repo&quot;,&quot;test/templates/repo/commit.html&quot;,&quot;test/templates/repo/file.html&quot;,&quot;test/templates/repo/index.html&quot;,&quot;test/templates/static&quot;,&quot;test/templates/static/a_nice_file&quot;,&quot;test/templates/style.css&quot;,&quot;test/templates/title.html.include&quot;]
+file.mode: Directory
+file.mode_octal: 40000
+file.mode_symbolic: drwxr-xr-x
+if file.is_directory then "directory" else "file": "directory"
\ No newline at end of file

src/Types.hs Modified

@@ -50,22 +50,22 @@
     toGVal :: Repo -> GVal m
     toGVal repo =
         def
-            { asHtml = html . pack . init . showNoQuote . dirname . repositoryPath $ repo
+            { asHtml = html . pack . init . unquote . show . dirname . repositoryPath $ repo
             , asText = pack . show . dirname . repositoryPath $ repo
             , asLookup = Just . repoAsLookup $ repo
             }
 
+unquote :: String -> String
+unquote = init . tail
+
 repoAsLookup :: Repo -> Text -> Maybe (GVal m)
 repoAsLookup repo = \case
-    "name" -> Just . toGVal . init . showNoQuote . dirname . repositoryPath $ repo
+    "name" -> Just . toGVal . init . unquote . show . dirname . repositoryPath $ repo
     "description" -> Just . toGVal . repositoryDescription $ repo
     "head" -> Just . toGVal . repositoryHead $ repo
     "updated" -> toGVal . show . signatureWhen . commitCommitter <$> repositoryHead repo
     _ -> Nothing
 
-showNoQuote :: Show a => a -> String
-showNoQuote = tail . init . show
-
 {-
 GVal implementation for `Git.Commit r`, allowing commits to be rendered in Ginger
 templates.
@@ -110,9 +110,6 @@
 data TreeEntryMode = ModeDirectory | ModePlain | ModeExecutable | ModeSymlink | ModeSubmodule
     deriving stock (Show)
 
-showMode :: TreeEntryMode -> String
-showMode = drop 4 . show
-
 {-
 Some helper functions to convert from Haskell's LibGit2 BlobKind to our TreeEntryMode,
 and then from that to Git's octal representation, as seen when calling `git ls-tree
@@ -153,7 +150,7 @@
 
 instance ToGVal RunRepo TreeFileContents where
     toGVal :: TreeFileContents -> GVal RunRepo
-    toGVal (FileContents text) = toGVal text
+    toGVal (FileContents text) = toGVal . strip $ text
     toGVal (FolderContents treeFiles) =
         def
             { asHtml = html . pack . show . fmap (toString . treeFilePath) $ treeFiles
@@ -166,7 +163,7 @@
     "path" -> Just . toGVal . treeFilePath $ treefile
     "href" -> Just . toGVal . treePathToHref . treeFilePath $ treefile
     "contents" -> Just . toGVal . treeFileContents $ treefile
-    "mode" -> Just . toGVal . show . treeFileMode $ treefile
+    "mode" -> Just . toGVal . drop 4 . show . treeFileMode $ treefile
     "mode_octal" -> Just . toGVal . modeToOctal . treeFileMode $ treefile
     "mode_symbolic" -> Just . toGVal . modeToSymbolic . treeFileMode $ treefile
     "is_directory" -> Just . toGVal . treeFileIsDirectory $ treefile