From 18aa098f50e2a2c7db01dd4d04dde460fd40f5d5 Mon Sep 17 00:00:00 2001 From: "Gabriel A. Giovanini" Date: Fri, 7 Jun 2024 14:02:25 +0200 Subject: feat: Add blob endpoint --- templates/base.qtpl | 5 ++ templates/base.qtpl.go | 145 ++++++++++++++++++++++-------------------- templates/gititemblob.qtpl | 14 ++++ templates/gititemblob.qtpl.go | 98 ++++++++++++++++++++++++++++ templates/gititemtree.qtpl | 20 +++++- templates/gititemtree.qtpl.go | 145 ++++++++++++++++++++++++++++++++---------- templates/navbar.qtpl | 3 + templates/navbar.qtpl.go | 134 +++++++++++++++++++------------------- 8 files changed, 392 insertions(+), 172 deletions(-) create mode 100644 templates/gititemblob.qtpl create mode 100644 templates/gititemblob.qtpl.go (limited to 'templates') diff --git a/templates/base.qtpl b/templates/base.qtpl index 16b8780..180b1ab 100644 --- a/templates/base.qtpl +++ b/templates/base.qtpl @@ -30,6 +30,11 @@ Page { } %} +{% code func Ignore[T any](v T, _ error) T { + return v + } +%} + Page prints a page implementing Page interface. {% func PageTemplate(p Page) %} diff --git a/templates/base.qtpl.go b/templates/base.qtpl.go index 6d4d0a0..c5570c8 100644 --- a/templates/base.qtpl.go +++ b/templates/base.qtpl.go @@ -71,174 +71,179 @@ func TimeFormat(t time.Time) string { return t.Format("2006-01-02") } +//line base.qtpl:33 +func Ignore[T any](v T, _ error) T { + return v +} + // Page prints a page implementing Page interface. -//line base.qtpl:34 +//line base.qtpl:39 func StreamPageTemplate(qw422016 *qt422016.Writer, p Page) { -//line base.qtpl:34 +//line base.qtpl:39 qw422016.N().S(` cerrado | `) -//line base.qtpl:39 +//line base.qtpl:44 p.StreamTitle(qw422016) -//line base.qtpl:39 +//line base.qtpl:44 qw422016.N().S(` `) -//line base.qtpl:44 +//line base.qtpl:49 p.StreamNavbar(qw422016) -//line base.qtpl:44 +//line base.qtpl:49 qw422016.N().S(`
`) -//line base.qtpl:46 +//line base.qtpl:51 p.StreamContent(qw422016) -//line base.qtpl:46 +//line base.qtpl:51 qw422016.N().S(`
`) -//line base.qtpl:49 +//line base.qtpl:54 p.StreamScript(qw422016) -//line base.qtpl:49 +//line base.qtpl:54 qw422016.N().S(` `) -//line base.qtpl:51 +//line base.qtpl:56 } -//line base.qtpl:51 +//line base.qtpl:56 func WritePageTemplate(qq422016 qtio422016.Writer, p Page) { -//line base.qtpl:51 +//line base.qtpl:56 qw422016 := qt422016.AcquireWriter(qq422016) -//line base.qtpl:51 +//line base.qtpl:56 StreamPageTemplate(qw422016, p) -//line base.qtpl:51 +//line base.qtpl:56 qt422016.ReleaseWriter(qw422016) -//line base.qtpl:51 +//line base.qtpl:56 } -//line base.qtpl:51 +//line base.qtpl:56 func PageTemplate(p Page) string { -//line base.qtpl:51 +//line base.qtpl:56 qb422016 := qt422016.AcquireByteBuffer() -//line base.qtpl:51 +//line base.qtpl:56 WritePageTemplate(qb422016, p) -//line base.qtpl:51 +//line base.qtpl:56 qs422016 := string(qb422016.B) -//line base.qtpl:51 +//line base.qtpl:56 qt422016.ReleaseByteBuffer(qb422016) -//line base.qtpl:51 +//line base.qtpl:56 return qs422016 -//line base.qtpl:51 +//line base.qtpl:56 } -//line base.qtpl:53 +//line base.qtpl:58 type BasePage struct{} -//line base.qtpl:54 +//line base.qtpl:59 func (p *BasePage) StreamTitle(qw422016 *qt422016.Writer) { -//line base.qtpl:54 +//line base.qtpl:59 qw422016.N().S(`Empty`) -//line base.qtpl:54 +//line base.qtpl:59 } -//line base.qtpl:54 +//line base.qtpl:59 func (p *BasePage) WriteTitle(qq422016 qtio422016.Writer) { -//line base.qtpl:54 +//line base.qtpl:59 qw422016 := qt422016.AcquireWriter(qq422016) -//line base.qtpl:54 +//line base.qtpl:59 p.StreamTitle(qw422016) -//line base.qtpl:54 +//line base.qtpl:59 qt422016.ReleaseWriter(qw422016) -//line base.qtpl:54 +//line base.qtpl:59 } -//line base.qtpl:54 +//line base.qtpl:59 func (p *BasePage) Title() string { -//line base.qtpl:54 +//line base.qtpl:59 qb422016 := qt422016.AcquireByteBuffer() -//line base.qtpl:54 +//line base.qtpl:59 p.WriteTitle(qb422016) -//line base.qtpl:54 +//line base.qtpl:59 qs422016 := string(qb422016.B) -//line base.qtpl:54 +//line base.qtpl:59 qt422016.ReleaseByteBuffer(qb422016) -//line base.qtpl:54 +//line base.qtpl:59 return qs422016 -//line base.qtpl:54 +//line base.qtpl:59 } -//line base.qtpl:55 +//line base.qtpl:60 func (p *BasePage) StreamBody(qw422016 *qt422016.Writer) { -//line base.qtpl:55 +//line base.qtpl:60 qw422016.N().S(`HelloWorld`) -//line base.qtpl:55 +//line base.qtpl:60 } -//line base.qtpl:55 +//line base.qtpl:60 func (p *BasePage) WriteBody(qq422016 qtio422016.Writer) { -//line base.qtpl:55 +//line base.qtpl:60 qw422016 := qt422016.AcquireWriter(qq422016) -//line base.qtpl:55 +//line base.qtpl:60 p.StreamBody(qw422016) -//line base.qtpl:55 +//line base.qtpl:60 qt422016.ReleaseWriter(qw422016) -//line base.qtpl:55 +//line base.qtpl:60 } -//line base.qtpl:55 +//line base.qtpl:60 func (p *BasePage) Body() string { -//line base.qtpl:55 +//line base.qtpl:60 qb422016 := qt422016.AcquireByteBuffer() -//line base.qtpl:55 +//line base.qtpl:60 p.WriteBody(qb422016) -//line base.qtpl:55 +//line base.qtpl:60 qs422016 := string(qb422016.B) -//line base.qtpl:55 +//line base.qtpl:60 qt422016.ReleaseByteBuffer(qb422016) -//line base.qtpl:55 +//line base.qtpl:60 return qs422016 -//line base.qtpl:55 +//line base.qtpl:60 } -//line base.qtpl:56 +//line base.qtpl:61 func (p *BasePage) StreamScript(qw422016 *qt422016.Writer) { -//line base.qtpl:56 +//line base.qtpl:61 } -//line base.qtpl:56 +//line base.qtpl:61 func (p *BasePage) WriteScript(qq422016 qtio422016.Writer) { -//line base.qtpl:56 +//line base.qtpl:61 qw422016 := qt422016.AcquireWriter(qq422016) -//line base.qtpl:56 +//line base.qtpl:61 p.StreamScript(qw422016) -//line base.qtpl:56 +//line base.qtpl:61 qt422016.ReleaseWriter(qw422016) -//line base.qtpl:56 +//line base.qtpl:61 } -//line base.qtpl:56 +//line base.qtpl:61 func (p *BasePage) Script() string { -//line base.qtpl:56 +//line base.qtpl:61 qb422016 := qt422016.AcquireByteBuffer() -//line base.qtpl:56 +//line base.qtpl:61 p.WriteScript(qb422016) -//line base.qtpl:56 +//line base.qtpl:61 qs422016 := string(qb422016.B) -//line base.qtpl:56 +//line base.qtpl:61 qt422016.ReleaseByteBuffer(qb422016) -//line base.qtpl:56 +//line base.qtpl:61 return qs422016 -//line base.qtpl:56 +//line base.qtpl:61 } diff --git a/templates/gititemblob.qtpl b/templates/gititemblob.qtpl new file mode 100644 index 0000000..89d002d --- /dev/null +++ b/templates/gititemblob.qtpl @@ -0,0 +1,14 @@ +{% code +type GitItemBlobPage struct { + File string + Content []byte +} +%} + +{% func (g *GitItemBlobPage) Nav(name, ref string) %}{%= GitItemNav(name, ref, Tree) %}{% endfunc %} + +{% func (g *GitItemBlobPage) GitContent() %} +
+{%z= g.Content %} +
+{% endfunc %} diff --git a/templates/gititemblob.qtpl.go b/templates/gititemblob.qtpl.go new file mode 100644 index 0000000..6b4e187 --- /dev/null +++ b/templates/gititemblob.qtpl.go @@ -0,0 +1,98 @@ +// Code generated by qtc from "gititemblob.qtpl". DO NOT EDIT. +// See https://github.com/valyala/quicktemplate for details. + +//line gititemblob.qtpl:1 +package templates + +//line gititemblob.qtpl:1 +import ( + qtio422016 "io" + + qt422016 "github.com/valyala/quicktemplate" +) + +//line gititemblob.qtpl:1 +var ( + _ = qtio422016.Copy + _ = qt422016.AcquireByteBuffer +) + +//line gititemblob.qtpl:2 +type GitItemBlobPage struct { + File string + Content []byte +} + +//line gititemblob.qtpl:8 +func (g *GitItemBlobPage) StreamNav(qw422016 *qt422016.Writer, name, ref string) { +//line gititemblob.qtpl:8 + StreamGitItemNav(qw422016, name, ref, Tree) +//line gititemblob.qtpl:8 +} + +//line gititemblob.qtpl:8 +func (g *GitItemBlobPage) WriteNav(qq422016 qtio422016.Writer, name, ref string) { +//line gititemblob.qtpl:8 + qw422016 := qt422016.AcquireWriter(qq422016) +//line gititemblob.qtpl:8 + g.StreamNav(qw422016, name, ref) +//line gititemblob.qtpl:8 + qt422016.ReleaseWriter(qw422016) +//line gititemblob.qtpl:8 +} + +//line gititemblob.qtpl:8 +func (g *GitItemBlobPage) Nav(name, ref string) string { +//line gititemblob.qtpl:8 + qb422016 := qt422016.AcquireByteBuffer() +//line gititemblob.qtpl:8 + g.WriteNav(qb422016, name, ref) +//line gititemblob.qtpl:8 + qs422016 := string(qb422016.B) +//line gititemblob.qtpl:8 + qt422016.ReleaseByteBuffer(qb422016) +//line gititemblob.qtpl:8 + return qs422016 +//line gititemblob.qtpl:8 +} + +//line gititemblob.qtpl:10 +func (g *GitItemBlobPage) StreamGitContent(qw422016 *qt422016.Writer) { +//line gititemblob.qtpl:10 + qw422016.N().S(` +
+`) +//line gititemblob.qtpl:12 + qw422016.N().Z(g.Content) +//line gititemblob.qtpl:12 + qw422016.N().S(` +
+`) +//line gititemblob.qtpl:14 +} + +//line gititemblob.qtpl:14 +func (g *GitItemBlobPage) WriteGitContent(qq422016 qtio422016.Writer) { +//line gititemblob.qtpl:14 + qw422016 := qt422016.AcquireWriter(qq422016) +//line gititemblob.qtpl:14 + g.StreamGitContent(qw422016) +//line gititemblob.qtpl:14 + qt422016.ReleaseWriter(qw422016) +//line gititemblob.qtpl:14 +} + +//line gititemblob.qtpl:14 +func (g *GitItemBlobPage) GitContent() string { +//line gititemblob.qtpl:14 + qb422016 := qt422016.AcquireByteBuffer() +//line gititemblob.qtpl:14 + g.WriteGitContent(qb422016) +//line gititemblob.qtpl:14 + qs422016 := string(qb422016.B) +//line gititemblob.qtpl:14 + qt422016.ReleaseByteBuffer(qb422016) +//line gititemblob.qtpl:14 + return qs422016 +//line gititemblob.qtpl:14 +} diff --git a/templates/gititemtree.qtpl b/templates/gititemtree.qtpl index 5ace7b0..be7a27d 100644 --- a/templates/gititemtree.qtpl +++ b/templates/gititemtree.qtpl @@ -1,10 +1,28 @@ +{% import "github.com/go-git/go-git/v5/plumbing/object" %} + {% code type GitItemTreePage struct { + CurrentPath string + Tree *object.Tree + + // TODO: remove this since it can be passed by GitCommit + Ref string + Name string } %} {% func (g *GitItemTreePage) Nav(name, ref string) %}{%= GitItemNav(name, ref, Tree) %}{% endfunc %} {% func (g *GitItemTreePage) GitContent() %} -

Tree

+{% for _, e := range g.Tree.Entries %} +
+
{%s Ignore(e.Mode.ToOSFileMode()).String() %}
+ {% if e.Mode.IsFile() %} + + {% else %} + + {% endif %} +
{%dl Ignore(g.Tree.Size(e.Name))%} KiB
+
+{% endfor %} {% endfunc %} diff --git a/templates/gititemtree.qtpl.go b/templates/gititemtree.qtpl.go index d8beb0e..cdc374f 100644 --- a/templates/gititemtree.qtpl.go +++ b/templates/gititemtree.qtpl.go @@ -5,86 +5,165 @@ package templates //line gititemtree.qtpl:1 +import "github.com/go-git/go-git/v5/plumbing/object" + +//line gititemtree.qtpl:3 import ( qtio422016 "io" qt422016 "github.com/valyala/quicktemplate" ) -//line gititemtree.qtpl:1 +//line gititemtree.qtpl:3 var ( _ = qtio422016.Copy _ = qt422016.AcquireByteBuffer ) -//line gititemtree.qtpl:2 +//line gititemtree.qtpl:4 type GitItemTreePage struct { + CurrentPath string + Tree *object.Tree + + // TODO: remove this since it can be passed by GitCommit + Ref string + Name string } -//line gititemtree.qtpl:6 +//line gititemtree.qtpl:14 func (g *GitItemTreePage) StreamNav(qw422016 *qt422016.Writer, name, ref string) { -//line gititemtree.qtpl:6 +//line gititemtree.qtpl:14 StreamGitItemNav(qw422016, name, ref, Tree) -//line gititemtree.qtpl:6 +//line gititemtree.qtpl:14 } -//line gititemtree.qtpl:6 +//line gititemtree.qtpl:14 func (g *GitItemTreePage) WriteNav(qq422016 qtio422016.Writer, name, ref string) { -//line gititemtree.qtpl:6 +//line gititemtree.qtpl:14 qw422016 := qt422016.AcquireWriter(qq422016) -//line gititemtree.qtpl:6 +//line gititemtree.qtpl:14 g.StreamNav(qw422016, name, ref) -//line gititemtree.qtpl:6 +//line gititemtree.qtpl:14 qt422016.ReleaseWriter(qw422016) -//line gititemtree.qtpl:6 +//line gititemtree.qtpl:14 } -//line gititemtree.qtpl:6 +//line gititemtree.qtpl:14 func (g *GitItemTreePage) Nav(name, ref string) string { -//line gititemtree.qtpl:6 +//line gititemtree.qtpl:14 qb422016 := qt422016.AcquireByteBuffer() -//line gititemtree.qtpl:6 +//line gititemtree.qtpl:14 g.WriteNav(qb422016, name, ref) -//line gititemtree.qtpl:6 +//line gititemtree.qtpl:14 qs422016 := string(qb422016.B) -//line gititemtree.qtpl:6 +//line gititemtree.qtpl:14 qt422016.ReleaseByteBuffer(qb422016) -//line gititemtree.qtpl:6 +//line gititemtree.qtpl:14 return qs422016 -//line gititemtree.qtpl:6 +//line gititemtree.qtpl:14 } -//line gititemtree.qtpl:8 +//line gititemtree.qtpl:16 func (g *GitItemTreePage) StreamGitContent(qw422016 *qt422016.Writer) { -//line gititemtree.qtpl:8 +//line gititemtree.qtpl:16 + qw422016.N().S(` +`) +//line gititemtree.qtpl:17 + for _, e := range g.Tree.Entries { +//line gititemtree.qtpl:17 + qw422016.N().S(` +
+
`) +//line gititemtree.qtpl:19 + qw422016.E().S(Ignore(e.Mode.ToOSFileMode()).String()) +//line gititemtree.qtpl:19 + qw422016.N().S(`
+ `) +//line gititemtree.qtpl:20 + if e.Mode.IsFile() { +//line gititemtree.qtpl:20 + qw422016.N().S(` + + `) +//line gititemtree.qtpl:22 + } else { +//line gititemtree.qtpl:22 + qw422016.N().S(` + + `) +//line gititemtree.qtpl:24 + } +//line gititemtree.qtpl:24 + qw422016.N().S(` +
`) +//line gititemtree.qtpl:25 + qw422016.N().DL(Ignore(g.Tree.Size(e.Name))) +//line gititemtree.qtpl:25 + qw422016.N().S(` KiB
+
+`) +//line gititemtree.qtpl:27 + } +//line gititemtree.qtpl:27 qw422016.N().S(` -

