all repos — elgit @ 9c336ff148d48d09a4f4866798511cdcce50202a

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

templates/tree.go (view raw)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
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))),
			),
		)})
}