@@ -19,7 +19,6 @@ import (
1919 "reflect"
2020 "regexp"
2121 "runtime"
22- "strconv"
2322 "strings"
2423 texttmpl "text/template"
2524 "time"
@@ -112,18 +111,17 @@ func NewFuncMap() []template.FuncMap {
112111 "IsShowFullName" : func () bool {
113112 return setting .UI .DefaultShowFullName
114113 },
115- "Safe" : Safe ,
116- "SafeJS" : SafeJS ,
117- "JSEscape" : JSEscape ,
118- "Str2html" : Str2html ,
119- "TimeSince" : timeutil .TimeSince ,
120- "TimeSinceUnix" : timeutil .TimeSinceUnix ,
121- "FileSize" : base .FileSize ,
122- "PrettyNumber" : base .PrettyNumber ,
123- "JsPrettyNumber" : JsPrettyNumber ,
124- "Subtract" : base .Subtract ,
125- "EntryIcon" : base .EntryIcon ,
126- "MigrationIcon" : MigrationIcon ,
114+ "Safe" : Safe ,
115+ "SafeJS" : SafeJS ,
116+ "JSEscape" : JSEscape ,
117+ "Str2html" : Str2html ,
118+ "TimeSince" : timeutil .TimeSince ,
119+ "TimeSinceUnix" : timeutil .TimeSinceUnix ,
120+ "FileSize" : base .FileSize ,
121+ "LocaleNumber" : LocaleNumber ,
122+ "Subtract" : base .Subtract ,
123+ "EntryIcon" : base .EntryIcon ,
124+ "MigrationIcon" : MigrationIcon ,
127125 "Add" : func (a ... int ) int {
128126 sum := 0
129127 for _ , val := range a {
@@ -410,62 +408,9 @@ func NewFuncMap() []template.FuncMap {
410408 "Join" : strings .Join ,
411409 "QueryEscape" : url .QueryEscape ,
412410 "DotEscape" : DotEscape ,
413- "Iterate" : func (arg interface {}) (items []uint64 ) {
414- count := uint64 (0 )
415- switch val := arg .(type ) {
416- case uint64 :
417- count = val
418- case * uint64 :
419- count = * val
420- case int64 :
421- if val < 0 {
422- val = 0
423- }
424- count = uint64 (val )
425- case * int64 :
426- if * val < 0 {
427- * val = 0
428- }
429- count = uint64 (* val )
430- case int :
431- if val < 0 {
432- val = 0
433- }
434- count = uint64 (val )
435- case * int :
436- if * val < 0 {
437- * val = 0
438- }
439- count = uint64 (* val )
440- case uint :
441- count = uint64 (val )
442- case * uint :
443- count = uint64 (* val )
444- case int32 :
445- if val < 0 {
446- val = 0
447- }
448- count = uint64 (val )
449- case * int32 :
450- if * val < 0 {
451- * val = 0
452- }
453- count = uint64 (* val )
454- case uint32 :
455- count = uint64 (val )
456- case * uint32 :
457- count = uint64 (* val )
458- case string :
459- cnt , _ := strconv .ParseInt (val , 10 , 64 )
460- if cnt < 0 {
461- cnt = 0
462- }
463- count = uint64 (cnt )
464- }
465- if count <= 0 {
466- return items
467- }
468- for i := uint64 (0 ); i < count ; i ++ {
411+ "Iterate" : func (arg interface {}) (items []int64 ) {
412+ count := util .ToInt64 (arg )
413+ for i := int64 (0 ); i < count ; i ++ {
469414 items = append (items , i )
470415 }
471416 return items
@@ -1067,10 +1012,8 @@ func mirrorRemoteAddress(ctx context.Context, m *repo_model.Repository, remoteNa
10671012 return a
10681013}
10691014
1070- // JsPrettyNumber renders a number using english decimal separators, e.g. 1,200 and subsequent
1071- // JS will replace the number with locale-specific separators, based on the user's selected language
1072- func JsPrettyNumber (i interface {}) template.HTML {
1073- num := util .NumberIntoInt64 (i )
1074-
1075- return template .HTML (`<span class="js-pretty-number" data-value="` + strconv .FormatInt (num , 10 ) + `">` + base .PrettyNumber (num ) + `</span>` )
1015+ // LocaleNumber renders a number with a Custom Element, browser will render it with a locale number
1016+ func LocaleNumber (v interface {}) template.HTML {
1017+ num := util .ToInt64 (v )
1018+ return template .HTML (fmt .Sprintf (`<gitea-locale-number data-number="%d">%d</gitea-locale-number>` , num , num ))
10761019}
0 commit comments