|
5 | 5 | package repo |
6 | 6 |
|
7 | 7 | import ( |
| 8 | + "encoding/json" |
8 | 9 | "fmt" |
9 | 10 | "io/ioutil" |
10 | 11 | "path" |
@@ -146,11 +147,24 @@ func editFile(ctx *context.Context, isNewFile bool) { |
146 | 147 | ctx.Data["MarkdownFileExts"] = strings.Join(setting.Markdown.FileExtensions, ",") |
147 | 148 | ctx.Data["LineWrapExtensions"] = strings.Join(setting.Repository.Editor.LineWrapExtensions, ",") |
148 | 149 | ctx.Data["PreviewableFileModes"] = strings.Join(setting.Repository.Editor.PreviewableFileModes, ",") |
149 | | - ctx.Data["EditorconfigURLPrefix"] = fmt.Sprintf("%s/api/v1/repos/%s/editorconfig/", setting.AppSubURL, ctx.Repo.Repository.FullName()) |
| 150 | + ctx.Data["Editorconfig"] = GetEditorConfig(ctx, treePath) |
150 | 151 |
|
151 | 152 | ctx.HTML(200, tplEditFile) |
152 | 153 | } |
153 | 154 |
|
| 155 | +// GetEditorConfig returns a editorconfig JSON string for given treePath or "null" |
| 156 | +func GetEditorConfig(ctx *context.Context, treePath string) string { |
| 157 | + ec, err := ctx.Repo.GetEditorconfig() |
| 158 | + if err == nil { |
| 159 | + def, err := ec.GetDefinitionForFilename(treePath) |
| 160 | + if err == nil { |
| 161 | + jsonStr, _ := json.Marshal(def) |
| 162 | + return string(jsonStr) |
| 163 | + } |
| 164 | + } |
| 165 | + return "null" |
| 166 | +} |
| 167 | + |
154 | 168 | // EditFile render edit file page |
155 | 169 | func EditFile(ctx *context.Context) { |
156 | 170 | editFile(ctx, false) |
@@ -186,6 +200,7 @@ func editFilePost(ctx *context.Context, form auth.EditRepoFileForm, isNewFile bo |
186 | 200 | ctx.Data["MarkdownFileExts"] = strings.Join(setting.Markdown.FileExtensions, ",") |
187 | 201 | ctx.Data["LineWrapExtensions"] = strings.Join(setting.Repository.Editor.LineWrapExtensions, ",") |
188 | 202 | ctx.Data["PreviewableFileModes"] = strings.Join(setting.Repository.Editor.PreviewableFileModes, ",") |
| 203 | + ctx.Data["Editorconfig"] = GetEditorConfig(ctx, form.TreePath) |
189 | 204 |
|
190 | 205 | if ctx.HasError() { |
191 | 206 | ctx.HTML(200, tplEditFile) |
|
0 commit comments