aboutsummaryrefslogtreecommitdiffstats
path: root/modules/template
diff options
context:
space:
mode:
authorAndrey Nering <andrey.nering@gmail.com>2016-08-11 21:07:09 -0300
committer无闻 <u@gogs.io>2016-08-11 17:07:09 -0700
commitdbed39ba05fd498dad6cd3bf127c1f68056bf2ab (patch)
tree5f57a18ecdb444bbf52e583894fc38f2d8d50280 /modules/template
parentaa1fc30b898a928ddafbfd0fddc47547c04f96e5 (diff)
downloadgitea-dbed39ba05fd498dad6cd3bf127c1f68056bf2ab.tar.gz
gitea-dbed39ba05fd498dad6cd3bf127c1f68056bf2ab.zip
On showing diff/file, use the tab_width specified on .editorconfig, if any (#3241)
Closes #3182
Diffstat (limited to 'modules/template')
-rw-r--r--modules/template/template.go10
1 files changed, 10 insertions, 0 deletions
diff --git a/modules/template/template.go b/modules/template/template.go
index 6e9b15b9be..1b5e0a11ad 100644
--- a/modules/template/template.go
+++ b/modules/template/template.go
@@ -17,6 +17,7 @@ import (
"golang.org/x/net/html/charset"
"golang.org/x/text/transform"
+ "gopkg.in/editorconfig/editorconfig-core-go.v1"
"github.com/gogits/gogs/models"
"github.com/gogits/gogs/modules/base"
@@ -109,6 +110,15 @@ func NewFuncMap() []template.FuncMap {
mimeType := mime.TypeByExtension(filepath.Ext(filename))
return strings.HasPrefix(mimeType, "image/")
},
+ "TabSizeClass": func(ec *editorconfig.Editorconfig, filename string) string {
+ if ec != nil {
+ def := ec.GetDefinitionForFilename(filename)
+ if def.TabWidth > 0 {
+ return fmt.Sprintf("tab-size-%d", def.TabWidth)
+ }
+ }
+ return "tab-size-8"
+ },
}}
}