From adb17791bdb94d22cdc571d7f633846c6fe3d938 Mon Sep 17 00:00:00 2001 From: Unknown Date: Sat, 15 Mar 2014 00:50:51 -0400 Subject: Add basic render of public act --- modules/base/tool.go | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) (limited to 'modules/base/tool.go') 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 = `%s created repository %s` +) + +// 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" + } +} -- cgit v1.2.3