aboutsummaryrefslogtreecommitdiff
path: root/modules/base
diff options
context:
space:
mode:
Diffstat (limited to 'modules/base')
-rw-r--r--modules/base/conf.go2
-rw-r--r--modules/base/markdown.go39
-rw-r--r--modules/base/template.go4
-rw-r--r--modules/base/tool.go30
4 files changed, 72 insertions, 3 deletions
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"
}