summaryrefslogtreecommitdiffstats
path: root/modules/base/tool.go
diff options
context:
space:
mode:
authorUnknown <joe2010xtmf@163.com>2014-03-15 00:50:51 -0400
committerUnknown <joe2010xtmf@163.com>2014-03-15 00:50:51 -0400
commitadb17791bdb94d22cdc571d7f633846c6fe3d938 (patch)
tree8d9f9ffa487e63874e21d42ee3cc8c4a6c3dc85a /modules/base/tool.go
parent2289ff20bf40e2adaa096aeac80837c69c2f01c3 (diff)
downloadgitea-adb17791bdb94d22cdc571d7f633846c6fe3d938.tar.gz
gitea-adb17791bdb94d22cdc571d7f633846c6fe3d938.zip
Add basic render of public act
Diffstat (limited to 'modules/base/tool.go')
-rw-r--r--modules/base/tool.go39
1 files changed, 39 insertions, 0 deletions
diff --git a/modules/base/tool.go b/modules/base/tool.go
index c7b907bee1..49a2a2b5d1 100644
--- a/modules/base/tool.go
+++ b/modules/base/tool.go
@@ -8,6 +8,7 @@ import (
"crypto/md5"
"encoding/hex"
"fmt"
+ "html/template"
"time"
)
@@ -28,6 +29,10 @@ const (
Year = 12 * Month
)
+func Str2html(raw string) template.HTML {
+ return template.HTML(raw)
+}
+
// TimeSince calculates the time interval and generate user-friendly string.
func TimeSince(then time.Time) string {
now := time.Now()
@@ -128,3 +133,37 @@ func Subtract(left interface{}, right interface{}) interface{} {
return fleft + float64(rleft) - (fright + float64(rright))
}
}
+
+type Actioner interface {
+ GetOpType() int
+ GetActUserName() string
+ GetRepoName() string
+}
+
+// ActionIcon accepts a int that represents action operation type
+// and returns a icon class name.
+func ActionIcon(opType int) string {
+ switch opType {
+ case 1: // Create repository.
+ return "plus-circle"
+ default:
+ return "invalid type"
+ }
+}
+
+const (
+ CreateRepoTpl = `<a href="/user/%s">%s</a> created repository <a href="/%s/%s">%s</a>`
+)
+
+// ActionDesc accepts int that represents action operation type
+// and returns the description.
+func ActionDesc(act Actioner) string {
+ actUserName := act.GetActUserName()
+ repoName := act.GetRepoName()
+ switch act.GetOpType() {
+ case 1: // Create repository.
+ return fmt.Sprintf(CreateRepoTpl, actUserName, actUserName, actUserName, repoName, repoName)
+ default:
+ return "invalid type"
+ }
+}