all repos — elgit @ ac6ca71f01885b3fff692b4b9ee36ed33965d396

fork of legit: web frontend for git, written in go

routes: file content view

commit

ac6ca71f01885b3fff692b4b9ee36ed33965d396

parent

ab30497e169cd3bfcd122e668c3cdde6bd48305b

1 file changed, 29 insertions(+), 6 deletions(-)

changed files
M routes/template.goroutes/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 @@ t := template.Must(template.ParseFiles(tpath))
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 } }