diff options
author | Lunny Xiao <xiaolunwen@gmail.com> | 2014-03-17 20:04:58 +0800 |
---|---|---|
committer | Lunny Xiao <xiaolunwen@gmail.com> | 2014-03-17 20:04:58 +0800 |
commit | a30e72323d1f8f6be7716a0548d99ef06807172b (patch) | |
tree | ea47ee0ed1836c47edd13267aefab1daf14fefe0 /modules | |
parent | 914ce405af975a6bf65cedd279e1bf75ca1671d5 (diff) | |
parent | 5bc2a1a6f98ae42ab5c30299d26082ffae54b859 (diff) |
merge
Diffstat (limited to 'modules')
-rw-r--r-- | modules/auth/repo.go | 7 | ||||
-rw-r--r-- | modules/base/conf.go | 2 | ||||
-rw-r--r-- | modules/base/markdown.go | 39 | ||||
-rw-r--r-- | modules/base/template.go | 4 | ||||
-rw-r--r-- | modules/base/tool.go | 30 | ||||
-rw-r--r-- | modules/middleware/repo.go | 5 |
6 files changed, 75 insertions, 12 deletions
diff --git a/modules/auth/repo.go b/modules/auth/repo.go index ac1b6b69..2cc93744 100644 --- a/modules/auth/repo.go +++ b/modules/auth/repo.go @@ -17,7 +17,6 @@ import ( ) type CreateRepoForm struct { - UserId int64 `form:"userId"` RepoName string `form:"repo" binding:"Required;AlphaDash"` Visibility string `form:"visibility"` Description string `form:"desc" binding:"MaxSize(100)"` @@ -52,9 +51,3 @@ func (f *CreateRepoForm) Validate(errors *binding.Errors, req *http.Request, con validate(errors, data, f) } - -type DeleteRepoForm struct { - UserId int64 `form:"userId" binding:"Required"` - UserName string `form:"userName" binding:"Required"` - RepoId int64 `form:"repoId" binding:"Required"` -} diff --git a/modules/base/conf.go b/modules/base/conf.go index f1508d7a..05412f38 100644 --- a/modules/base/conf.go +++ b/modules/base/conf.go @@ -18,6 +18,7 @@ import ( var ( AppVer string AppName string + Domain string Cfg *goconfig.ConfigFile ) @@ -58,4 +59,5 @@ func init() { Cfg.BlockMode = false AppName = Cfg.MustValue("", "APP_NAME") + Domain = Cfg.MustValue("server", "DOMAIN") } diff --git a/modules/base/markdown.go b/modules/base/markdown.go new file mode 100644 index 00000000..d170abe1 --- /dev/null +++ b/modules/base/markdown.go @@ -0,0 +1,39 @@ +// Copyright 2014 The Gogs Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + +package base + +import ( + "github.com/slene/blackfriday" +) + +func RenderMarkdown(rawBytes []byte) []byte { + htmlFlags := 0 + htmlFlags |= blackfriday.HTML_USE_XHTML + // htmlFlags |= blackfriday.HTML_USE_SMARTYPANTS + // htmlFlags |= blackfriday.HTML_SMARTYPANTS_FRACTIONS + // htmlFlags |= blackfriday.HTML_SMARTYPANTS_LATEX_DASHES + htmlFlags |= blackfriday.HTML_SKIP_HTML + htmlFlags |= blackfriday.HTML_SKIP_STYLE + htmlFlags |= blackfriday.HTML_SKIP_SCRIPT + htmlFlags |= blackfriday.HTML_GITHUB_BLOCKCODE + htmlFlags |= blackfriday.HTML_OMIT_CONTENTS + htmlFlags |= blackfriday.HTML_COMPLETE_PAGE + renderer := blackfriday.HtmlRenderer(htmlFlags, "", "") + + // set up the parser + extensions := 0 + extensions |= blackfriday.EXTENSION_NO_INTRA_EMPHASIS + extensions |= blackfriday.EXTENSION_TABLES + extensions |= blackfriday.EXTENSION_FENCED_CODE + extensions |= blackfriday.EXTENSION_AUTOLINK + extensions |= blackfriday.EXTENSION_STRIKETHROUGH + extensions |= blackfriday.EXTENSION_HARD_LINE_BREAK + extensions |= blackfriday.EXTENSION_SPACE_HEADERS + extensions |= blackfriday.EXTENSION_NO_EMPTY_LINE_BEFORE_BLOCK + + body := blackfriday.Markdown(rawBytes, renderer, extensions) + + return body +} diff --git a/modules/base/template.go b/modules/base/template.go index b38ab140..4517cd47 100644 --- a/modules/base/template.go +++ b/modules/base/template.go @@ -19,6 +19,10 @@ var TemplateFuncs template.FuncMap = map[string]interface{}{ "AppVer": func() string { return AppVer }, + "AppDomain": func() string { + return Domain + }, + "AvatarLink": AvatarLink, "str2html": Str2html, "TimeSince": TimeSince, "FileSize": FileSize, diff --git a/modules/base/tool.go b/modules/base/tool.go index 3f8b8ffa..046b2c51 100644 --- a/modules/base/tool.go +++ b/modules/base/tool.go @@ -5,8 +5,10 @@ package base import ( + "bytes" "crypto/md5" "encoding/hex" + "encoding/json" "fmt" "math" "strings" @@ -20,6 +22,11 @@ func EncodeMd5(str string) string { return hex.EncodeToString(m.Sum(nil)) } +// AvatarLink returns avatar link by given e-mail. +func AvatarLink(email string) string { + return "http://1.gravatar.com/avatar/" + EncodeMd5(email) +} + // Seconds-based time units const ( Minute = 60 @@ -235,6 +242,7 @@ type Actioner interface { GetOpType() int GetActUserName() string GetRepoName() string + GetContent() string } // ActionIcon accepts a int that represents action operation type @@ -243,23 +251,39 @@ func ActionIcon(opType int) string { switch opType { case 1: // Create repository. return "plus-circle" + case 5: // Commit repository. + return "arrow-circle-o-right" default: return "invalid type" } } const ( - CreateRepoTpl = `<a href="/user/%s">%s</a> created repository <a href="/%s/%s">%s</a>` + TPL_CREATE_REPO = `<a href="/user/%s">%s</a> created repository <a href="/%s/%s">%s</a>` + TPL_COMMIT_REPO = `<a href="/user/%s">%s</a> pushed to <a href="/%s/%s/tree/%s">%s</a> at <a href="/%s/%s">%s/%s</a>%s` + TPL_COMMIT_REPO_LI = `<div><img id="gogs-user-avatar-commit" src="%s?s=16" alt="user-avatar" title="username"/> <a href="/%s/%s/commit/%s">%s</a> %s</div>` ) // ActionDesc accepts int that represents action operation type // and returns the description. -func ActionDesc(act Actioner) string { +func ActionDesc(act Actioner, avatarLink string) string { actUserName := act.GetActUserName() repoName := act.GetRepoName() + content := act.GetContent() switch act.GetOpType() { case 1: // Create repository. - return fmt.Sprintf(CreateRepoTpl, actUserName, actUserName, actUserName, repoName, repoName) + return fmt.Sprintf(TPL_CREATE_REPO, actUserName, actUserName, actUserName, repoName, repoName) + case 5: // Commit repository. + var commits [][]string + if err := json.Unmarshal([]byte(content), &commits); err != nil { + return err.Error() + } + buf := bytes.NewBuffer([]byte("\n")) + for _, commit := range commits { + buf.WriteString(fmt.Sprintf(TPL_COMMIT_REPO_LI, avatarLink, actUserName, repoName, commit[0], commit[0][:7], commit[1]) + "\n") + } + return fmt.Sprintf(TPL_COMMIT_REPO, actUserName, actUserName, actUserName, repoName, "master", "master", actUserName, repoName, actUserName, repoName, + buf.String()) default: return "invalid type" } diff --git a/modules/middleware/repo.go b/modules/middleware/repo.go index 8cdc6df7..db29bd11 100644 --- a/modules/middleware/repo.go +++ b/modules/middleware/repo.go @@ -6,6 +6,7 @@ package middleware import ( "errors" + "strings" "github.com/codegangsta/martini" @@ -23,8 +24,7 @@ func RepoAssignment(redirect bool) martini.Handler { ) // get repository owner - ctx.Repo.IsOwner = ctx.IsSigned && ctx.User.LowerName == params["username"] - ctx.Data["IsRepositoryOwner"] = ctx.Repo.IsOwner + ctx.Repo.IsOwner = ctx.IsSigned && ctx.User.LowerName == strings.ToLower(params["username"]) if !ctx.Repo.IsOwner { user, err = models.GetUserByName(params["username"]) @@ -70,5 +70,6 @@ func RepoAssignment(redirect bool) martini.Handler { ctx.Data["Owner"] = user ctx.Data["Title"] = user.Name + "/" + repo.Name ctx.Data["RepositoryLink"] = ctx.Data["Title"] + ctx.Data["IsRepositoryOwner"] = ctx.Repo.IsOwner } } |