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, 111 insertions(+), 0 deletions(-)

changed files
A templates/commit.go
@@ -0,0 +1,111 @@
+package templates + +import ( + "fmt" + + "github.com/bluekeyes/go-gitdiff/gitdiff" + "go.alanpearce.eu/elgit/git" + g "go.alanpearce.eu/gomponents" + . "go.alanpearce.eu/gomponents/html" +) + +// Commit renders a commit diff page +func Commit(data PageData, diff *git.NiceDiff) g.Node { + return Page(data, []g.Node{ + RepoHeader(data), + RenderNav(data), + Main( + Section(Class("commit"), + Pre(g.Text(diff.Commit.Message)), + Div(Class("commit-info"), + g.Text(diff.Commit.Author.Name+" "), + A(Href(fmt.Sprintf("mailto:%s", diff.Commit.Author.Email)), + Class("commit-email"), + g.Text(diff.Commit.Author.Email)), + Div(g.Text(diff.Commit.Author.When.Format("Mon, 02 Jan 2006 15:04:05 -0700"))), + ), + Div( + Strong(g.Text("commit")), + P(A(Href(fmt.Sprintf("/%s/commit/%s", data.Name, diff.Commit.This)), + Class("commit-hash"), + g.Text(diff.Commit.This))), + ), + g.If(diff.Commit.Parent != "", + Div( + Strong(g.Text("parent")), + P(A(Href(fmt.Sprintf("/%s/commit/%s", data.Name, diff.Commit.Parent)), + Class("commit-hash"), + g.Text(diff.Commit.Parent))), + ), + ), + Div(Class("diff-stat"), + Div(g.Textf("%d files changed, %d insertions(+), %d deletions(-)", + diff.Stat.FilesChanged, diff.Stat.Insertions, diff.Stat.Deletions)), + Div( + Br(), + Strong(g.Text("jump to")), + Ul(g.Map(diff.Diff, func(d git.Diff) g.Node { + return Li(A(Href("#"+d.Name.New), g.Text(d.Name.New))) + })), + ), + ), + ), + Section( + g.Map(diff.Diff, func(d git.Diff) g.Node { + return Div(ID(d.Name.New), + Div(Class("diff"), + g.If(d.IsNew, + Span(Class("diff-type"), g.Text("A")), + g.If(d.IsDelete, + Span(Class("diff-type"), g.Text("D")), + Span(Class("diff-type"), g.Text("M")), + ), + ), + g.Text(" "), + g.If(d.Name.Old != "", + g.Group{ + A(Href(fmt.Sprintf("/%s/blob/%s/%s", data.Name, diff.Commit.Parent, d.Name.Old)), + g.Text(d.Name.Old)), + g.If(d.Name.New != "", + g.Group{ + g.Text(" → "), + A( + Href( + fmt.Sprintf("/%s/blob/%s/%s", data.Name, diff.Commit.This, d.Name.New), + ), + g.Text(d.Name.New), + ), + }, + ), + }, + A(Href(fmt.Sprintf("/%s/blob/%s/%s", data.Name, diff.Commit.This, d.Name.New)), + g.Text(d.Name.New)), + ), + g.If(d.IsBinary, + P(g.Text("Not showing binary file.")), + Pre( + g.Group(g.Map(d.TextFragments, func(tf git.TextFragment) g.Node { + return g.Group( + []g.Node{ + Span(g.Attr("style", "display: block"), g.Text(tf.Header)), + g.Map(tf.Lines, func(line gitdiff.Line) g.Node { + switch line.Op.String() { + case "+": + return Span(Class("diff-add"), g.Text(line.String())) + case "-": + return Span(Class("diff-del"), g.Text(line.String())) + default: + return Span(Class("diff-noop"), g.Text(line.String())) + } + }), + }) + })), + ), + ), + ), + ) + })..., + ), + ), + }) +}