summaryrefslogtreecommitdiffstats
path: root/routers
diff options
context:
space:
mode:
author无闻 <u@gogs.io>2016-08-30 16:47:22 -0700
committerGitHub <noreply@github.com>2016-08-30 16:47:22 -0700
commitcd9b926af7d186c82997c26fea0bbdeed447b4dc (patch)
treed9b0e47314b291850f71b59477bce27eb577c4fa /routers
parent8516dfcb6cb008f286ec84bed4243928acb94844 (diff)
parent9ac46fb983f31cfece76e2181a9fe73b71f02e2e (diff)
downloadgitea-cd9b926af7d186c82997c26fea0bbdeed447b4dc.tar.gz
gitea-cd9b926af7d186c82997c26fea0bbdeed447b4dc.zip
Support Editorconfig on web editor (#3512)
Diffstat (limited to 'routers')
-rw-r--r--routers/api/v1/api.go1
-rw-r--r--routers/api/v1/repo/file.go20
-rw-r--r--routers/repo/editor.go1
3 files changed, 22 insertions, 0 deletions
diff --git a/routers/api/v1/api.go b/routers/api/v1/api.go
index 16322fbffd..0591cddb86 100644
--- a/routers/api/v1/api.go
+++ b/routers/api/v1/api.go
@@ -290,6 +290,7 @@ func RegisterRoutes(m *macaron.Macaron) {
Patch(reqRepoWriter(), bind(api.EditMilestoneOption{}), repo.EditMilestone).
Delete(reqRepoWriter(), repo.DeleteMilestone)
})
+ m.Get("/editorconfig/:filename", context.RepoRef(), repo.GetEditorconfig)
}, repoAssignment())
}, reqToken())
diff --git a/routers/api/v1/repo/file.go b/routers/api/v1/repo/file.go
index 972dbefac0..ee9d15a322 100644
--- a/routers/api/v1/repo/file.go
+++ b/routers/api/v1/repo/file.go
@@ -45,3 +45,23 @@ func GetArchive(ctx *context.APIContext) {
repo.Download(ctx.Context)
}
+
+func GetEditorconfig(ctx *context.APIContext) {
+ ec, err := ctx.Repo.GetEditorconfig()
+ if err != nil {
+ if git.IsErrNotExist(err) {
+ ctx.Error(404, "GetEditorconfig", err)
+ } else {
+ ctx.Error(500, "GetEditorconfig", err)
+ }
+ return
+ }
+
+ fileName := ctx.Params("filename")
+ def := ec.GetDefinitionForFilename(fileName)
+ if def == nil {
+ ctx.Error(404, "GetDefinitionForFilename", err)
+ return
+ }
+ ctx.JSON(200, def)
+}
diff --git a/routers/repo/editor.go b/routers/repo/editor.go
index f471e5ee22..bf2244719c 100644
--- a/routers/repo/editor.go
+++ b/routers/repo/editor.go
@@ -98,6 +98,7 @@ func editFile(ctx *context.Context, isNewFile bool) {
ctx.Data["MarkdownFileExts"] = strings.Join(setting.Markdown.FileExtensions, ",")
ctx.Data["LineWrapExtensions"] = strings.Join(setting.Repository.Editor.LineWrapExtensions, ",")
ctx.Data["PreviewableFileModes"] = strings.Join(setting.Repository.Editor.PreviewableFileModes, ",")
+ ctx.Data["EditorconfigURLPrefix"] = fmt.Sprintf("%s/api/v1/repos/%s/editorconfig/", setting.AppSubUrl, ctx.Repo.Repository.FullName())
ctx.HTML(200, EDIT_FILE)
}