You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

72 lines
1.8 KiB

  1. // Copyright 2020 The Gitea Authors. All rights reserved.
  2. // Use of this source code is governed by a MIT-style
  3. // license that can be found in the LICENSE file.
  4. package repo
  5. import (
  6. "fmt"
  7. "code.gitea.io/gitea/models"
  8. "code.gitea.io/gitea/modules/context"
  9. "code.gitea.io/gitea/modules/git"
  10. )
  11. // SetEditorconfigIfExists set editor config as render variable
  12. func SetEditorconfigIfExists(ctx *context.Context) {
  13. if ctx.Repo.Repository.IsEmpty {
  14. ctx.Data["Editorconfig"] = nil
  15. return
  16. }
  17. ec, err := ctx.Repo.GetEditorconfig()
  18. if err != nil && !git.IsErrNotExist(err) {
  19. description := fmt.Sprintf("Error while getting .editorconfig file: %v", err)
  20. if err := models.CreateRepositoryNotice(description); err != nil {
  21. ctx.ServerError("ErrCreatingReporitoryNotice", err)
  22. }
  23. return
  24. }
  25. ctx.Data["Editorconfig"] = ec
  26. }
  27. // SetDiffViewStyle set diff style as render variable
  28. func SetDiffViewStyle(ctx *context.Context) {
  29. queryStyle := ctx.Query("style")
  30. if !ctx.IsSigned {
  31. ctx.Data["IsSplitStyle"] = queryStyle == "split"
  32. return
  33. }
  34. var (
  35. userStyle = ctx.User.DiffViewStyle
  36. style string
  37. )
  38. if queryStyle == "unified" || queryStyle == "split" {
  39. style = queryStyle
  40. } else if userStyle == "unified" || userStyle == "split" {
  41. style = userStyle
  42. } else {
  43. style = "unified"
  44. }
  45. ctx.Data["IsSplitStyle"] = style == "split"
  46. if err := ctx.User.UpdateDiffViewStyle(style); err != nil {
  47. ctx.ServerError("ErrUpdateDiffViewStyle", err)
  48. }
  49. }
  50. // SetWhitespaceBehavior set whitespace behavior as render variable
  51. func SetWhitespaceBehavior(ctx *context.Context) {
  52. whitespaceBehavior := ctx.Query("whitespace")
  53. switch whitespaceBehavior {
  54. case "ignore-all", "ignore-eol", "ignore-change":
  55. ctx.Data["WhitespaceBehavior"] = whitespaceBehavior
  56. default:
  57. ctx.Data["WhitespaceBehavior"] = ""
  58. }
  59. }