package templates import ( "fmt" "go.alanpearce.eu/elgit/git" g "go.alanpearce.eu/gomponents" . "go.alanpearce.eu/gomponents/html" ) // Tree renders a repository file tree view func Tree(data PageData, files []git.NiceTree, readme string, dotdot string) g.Node { return Page(data, []g.Node{ RepoHeader(data), RenderNav(data), Main( Div(Class("tree"), g.If(data.Parent != "", g.Group{ Div(), Div(), Div(A(Href(fmt.Sprintf("/%s/tree/%s/%s", data.Name, data.Ref, dotdot)), g.Text(".."))), }, ), g.Map(files, func(file git.NiceTree) g.Node { if !file.IsFile { return g.Group{ Div(Class("mode"), g.Text(file.Mode)), Div(Class("size"), g.Text(fmt.Sprintf("%d", file.Size))), Div( g.If(data.Parent != "", A( Href( fmt.Sprintf("/%s/tree/%s/%s/%s", data.Name, data.Ref, data.Parent, file.Name), ), g.Text(file.Name+"/"), ), A( Href(fmt.Sprintf("/%s/tree/%s/%s", data.Name, data.Ref, file.Name)), g.Text(file.Name+"/"), ), ), ), } } return nil }), g.Map(files, func(file git.NiceTree) g.Node { if file.IsFile { return g.Group{ Div(Class("mode"), g.Text(file.Mode)), Div(Class("size"), g.Text(fmt.Sprintf("%d", file.Size))), Div( g.If(data.Parent != "", A( Href( fmt.Sprintf("/%s/blob/%s/%s/%s", data.Name, data.Ref, data.Parent, file.Name), ), g.Text(file.Name), ), A( Href(fmt.Sprintf("/%s/blob/%s/%s", data.Name, data.Ref, file.Name)), g.Text(file.Name), ), ), ), } } return nil }), ), Article( g.If(readme != "", Pre(g.Raw(readme))), ), )}) }