Tree

`) -//line gititemtree.qtpl:10 +//line gititemtree.qtpl:28 } -//line gititemtree.qtpl:10 +//line gititemtree.qtpl:28 func (g *GitItemTreePage) WriteGitContent(qq422016 qtio422016.Writer) { -//line gititemtree.qtpl:10 +//line gititemtree.qtpl:28 qw422016 := qt422016.AcquireWriter(qq422016) -//line gititemtree.qtpl:10 +//line gititemtree.qtpl:28 g.StreamGitContent(qw422016) -//line gititemtree.qtpl:10 +//line gititemtree.qtpl:28 qt422016.ReleaseWriter(qw422016) -//line gititemtree.qtpl:10 +//line gititemtree.qtpl:28 } -//line gititemtree.qtpl:10 +//line gititemtree.qtpl:28 func (g *GitItemTreePage) GitContent() string { -//line gititemtree.qtpl:10 +//line gititemtree.qtpl:28 qb422016 := qt422016.AcquireByteBuffer() -//line gititemtree.qtpl:10 +//line gititemtree.qtpl:28 g.WriteGitContent(qb422016) -//line gititemtree.qtpl:10 +//line gititemtree.qtpl:28 qs422016 := string(qb422016.B) -//line gititemtree.qtpl:10 +//line gititemtree.qtpl:28 qt422016.ReleaseByteBuffer(qb422016) -//line gititemtree.qtpl:10 +//line gititemtree.qtpl:28 return qs422016 -//line gititemtree.qtpl:10 +//line gititemtree.qtpl:28 } diff --git a/templates/navbar.qtpl b/templates/navbar.qtpl index 775f496..9681fa4 100644 --- a/templates/navbar.qtpl +++ b/templates/navbar.qtpl @@ -25,7 +25,10 @@ const ( `) -//line navbar.qtpl:33 +//line navbar.qtpl:36 } -//line navbar.qtpl:33 +//line navbar.qtpl:36 func WriteNavbar(qq422016 qtio422016.Writer, s Selection) { -//line navbar.qtpl:33 +//line navbar.qtpl:36 qw422016 := qt422016.AcquireWriter(qq422016) -//line navbar.qtpl:33 +//line navbar.qtpl:36 StreamNavbar(qw422016, s) -//line navbar.qtpl:33 +//line navbar.qtpl:36 qt422016.ReleaseWriter(qw422016) -//line navbar.qtpl:33 +//line navbar.qtpl:36 } -//line navbar.qtpl:33 +//line navbar.qtpl:36 func Navbar(s Selection) string { -//line navbar.qtpl:33 +//line navbar.qtpl:36 qb422016 := qt422016.AcquireByteBuffer() -//line navbar.qtpl:33 +//line navbar.qtpl:36 WriteNavbar(qb422016, s) -//line navbar.qtpl:33 +//line navbar.qtpl:36 qs422016 := string(qb422016.B) -//line navbar.qtpl:33 +//line navbar.qtpl:36 qt422016.ReleaseByteBuffer(qb422016) -//line navbar.qtpl:33 +//line navbar.qtpl:36 return qs422016 -//line navbar.qtpl:33 +//line navbar.qtpl:36 } -//line navbar.qtpl:35 +//line navbar.qtpl:38 func StreamGitItemNav(qw422016 *qt422016.Writer, name, ref string, s GitSelection) { -//line navbar.qtpl:35 +//line navbar.qtpl:38 qw422016.N().S(`

