From dbed39ba05fd498dad6cd3bf127c1f68056bf2ab Mon Sep 17 00:00:00 2001 From: Andrey Nering Date: Thu, 11 Aug 2016 21:07:09 -0300 Subject: On showing diff/file, use the tab_width specified on .editorconfig, if any (#3241) Closes #3182 --- modules/template/template.go | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'modules/template') diff --git a/modules/template/template.go b/modules/template/template.go index 6e9b15b9..1b5e0a11 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" + }, }} } -- cgit v1.2.3