@@ -18,6 +18,7 @@ import (
18
18
"regexp"
19
19
"runtime"
20
20
"strings"
21
+ "strconv"
21
22
texttmpl "text/template"
22
23
"time"
23
24
"unicode"
@@ -92,18 +93,19 @@ func NewFuncMap() []template.FuncMap {
92
93
"CustomEmojis" : func () map [string ]string {
93
94
return setting .UI .CustomEmojisMap
94
95
},
95
- "Safe" : Safe ,
96
- "SafeJS" : SafeJS ,
97
- "JSEscape" : JSEscape ,
98
- "Str2html" : Str2html ,
99
- "TimeSince" : timeutil .TimeSince ,
100
- "TimeSinceUnix" : timeutil .TimeSinceUnix ,
101
- "RawTimeSince" : timeutil .RawTimeSince ,
102
- "FileSize" : base .FileSize ,
103
- "PrettyNumber" : base .PrettyNumber ,
104
- "Subtract" : base .Subtract ,
105
- "EntryIcon" : base .EntryIcon ,
106
- "MigrationIcon" : MigrationIcon ,
96
+ "Safe" : Safe ,
97
+ "SafeJS" : SafeJS ,
98
+ "JSEscape" : JSEscape ,
99
+ "Str2html" : Str2html ,
100
+ "TimeSince" : timeutil .TimeSince ,
101
+ "TimeSinceUnix" : timeutil .TimeSinceUnix ,
102
+ "RawTimeSince" : timeutil .RawTimeSince ,
103
+ "FileSize" : base .FileSize ,
104
+ "PrettyNumber" : base .PrettyNumber ,
105
+ "JsPrettyNumber" : JsPrettyNumber ,
106
+ "Subtract" : base .Subtract ,
107
+ "EntryIcon" : base .EntryIcon ,
108
+ "MigrationIcon" : MigrationIcon ,
107
109
"Add" : func (a ... int ) int {
108
110
sum := 0
109
111
for _ , val := range a {
@@ -972,3 +974,23 @@ func mirrorRemoteAddress(m models.RemoteMirrorer) remoteAddress {
972
974
973
975
return a
974
976
}
977
+
978
+ // JsPrettyNumber renders a number using english decimal separators, e.g. 1,200
979
+ // subsequent Js will replace the number with locale-specific separators
980
+ func JsPrettyNumber (i interface {}) template.HTML {
981
+ var num int64
982
+ switch v := i .(type ) {
983
+ case int :
984
+ num = int64 (v )
985
+ case int8 :
986
+ num = int64 (v )
987
+ case int16 :
988
+ num = int64 (v )
989
+ case int32 :
990
+ num = int64 (v )
991
+ case int64 :
992
+ num = v
993
+ }
994
+
995
+ return template .HTML (`<span class="js-pretty-number" data-value="` + strconv .FormatInt (num , 10 ) + `">` + base .PrettyNumber (num ) + `</span>` )
996
+ }
0 commit comments