all repos — elgit @ 74eea2ebbccc8458b5b62002d281b2b49f5c30c4

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

switch to gomponents

Alan Pearce
commit

74eea2ebbccc8458b5b62002d281b2b49f5c30c4

parent

776a7b0dafa651c5ba71381608e9726d9756c3b1

1 file changed, 44 insertions(+), 0 deletions(-)

changed files
A templates/file.go
@@ -0,0 +1,44 @@
+package templates + +import ( + "fmt" + + g "go.alanpearce.eu/gomponents" + . "go.alanpearce.eu/gomponents/html" +) + +// File renders a file view page +func File(data PageData, chroma bool) g.Node { + return Page(data, []g.Node{ + RepoHeader(data), + RenderNav(data), + Main( + P(g.Text(data.Path), g.Text(" ("), A(Href("?raw=true"), g.Text("view raw")), g.Text(")")), + g.If(chroma, + Div(Class("chroma-file-wrapper"), g.Raw(data.Content)), + Div(Class("file-wrapper"), + Table( + TBody( + Tr( + Td(Class("line-numbers"), + Pre(g.Map(data.LineCount, func(line int) g.Node { + return g.Group([]g.Node{ + g.Text("\n"), + A( + ID(fmt.Sprintf("L%d", line)), + Href(fmt.Sprintf("#L%d", line)), + g.Text(fmt.Sprintf("%d", line)), + )}) + })), + ), + Td(Class("file-content"), + Pre(g.Text(data.Content)), + ), + ), + ), + ), + ), + ), + ), + }) +}