本站源代码
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.

64 lines
1.5KB

  1. package repo
  2. import (
  3. "fmt"
  4. "code.gitea.io/gitea/models"
  5. "code.gitea.io/gitea/modules/context"
  6. "code.gitea.io/gitea/modules/git"
  7. )
  8. // SetEditorconfigIfExists set editor config as render variable
  9. func SetEditorconfigIfExists(ctx *context.Context) {
  10. ec, err := ctx.Repo.GetEditorconfig()
  11. if err != nil && !git.IsErrNotExist(err) {
  12. description := fmt.Sprintf("Error while getting .editorconfig file: %v", err)
  13. if err := models.CreateRepositoryNotice(description); err != nil {
  14. ctx.ServerError("ErrCreatingReporitoryNotice", err)
  15. }
  16. return
  17. }
  18. ctx.Data["Editorconfig"] = ec
  19. }
  20. // SetDiffViewStyle set diff style as render variable
  21. func SetDiffViewStyle(ctx *context.Context) {
  22. queryStyle := ctx.Query("style")
  23. if !ctx.IsSigned {
  24. ctx.Data["IsSplitStyle"] = queryStyle == "split"
  25. return
  26. }
  27. var (
  28. userStyle = ctx.User.DiffViewStyle
  29. style string
  30. )
  31. if queryStyle == "unified" || queryStyle == "split" {
  32. style = queryStyle
  33. } else if userStyle == "unified" || userStyle == "split" {
  34. style = userStyle
  35. } else {
  36. style = "unified"
  37. }
  38. ctx.Data["IsSplitStyle"] = style == "split"
  39. if err := ctx.User.UpdateDiffViewStyle(style); err != nil {
  40. ctx.ServerError("ErrUpdateDiffViewStyle", err)
  41. }
  42. }
  43. // SetWhitespaceBehavior set whitespace behavior as render variable
  44. func SetWhitespaceBehavior(ctx *context.Context) {
  45. whitespaceBehavior := ctx.Query("whitespace")
  46. switch whitespaceBehavior {
  47. case "ignore-all", "ignore-eol", "ignore-change":
  48. ctx.Data["WhitespaceBehavior"] = whitespaceBehavior
  49. default:
  50. ctx.Data["WhitespaceBehavior"] = ""
  51. }
  52. }
上海开阖软件有限公司 沪ICP备12045867号-1