mirror of
				https://github.com/go-gitea/gitea.git
				synced 2025-10-31 10:27:29 -04:00 
			
		
		
		
	Before:
* `{{.locale.Tr ...}}`
* `{{$.locale.Tr ...}}`
* `{{$.root.locale.Tr ...}}`
* `{{template "sub" .}}`
* `{{template "sub" (dict "locale" $.locale)}}`
* `{{template "sub" (dict "root" $)}}`
* .....
With context function: only need to `{{ctx.Locale.Tr ...}}`
The "ctx" could be considered as a super-global variable for all
templates including sub-templates.
To avoid potential risks (any bug in the template context function
package), this PR only starts using "ctx" in "head.tmpl" and
"footer.tmpl" and it has a "DataRaceCheck". If there is anything wrong,
the code can be fixed or reverted easily.
		
	
		
			
				
	
	
		
			26 lines
		
	
	
		
			694 B
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			26 lines
		
	
	
		
			694 B
		
	
	
	
		
			Go
		
	
	
	
	
	
| // Copyright 2020 The Gitea Authors. All rights reserved.
 | |
| // SPDX-License-Identifier: MIT
 | |
| 
 | |
| package web
 | |
| 
 | |
| import (
 | |
| 	"code.gitea.io/gitea/modules/base"
 | |
| 	"code.gitea.io/gitea/modules/context"
 | |
| )
 | |
| 
 | |
| // tplSwaggerV1Json swagger v1 json template
 | |
| const tplSwaggerV1Json base.TplName = "swagger/v1_json"
 | |
| 
 | |
| // SwaggerV1Json render swagger v1 json
 | |
| func SwaggerV1Json(ctx *context.Context) {
 | |
| 	t, err := ctx.Render.TemplateLookup(string(tplSwaggerV1Json), nil)
 | |
| 	if err != nil {
 | |
| 		ctx.ServerError("unable to find template", err)
 | |
| 		return
 | |
| 	}
 | |
| 	ctx.Resp.Header().Set("Content-Type", "application/json")
 | |
| 	if err = t.Execute(ctx.Resp, ctx.Data); err != nil {
 | |
| 		ctx.ServerError("unable to execute template", err)
 | |
| 	}
 | |
| }
 |