`) -//line navbar.qtpl:37 +//line navbar.qtpl:40 qw422016.E().S(name) -//line navbar.qtpl:37 +//line navbar.qtpl:40 qw422016.N().S(` `) -//line navbar.qtpl:37 +//line navbar.qtpl:40 if ref != "" && (s == Log || s == Tree) { -//line navbar.qtpl:37 +//line navbar.qtpl:40 qw422016.N().S(`@ `) -//line navbar.qtpl:37 +//line navbar.qtpl:40 qw422016.E().S(ref) -//line navbar.qtpl:37 +//line navbar.qtpl:40 } -//line navbar.qtpl:37 +//line navbar.qtpl:40 qw422016.N().S(`

`) -//line navbar.qtpl:58 +//line navbar.qtpl:61 } -//line navbar.qtpl:58 +//line navbar.qtpl:61 func WriteGitItemNav(qq422016 qtio422016.Writer, name, ref string, s GitSelection) { -//line navbar.qtpl:58 +//line navbar.qtpl:61 qw422016 := qt422016.AcquireWriter(qq422016) -//line navbar.qtpl:58 +//line navbar.qtpl:61 StreamGitItemNav(qw422016, name, ref, s) -//line navbar.qtpl:58 +//line navbar.qtpl:61 qt422016.ReleaseWriter(qw422016) -//line navbar.qtpl:58 +//line navbar.qtpl:61 } -//line navbar.qtpl:58 +//line navbar.qtpl:61 func GitItemNav(name, ref string, s GitSelection) string { -//line navbar.qtpl:58 +//line navbar.qtpl:61 qb422016 := qt422016.AcquireByteBuffer() -//line navbar.qtpl:58 +//line navbar.qtpl:61 WriteGitItemNav(qb422016, name, ref, s) -//line navbar.qtpl:58 +//line navbar.qtpl:61 qs422016 := string(qb422016.B) -//line navbar.qtpl:58 +//line navbar.qtpl:61 qt422016.ReleaseByteBuffer(qb422016) -//line navbar.qtpl:58 +//line navbar.qtpl:61 return qs422016 -//line navbar.qtpl:58 +//line navbar.qtpl:61 } -- cgit v1.2.3