summaryrefslogtreecommitdiffstats
path: root/modules/templates
diff options
context:
space:
mode:
authorPiotr Orzechowski <piotr@orzechowski.tech>2018-07-28 02:19:01 +0200
committerLauris BH <lauris@nix.lv>2018-07-28 03:19:01 +0300
commita74426d631e3311cc3c460ae9917f76f0221f4de (patch)
tree1343766d999308825f42bc0b67c1845a5e9e9546 /modules/templates
parent412583a3f28162c89e827fbb586319ac8eea9825 (diff)
downloadgitea-a74426d631e3311cc3c460ae9917f76f0221f4de.tar.gz
gitea-a74426d631e3311cc3c460ae9917f76f0221f4de.zip
Swagger.v1.json template (#3572)
* Turn swagger.v1.json into template * Rename ENABLE_SWAGGER_ENDPOINT option to ENABLE_SWAGGER
Diffstat (limited to 'modules/templates')
-rw-r--r--modules/templates/dynamic.go16
-rw-r--r--modules/templates/static.go21
2 files changed, 32 insertions, 5 deletions
diff --git a/modules/templates/dynamic.go b/modules/templates/dynamic.go
index c127b69470..d70a465c1c 100644
--- a/modules/templates/dynamic.go
+++ b/modules/templates/dynamic.go
@@ -22,8 +22,8 @@ var (
templates = template.New("")
)
-// Renderer implements the macaron handler for serving the templates.
-func Renderer() macaron.Handler {
+// HTMLRenderer implements the macaron handler for serving HTML templates.
+func HTMLRenderer() macaron.Handler {
return macaron.Renderer(macaron.RenderOptions{
Funcs: NewFuncMap(),
Directory: path.Join(setting.StaticRootPath, "templates"),
@@ -33,6 +33,18 @@ func Renderer() macaron.Handler {
})
}
+// JSONRenderer implements the macaron handler for serving JSON templates.
+func JSONRenderer() macaron.Handler {
+ return macaron.Renderer(macaron.RenderOptions{
+ Funcs: NewFuncMap(),
+ Directory: path.Join(setting.StaticRootPath, "templates"),
+ AppendDirectories: []string{
+ path.Join(setting.CustomPath, "templates"),
+ },
+ HTMLContentType: "application/json",
+ })
+}
+
// Mailer provides the templates required for sending notification mails.
func Mailer() *template.Template {
for _, funcs := range NewFuncMap() {
diff --git a/modules/templates/static.go b/modules/templates/static.go
index 65b82053fd..c16b18cc08 100644
--- a/modules/templates/static.go
+++ b/modules/templates/static.go
@@ -43,8 +43,7 @@ func (templates templateFileSystem) Get(name string) (io.Reader, error) {
return nil, fmt.Errorf("file '%s' not found", name)
}
-// Renderer implements the macaron handler for serving the templates.
-func Renderer() macaron.Handler {
+func NewTemplateFileSystem() templateFileSystem {
fs := templateFileSystem{}
fs.files = make([]macaron.TemplateFile, 0, 10)
@@ -110,9 +109,25 @@ func Renderer() macaron.Handler {
}
}
+ return fs
+}
+
+var tplFileSys = NewTemplateFileSystem()
+
+// HTMLRenderer implements the macaron handler for serving HTML templates.
+func HTMLRenderer() macaron.Handler {
+ return macaron.Renderer(macaron.RenderOptions{
+ Funcs: NewFuncMap(),
+ TemplateFileSystem: tplFileSys,
+ })
+}
+
+// JSONRenderer implements the macaron handler for serving JSON templates.
+func JSONRenderer() macaron.Handler {
return macaron.Renderer(macaron.RenderOptions{
Funcs: NewFuncMap(),
- TemplateFileSystem: fs,
+ TemplateFileSystem: tplFileSys,
+ HTMLContentType: "application/json",
})
}