diff options
author | Anirudh Oppiliappan <x@icyphox.sh> | 2022-12-11 14:18:39 +0530 |
---|---|---|
committer | Anirudh Oppiliappan <x@icyphox.sh> | 2022-12-11 14:18:39 +0530 |
commit | ac6ca71f01885b3fff692b4b9ee36ed33965d396 (patch) | |
tree | 6270a3a3c849df8b6fcbd95f9930f39a239e4cfb /routes/template.go | |
parent | ab30497e169cd3bfcd122e668c3cdde6bd48305b (diff) | |
download | legit-ac6ca71f01885b3fff692b4b9ee36ed33965d396.tar.gz legit-ac6ca71f01885b3fff692b4b9ee36ed33965d396.tar.bz2 legit-ac6ca71f01885b3fff692b4b9ee36ed33965d396.zip |
routes: file content view
Diffstat (limited to 'routes/template.go')
-rw-r--r-- | routes/template.go | 35 |
1 files changed, 29 insertions, 6 deletions
diff --git a/routes/template.go b/routes/template.go index 212ed21..5595f6e 100644 --- a/routes/template.go +++ b/routes/template.go @@ -2,11 +2,12 @@ package routes import ( "html/template" + "log" "net/http" - "os" "path/filepath" "icyphox.sh/legit/config" + "icyphox.sh/legit/git" ) func Write404(w http.ResponseWriter, c config.Config) { @@ -23,10 +24,32 @@ func Write500(w http.ResponseWriter, c config.Config) { t.Execute(w, nil) } -func funcMap() template.FuncMap { - return template.FuncMap{ - "prettyMode": func(mode uint32) string { - return os.FileMode(mode).String() - }, +func (d *deps) listFiles(files []git.NiceTree, w http.ResponseWriter) { + tpath := filepath.Join(d.c.Template.Dir, "*") + t := template.Must(template.ParseGlob(tpath)) + + data := make(map[string]interface{}) + data["files"] = files + data["meta"] = d.c.Meta + + if err := t.ExecuteTemplate(w, "repo", data); err != nil { + Write500(w, *d.c) + log.Println(err) + return + } +} + +func (d *deps) showFile(content string, w http.ResponseWriter) { + tpath := filepath.Join(d.c.Template.Dir, "*") + t := template.Must(template.ParseGlob(tpath)) + + data := make(map[string]interface{}) + data["content"] = content + data["meta"] = d.c.Meta + + if err := t.ExecuteTemplate(w, "file", data); err != nil { + Write500(w, *d.c) + log.Println(err) + return } } |