mirror of
https://github.com/samsonjs/retrogit.git
synced 2026-03-25 09:25:49 +00:00
Move digest rendering into its own template.
This commit is contained in:
parent
63982d15d9
commit
1ffac114ff
4 changed files with 37 additions and 25 deletions
|
|
@ -52,8 +52,7 @@ func init() {
|
|||
http.Handle("/", router)
|
||||
}
|
||||
|
||||
var indexTemplate = template.Must(template.ParseFiles("templates/index.html"))
|
||||
var indexSignedOutTemplate = template.Must(template.ParseFiles("templates/index-signed-out.html"))
|
||||
var templates = template.Must(template.ParseGlob("templates/*.html"))
|
||||
|
||||
func signInHandler(w http.ResponseWriter, r *http.Request) {
|
||||
http.Redirect(w, r, githubOauthConfig.AuthCodeURL(""), http.StatusFound)
|
||||
|
|
@ -75,7 +74,7 @@ func indexHandler(w http.ResponseWriter, r *http.Request) {
|
|||
var data = map[string]string{
|
||||
"SignInUrl": signInUrl.String(),
|
||||
}
|
||||
if err := indexSignedOutTemplate.Execute(w, data); err != nil {
|
||||
if err := templates.ExecuteTemplate(w, "index-signed-out", data); err != nil {
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
return
|
||||
|
|
@ -105,7 +104,7 @@ func indexHandler(w http.ResponseWriter, r *http.Request) {
|
|||
"SignOutUrl": signOutUrl.String(),
|
||||
"Digest": digest,
|
||||
}
|
||||
if err := indexTemplate.Execute(w, data); err != nil {
|
||||
if err := templates.ExecuteTemplate(w, "index", data); err != nil {
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
25
app/templates/digest.html
Normal file
25
app/templates/digest.html
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
{{define "digest"}}
|
||||
|
||||
{{.User.Login}}'s digest:
|
||||
<ul>
|
||||
{{range $index, $repoDigest := .RepoDigests}}
|
||||
<li>
|
||||
<a href="https://github.com/{{.Repo.FullName}}">
|
||||
{{.Repo.FullName}}
|
||||
</a>
|
||||
<ul>
|
||||
{{range .Commits }}
|
||||
<li>
|
||||
<code><a href="https://github.com/{{$repoDigest.Repo.FullName}}/commit/{{.SHA}}">{{.SHA}}</a></code>
|
||||
-
|
||||
<i>{{.Commit.Author.Date}}</i>
|
||||
<br>
|
||||
<pre>{{.Commit.Message}}</pre>
|
||||
</li>
|
||||
{{end}}
|
||||
</ul>
|
||||
</li>
|
||||
{{end}}
|
||||
</ul>
|
||||
|
||||
{{end}}
|
||||
|
|
@ -1,3 +1,5 @@
|
|||
{{define "index-signed-out"}}
|
||||
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
|
|
@ -13,3 +15,5 @@
|
|||
</a>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
{{end}}
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
{{define "index"}}
|
||||
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
|
|
@ -14,26 +16,8 @@
|
|||
</a>
|
||||
</p>
|
||||
|
||||
{{.Digest.User.Login}}'s digest:
|
||||
<ul>
|
||||
{{range $index, $repoDigest := .Digest.RepoDigests}}
|
||||
<li>
|
||||
<a href="https://github.com/{{.Repo.FullName}}">
|
||||
{{.Repo.FullName}}
|
||||
</a>
|
||||
<ul>
|
||||
{{range .Commits }}
|
||||
<li>
|
||||
<code><a href="https://github.com/{{$repoDigest.Repo.FullName}}/commit/{{.SHA}}">{{.SHA}}</a></code>
|
||||
-
|
||||
<i>{{.Commit.Author.Date}}</i>
|
||||
<br>
|
||||
<pre>{{.Commit.Message}}</pre>
|
||||
</li>
|
||||
{{end}}
|
||||
</ul>
|
||||
</li>
|
||||
{{end}}
|
||||
</ul>
|
||||
{{template "digest" .Digest}}
|
||||
</body>
|
||||
</html>
|
||||
|
||||
{{end}}
|
||||
|
|
|
|||
Loading…
Reference in a new issue