@@ -36,16 +36,16 @@ func NewFuncMap() template.FuncMap {
36
36
// -----------------------------------------------------------------
37
37
// html/template related functions
38
38
"dict" : dict , // it's lowercase because this name has been widely used. Our other functions should have uppercase names.
39
- "Iif" : Iif ,
40
- "Eval" : Eval ,
41
- "SafeHTML" : SafeHTML ,
39
+ "Iif" : iif ,
40
+ "Eval" : evalTokens ,
41
+ "SafeHTML" : safeHTML ,
42
42
"HTMLFormat" : HTMLFormat ,
43
- "HTMLEscape" : HTMLEscape ,
44
- "QueryEscape" : QueryEscape ,
45
- "JSEscape" : JSEscapeSafe ,
43
+ "HTMLEscape" : htmlEscape ,
44
+ "QueryEscape" : queryEscape ,
45
+ "JSEscape" : jsEscapeSafe ,
46
46
"SanitizeHTML" : SanitizeHTML ,
47
47
"URLJoin" : util .URLJoin ,
48
- "DotEscape" : DotEscape ,
48
+ "DotEscape" : dotEscape ,
49
49
50
50
"PathEscape" : url .PathEscape ,
51
51
"PathEscapeSegments" : util .PathEscapeSegments ,
@@ -59,9 +59,9 @@ func NewFuncMap() template.FuncMap {
59
59
// svg / avatar / icon / color
60
60
"svg" : svg .RenderHTML ,
61
61
"EntryIcon" : base .EntryIcon ,
62
- "MigrationIcon" : MigrationIcon ,
63
- "ActionIcon" : ActionIcon ,
64
- "SortArrow" : SortArrow ,
62
+ "MigrationIcon" : migrationIcon ,
63
+ "ActionIcon" : actionIcon ,
64
+ "SortArrow" : sortArrow ,
65
65
"ContrastColor" : util .ContrastColor ,
66
66
67
67
// -----------------------------------------------------------------
@@ -139,7 +139,7 @@ func NewFuncMap() template.FuncMap {
139
139
"DisableImportLocal" : func () bool {
140
140
return ! setting .ImportLocalPaths
141
141
},
142
- "UserThemeName" : UserThemeName ,
142
+ "UserThemeName" : userThemeName ,
143
143
"NotificationSettings" : func () map [string ]any {
144
144
return map [string ]any {
145
145
"MinTimeout" : int (setting .UI .Notification .MinTimeout / time .Millisecond ),
@@ -155,28 +155,28 @@ func NewFuncMap() template.FuncMap {
155
155
// -----------------------------------------------------------------
156
156
// render
157
157
"RenderCommitMessage" : RenderCommitMessage ,
158
- "RenderCommitMessageLinkSubject" : RenderCommitMessageLinkSubject ,
158
+ "RenderCommitMessageLinkSubject" : renderCommitMessageLinkSubject ,
159
159
160
- "RenderCommitBody" : RenderCommitBody ,
161
- "RenderCodeBlock" : RenderCodeBlock ,
162
- "RenderIssueTitle" : RenderIssueTitle ,
163
- "RenderEmoji" : RenderEmoji ,
164
- "ReactionToEmoji" : ReactionToEmoji ,
160
+ "RenderCommitBody" : renderCommitBody ,
161
+ "RenderCodeBlock" : renderCodeBlock ,
162
+ "RenderIssueTitle" : renderIssueTitle ,
163
+ "RenderEmoji" : renderEmoji ,
164
+ "ReactionToEmoji" : reactionToEmoji ,
165
165
166
166
"RenderMarkdownToHtml" : RenderMarkdownToHtml ,
167
- "RenderLabel" : RenderLabel ,
167
+ "RenderLabel" : renderLabel ,
168
168
"RenderLabels" : RenderLabels ,
169
169
170
170
// -----------------------------------------------------------------
171
171
// misc
172
172
"ShortSha" : base .ShortSha ,
173
173
"ActionContent2Commits" : ActionContent2Commits ,
174
- "IsMultilineCommitMessage" : IsMultilineCommitMessage ,
174
+ "IsMultilineCommitMessage" : isMultilineCommitMessage ,
175
175
"CommentMustAsDiff" : gitdiff .CommentMustAsDiff ,
176
176
"MirrorRemoteAddress" : mirrorRemoteAddress ,
177
177
178
- "FilenameIsImage" : FilenameIsImage ,
179
- "TabSizeClass" : TabSizeClass ,
178
+ "FilenameIsImage" : filenameIsImage ,
179
+ "TabSizeClass" : tabSizeClass ,
180
180
}
181
181
}
182
182
@@ -197,8 +197,8 @@ func HTMLFormat(s string, rawArgs ...any) template.HTML {
197
197
return template .HTML (fmt .Sprintf (s , args ... ))
198
198
}
199
199
200
- // SafeHTML render raw as HTML
201
- func SafeHTML (s any ) template.HTML {
200
+ // safeHTML render raw as HTML
201
+ func safeHTML (s any ) template.HTML {
202
202
switch v := s .(type ) {
203
203
case string :
204
204
return template .HTML (v )
@@ -213,7 +213,7 @@ func SanitizeHTML(s string) template.HTML {
213
213
return template .HTML (markup .Sanitize (s ))
214
214
}
215
215
216
- func HTMLEscape (s any ) template.HTML {
216
+ func htmlEscape (s any ) template.HTML {
217
217
switch v := s .(type ) {
218
218
case string :
219
219
return template .HTML (html .EscapeString (v ))
@@ -223,22 +223,22 @@ func HTMLEscape(s any) template.HTML {
223
223
panic (fmt .Sprintf ("unexpected type %T" , s ))
224
224
}
225
225
226
- func JSEscapeSafe (s string ) template.HTML {
226
+ func jsEscapeSafe (s string ) template.HTML {
227
227
return template .HTML (template .JSEscapeString (s ))
228
228
}
229
229
230
- func QueryEscape (s string ) template.URL {
230
+ func queryEscape (s string ) template.URL {
231
231
return template .URL (url .QueryEscape (s ))
232
232
}
233
233
234
- // DotEscape wraps a dots in names with ZWJ [U+200D] in order to prevent autolinkers from detecting these as urls
235
- func DotEscape (raw string ) string {
234
+ // dotEscape wraps a dots in names with ZWJ [U+200D] in order to prevent auto-linkers from detecting these as urls
235
+ func dotEscape (raw string ) string {
236
236
return strings .ReplaceAll (raw , "." , "\u200d .\u200d " )
237
237
}
238
238
239
- // Iif is an "inline-if", similar util.Iif[T] but templates need the non-generic version,
240
- // and it could be simply used as "{{Iif expr trueVal}}" (omit the falseVal).
241
- func Iif (condition any , vals ... any ) any {
239
+ // iif is an "inline-if", similar util.Iif[T] but templates need the non-generic version,
240
+ // and it could be simply used as "{{iif expr trueVal}}" (omit the falseVal).
241
+ func iif (condition any , vals ... any ) any {
242
242
if isTemplateTruthy (condition ) {
243
243
return vals [0 ]
244
244
} else if len (vals ) > 1 {
@@ -273,19 +273,19 @@ func isTemplateTruthy(v any) bool {
273
273
}
274
274
}
275
275
276
- // Eval the expression and return the result, see the comment of eval.Expr for details.
276
+ // evalTokens evaluates the expression by tokens and returns the result, see the comment of eval.Expr for details.
277
277
// To use this helper function in templates, pass each token as a separate parameter.
278
278
//
279
279
// {{ $int64 := Eval $var "+" 1 }}
280
280
// {{ $float64 := Eval $var "+" 1.0 }}
281
281
//
282
282
// Golang's template supports comparable int types, so the int64 result can be used in later statements like {{if lt $int64 10}}
283
- func Eval (tokens ... any ) (any , error ) {
283
+ func evalTokens (tokens ... any ) (any , error ) {
284
284
n , err := eval .Expr (tokens ... )
285
285
return n .Value , err
286
286
}
287
287
288
- func UserThemeName (user * user_model.User ) string {
288
+ func userThemeName (user * user_model.User ) string {
289
289
if user == nil || user .Theme == "" {
290
290
return setting .UI .DefaultTheme
291
291
}
0 commit comments