From edaf14f2b6fd86f8dec99f67512a5c0095e391dc Mon Sep 17 00:00:00 2001 From: Unknwon Date: Wed, 5 Apr 2017 09:17:21 -0400 Subject: [PATCH] Refactoring: remove tool.TplName --- pkg/context/api.go | 6 ++++-- pkg/context/context.go | 11 +++++------ pkg/mailer/mail.go | 21 ++++++++++----------- pkg/tool/base.go | 11 ----------- routers/admin/admin.go | 8 ++++---- routers/admin/auths.go | 7 +++---- routers/admin/notice.go | 3 +-- routers/admin/orgs.go | 3 +-- routers/admin/repos.go | 3 +-- routers/admin/users.go | 7 +++---- routers/dev/template.go | 3 +-- routers/home.go | 11 +++++------ routers/install.go | 4 ++-- routers/org/members.go | 5 ++--- routers/org/org.go | 5 ++--- routers/org/setting.go | 7 +++---- routers/org/teams.go | 9 ++++----- routers/repo/branch.go | 5 ++--- routers/repo/commit.go | 6 +++--- routers/repo/editor.go | 10 +++++----- routers/repo/issue.go | 16 ++++++++-------- routers/repo/pull.go | 10 +++++----- routers/repo/release.go | 5 ++--- routers/repo/repo.go | 8 ++++---- routers/repo/setting.go | 15 +++++++-------- routers/repo/view.go | 12 ++++++------ routers/repo/webhook.go | 9 ++++----- routers/repo/wiki.go | 9 ++++----- routers/user/auth.go | 11 +++++------ routers/user/home.go | 11 +++++------ routers/user/profile.go | 5 ++--- routers/user/setting.go | 24 ++++++++++++------------ 32 files changed, 125 insertions(+), 155 deletions(-) delete mode 100644 pkg/tool/base.go diff --git a/pkg/context/api.go b/pkg/context/api.go index 5e29a73f..ffaddd33 100644 --- a/pkg/context/api.go +++ b/pkg/context/api.go @@ -12,7 +12,6 @@ import ( log "gopkg.in/clog.v1" "gopkg.in/macaron.v1" - "github.com/gogits/gogs/pkg/tool" "github.com/gogits/gogs/pkg/setting" ) @@ -21,6 +20,9 @@ type APIContext struct { Org *APIOrganization } +// FIXME: move to github.com/gogits/go-gogs-client +const DOC_URL = "https://github.com/gogits/go-gogs-client/wiki" + // Error responses error message to client with given message. // If status is 500, also it prints error to log. func (ctx *APIContext) Error(status int, title string, obj interface{}) { @@ -37,7 +39,7 @@ func (ctx *APIContext) Error(status int, title string, obj interface{}) { ctx.JSON(status, map[string]string{ "message": message, - "url": tool.DOC_URL, + "url": DOC_URL, }) } diff --git a/pkg/context/context.go b/pkg/context/context.go index 89783007..4213eaa4 100644 --- a/pkg/context/context.go +++ b/pkg/context/context.go @@ -21,7 +21,6 @@ import ( "github.com/gogits/gogs/models" "github.com/gogits/gogs/pkg/auth" - "github.com/gogits/gogs/pkg/tool" "github.com/gogits/gogs/pkg/form" "github.com/gogits/gogs/pkg/setting" ) @@ -80,18 +79,18 @@ func (ctx *Context) HasValue(name string) bool { } // HTML responses template with given status. -func (ctx *Context) HTML(status int, name tool.TplName) { +func (ctx *Context) HTML(status int, name string) { log.Trace("Template: %s", name) - ctx.Context.HTML(status, string(name)) + ctx.Context.HTML(status, name) } // Success responses template with status http.StatusOK. -func (c *Context) Success(name tool.TplName) { +func (c *Context) Success(name string) { c.HTML(http.StatusOK, name) } // RenderWithErr used for page has form validation but need to prompt error to users. -func (ctx *Context) RenderWithErr(msg string, tpl tool.TplName, f interface{}) { +func (ctx *Context) RenderWithErr(msg, tpl string, f interface{}) { if f != nil { form.Assign(f, ctx.Data) } @@ -112,7 +111,7 @@ func (ctx *Context) Handle(status int, title string, err error) { ctx.Data["ErrorMsg"] = err } } - ctx.HTML(status, tool.TplName(fmt.Sprintf("status/%d", status))) + ctx.HTML(status, fmt.Sprintf("status/%d", status)) } // NotFound renders the 404 page. diff --git a/pkg/mailer/mail.go b/pkg/mailer/mail.go index 09405a2d..273dca6d 100644 --- a/pkg/mailer/mail.go +++ b/pkg/mailer/mail.go @@ -12,21 +12,20 @@ import ( "gopkg.in/gomail.v2" "gopkg.in/macaron.v1" - "github.com/gogits/gogs/pkg/tool" "github.com/gogits/gogs/pkg/markup" "github.com/gogits/gogs/pkg/setting" ) const ( - MAIL_AUTH_ACTIVATE tool.TplName = "auth/activate" - MAIL_AUTH_ACTIVATE_EMAIL tool.TplName = "auth/activate_email" - MAIL_AUTH_RESET_PASSWORD tool.TplName = "auth/reset_passwd" - MAIL_AUTH_REGISTER_NOTIFY tool.TplName = "auth/register_notify" + MAIL_AUTH_ACTIVATE = "auth/activate" + MAIL_AUTH_ACTIVATE_EMAIL = "auth/activate_email" + MAIL_AUTH_RESET_PASSWORD = "auth/reset_passwd" + MAIL_AUTH_REGISTER_NOTIFY = "auth/register_notify" - MAIL_ISSUE_COMMENT tool.TplName = "issue/comment" - MAIL_ISSUE_MENTION tool.TplName = "issue/mention" + MAIL_ISSUE_COMMENT = "issue/comment" + MAIL_ISSUE_MENTION = "issue/mention" - MAIL_NOTIFY_COLLABORATOR tool.TplName = "notify/collaborator" + MAIL_NOTIFY_COLLABORATOR = "notify/collaborator" ) type MailRender interface { @@ -79,7 +78,7 @@ type Issue interface { HTMLURL() string } -func SendUserMail(c *macaron.Context, u User, tpl tool.TplName, code, subject, info string) { +func SendUserMail(c *macaron.Context, u User, tpl, code, subject, info string) { data := map[string]interface{}{ "Username": u.DisplayName(), "ActiveCodeLives": setting.Service.ActiveCodeLives / 60, @@ -172,12 +171,12 @@ func composeTplData(subject, body, link string) map[string]interface{} { return data } -func composeIssueMessage(issue Issue, repo Repository, doer User, tplName tool.TplName, tos []string, info string) *Message { +func composeIssueMessage(issue Issue, repo Repository, doer User, tplName string, tos []string, info string) *Message { subject := issue.MailSubject() body := string(markup.RenderSpecialLink([]byte(issue.Content()), repo.HTMLURL(), repo.ComposeMetas())) data := composeTplData(subject, body, issue.HTMLURL()) data["Doer"] = doer - content, err := mailRender.HTMLString(string(tplName), data) + content, err := mailRender.HTMLString(tplName, data) if err != nil { log.Error(3, "HTMLString (%s): %v", tplName, err) } diff --git a/pkg/tool/base.go b/pkg/tool/base.go deleted file mode 100644 index 6ad1a99b..00000000 --- a/pkg/tool/base.go +++ /dev/null @@ -1,11 +0,0 @@ -// Copyright 2014 The Gogs Authors. All rights reserved. -// Use of this source code is governed by a MIT-style -// license that can be found in the LICENSE file. - -package tool - -const DOC_URL = "https://github.com/gogits/go-gogs-client/wiki" - -type ( - TplName string -) diff --git a/routers/admin/admin.go b/routers/admin/admin.go index 91b562ad..c7aa7f02 100644 --- a/routers/admin/admin.go +++ b/routers/admin/admin.go @@ -15,18 +15,18 @@ import ( "gopkg.in/macaron.v1" "github.com/gogits/gogs/models" - "github.com/gogits/gogs/pkg/tool" "github.com/gogits/gogs/pkg/context" "github.com/gogits/gogs/pkg/cron" "github.com/gogits/gogs/pkg/mailer" "github.com/gogits/gogs/pkg/process" "github.com/gogits/gogs/pkg/setting" + "github.com/gogits/gogs/pkg/tool" ) const ( - DASHBOARD tool.TplName = "admin/dashboard" - CONFIG tool.TplName = "admin/config" - MONITOR tool.TplName = "admin/monitor" + DASHBOARD = "admin/dashboard" + CONFIG = "admin/config" + MONITOR = "admin/monitor" ) var ( diff --git a/routers/admin/auths.go b/routers/admin/auths.go index 1aba22a2..81a61957 100644 --- a/routers/admin/auths.go +++ b/routers/admin/auths.go @@ -13,16 +13,15 @@ import ( "github.com/gogits/gogs/models" "github.com/gogits/gogs/pkg/auth/ldap" - "github.com/gogits/gogs/pkg/tool" "github.com/gogits/gogs/pkg/context" "github.com/gogits/gogs/pkg/form" "github.com/gogits/gogs/pkg/setting" ) const ( - AUTHS tool.TplName = "admin/auth/list" - AUTH_NEW tool.TplName = "admin/auth/new" - AUTH_EDIT tool.TplName = "admin/auth/edit" + AUTHS = "admin/auth/list" + AUTH_NEW = "admin/auth/new" + AUTH_EDIT = "admin/auth/edit" ) func Authentications(ctx *context.Context) { diff --git a/routers/admin/notice.go b/routers/admin/notice.go index 47ca135d..4041a0fc 100644 --- a/routers/admin/notice.go +++ b/routers/admin/notice.go @@ -10,13 +10,12 @@ import ( log "gopkg.in/clog.v1" "github.com/gogits/gogs/models" - "github.com/gogits/gogs/pkg/tool" "github.com/gogits/gogs/pkg/context" "github.com/gogits/gogs/pkg/setting" ) const ( - NOTICES tool.TplName = "admin/notice" + NOTICES = "admin/notice" ) func Notices(ctx *context.Context) { diff --git a/routers/admin/orgs.go b/routers/admin/orgs.go index 62c03d9a..80732e72 100644 --- a/routers/admin/orgs.go +++ b/routers/admin/orgs.go @@ -6,14 +6,13 @@ package admin import ( "github.com/gogits/gogs/models" - "github.com/gogits/gogs/pkg/tool" "github.com/gogits/gogs/pkg/context" "github.com/gogits/gogs/pkg/setting" "github.com/gogits/gogs/routers" ) const ( - ORGS tool.TplName = "admin/org/list" + ORGS = "admin/org/list" ) func Organizations(ctx *context.Context) { diff --git a/routers/admin/repos.go b/routers/admin/repos.go index 7b4a9c6f..1cd0b749 100644 --- a/routers/admin/repos.go +++ b/routers/admin/repos.go @@ -9,13 +9,12 @@ import ( log "gopkg.in/clog.v1" "github.com/gogits/gogs/models" - "github.com/gogits/gogs/pkg/tool" "github.com/gogits/gogs/pkg/context" "github.com/gogits/gogs/pkg/setting" ) const ( - REPOS tool.TplName = "admin/repo/list" + REPOS = "admin/repo/list" ) func Repos(ctx *context.Context) { diff --git a/routers/admin/users.go b/routers/admin/users.go index 5bcca776..7bb9ec77 100644 --- a/routers/admin/users.go +++ b/routers/admin/users.go @@ -11,7 +11,6 @@ import ( log "gopkg.in/clog.v1" "github.com/gogits/gogs/models" - "github.com/gogits/gogs/pkg/tool" "github.com/gogits/gogs/pkg/context" "github.com/gogits/gogs/pkg/form" "github.com/gogits/gogs/pkg/mailer" @@ -20,9 +19,9 @@ import ( ) const ( - USERS tool.TplName = "admin/user/list" - USER_NEW tool.TplName = "admin/user/new" - USER_EDIT tool.TplName = "admin/user/edit" + USERS = "admin/user/list" + USER_NEW = "admin/user/new" + USER_EDIT = "admin/user/edit" ) func Users(ctx *context.Context) { diff --git a/routers/dev/template.go b/routers/dev/template.go index bc2bb8d2..89cdd10d 100644 --- a/routers/dev/template.go +++ b/routers/dev/template.go @@ -6,7 +6,6 @@ package dev import ( "github.com/gogits/gogs/models" - "github.com/gogits/gogs/pkg/tool" "github.com/gogits/gogs/pkg/context" "github.com/gogits/gogs/pkg/setting" ) @@ -21,5 +20,5 @@ func TemplatePreview(ctx *context.Context) { ctx.Data["ResetPwdCodeLives"] = setting.Service.ResetPwdCodeLives / 60 ctx.Data["CurDbValue"] = "" - ctx.HTML(200, tool.TplName(ctx.Params("*"))) + ctx.HTML(200, (ctx.Params("*"))) } diff --git a/routers/home.go b/routers/home.go index cbd0070a..66091579 100644 --- a/routers/home.go +++ b/routers/home.go @@ -8,17 +8,16 @@ import ( "github.com/Unknwon/paginater" "github.com/gogits/gogs/models" - "github.com/gogits/gogs/pkg/tool" "github.com/gogits/gogs/pkg/context" "github.com/gogits/gogs/pkg/setting" "github.com/gogits/gogs/routers/user" ) const ( - HOME tool.TplName = "home" - EXPLORE_REPOS tool.TplName = "explore/repos" - EXPLORE_USERS tool.TplName = "explore/users" - EXPLORE_ORGANIZATIONS tool.TplName = "explore/organizations" + HOME = "home" + EXPLORE_REPOS = "explore/repos" + EXPLORE_USERS = "explore/users" + EXPLORE_ORGANIZATIONS = "explore/organizations" ) func Home(ctx *context.Context) { @@ -84,7 +83,7 @@ type UserSearchOptions struct { Ranger func(int, int) ([]*models.User, error) PageSize int OrderBy string - TplName tool.TplName + TplName string } func RenderUserSearch(ctx *context.Context, opts *UserSearchOptions) { diff --git a/routers/install.go b/routers/install.go index 9e2bf784..2f482e45 100644 --- a/routers/install.go +++ b/routers/install.go @@ -21,7 +21,6 @@ import ( "github.com/gogits/git-module" "github.com/gogits/gogs/models" - "github.com/gogits/gogs/pkg/tool" "github.com/gogits/gogs/pkg/context" "github.com/gogits/gogs/pkg/cron" "github.com/gogits/gogs/pkg/form" @@ -30,11 +29,12 @@ import ( "github.com/gogits/gogs/pkg/setting" "github.com/gogits/gogs/pkg/ssh" "github.com/gogits/gogs/pkg/template/highlight" + "github.com/gogits/gogs/pkg/tool" "github.com/gogits/gogs/pkg/user" ) const ( - INSTALL tool.TplName = "install" + INSTALL = "install" ) func checkRunMode() { diff --git a/routers/org/members.go b/routers/org/members.go index 87686231..06d8fe6a 100644 --- a/routers/org/members.go +++ b/routers/org/members.go @@ -10,14 +10,13 @@ import ( "github.com/gogits/gogs/models" "github.com/gogits/gogs/models/errors" - "github.com/gogits/gogs/pkg/tool" "github.com/gogits/gogs/pkg/context" "github.com/gogits/gogs/pkg/setting" ) const ( - MEMBERS tool.TplName = "org/member/members" - MEMBER_INVITE tool.TplName = "org/member/invite" + MEMBERS = "org/member/members" + MEMBER_INVITE = "org/member/invite" ) func Members(ctx *context.Context) { diff --git a/routers/org/org.go b/routers/org/org.go index bedb3839..42768dd5 100644 --- a/routers/org/org.go +++ b/routers/org/org.go @@ -8,14 +8,13 @@ import ( log "gopkg.in/clog.v1" "github.com/gogits/gogs/models" - "github.com/gogits/gogs/pkg/form" - "github.com/gogits/gogs/pkg/tool" "github.com/gogits/gogs/pkg/context" + "github.com/gogits/gogs/pkg/form" "github.com/gogits/gogs/pkg/setting" ) const ( - CREATE tool.TplName = "org/create" + CREATE = "org/create" ) func Create(ctx *context.Context) { diff --git a/routers/org/setting.go b/routers/org/setting.go index 966d5afe..2ce454fe 100644 --- a/routers/org/setting.go +++ b/routers/org/setting.go @@ -11,7 +11,6 @@ import ( "github.com/gogits/gogs/models" "github.com/gogits/gogs/models/errors" - "github.com/gogits/gogs/pkg/tool" "github.com/gogits/gogs/pkg/context" "github.com/gogits/gogs/pkg/form" "github.com/gogits/gogs/pkg/setting" @@ -19,9 +18,9 @@ import ( ) const ( - SETTINGS_OPTIONS tool.TplName = "org/settings/options" - SETTINGS_DELETE tool.TplName = "org/settings/delete" - SETTINGS_WEBHOOKS tool.TplName = "org/settings/webhooks" + SETTINGS_OPTIONS = "org/settings/options" + SETTINGS_DELETE = "org/settings/delete" + SETTINGS_WEBHOOKS = "org/settings/webhooks" ) func Settings(ctx *context.Context) { diff --git a/routers/org/teams.go b/routers/org/teams.go index 54e2fe72..0c16043a 100644 --- a/routers/org/teams.go +++ b/routers/org/teams.go @@ -12,16 +12,15 @@ import ( "github.com/gogits/gogs/models" "github.com/gogits/gogs/models/errors" - "github.com/gogits/gogs/pkg/tool" "github.com/gogits/gogs/pkg/context" "github.com/gogits/gogs/pkg/form" ) const ( - TEAMS tool.TplName = "org/team/teams" - TEAM_NEW tool.TplName = "org/team/new" - TEAM_MEMBERS tool.TplName = "org/team/members" - TEAM_REPOSITORIES tool.TplName = "org/team/repositories" + TEAMS = "org/team/teams" + TEAM_NEW = "org/team/new" + TEAM_MEMBERS = "org/team/members" + TEAM_REPOSITORIES = "org/team/repositories" ) func Teams(ctx *context.Context) { diff --git a/routers/repo/branch.go b/routers/repo/branch.go index 12b62507..71e9337e 100644 --- a/routers/repo/branch.go +++ b/routers/repo/branch.go @@ -12,13 +12,12 @@ import ( "github.com/gogits/git-module" "github.com/gogits/gogs/models" - "github.com/gogits/gogs/pkg/tool" "github.com/gogits/gogs/pkg/context" ) const ( - BRANCHES_OVERVIEW tool.TplName = "repo/branches/overview" - BRANCHES_ALL tool.TplName = "repo/branches/all" + BRANCHES_OVERVIEW = "repo/branches/overview" + BRANCHES_ALL = "repo/branches/all" ) type Branch struct { diff --git a/routers/repo/commit.go b/routers/repo/commit.go index e51e81c8..19803dc6 100644 --- a/routers/repo/commit.go +++ b/routers/repo/commit.go @@ -11,14 +11,14 @@ import ( "github.com/gogits/git-module" "github.com/gogits/gogs/models" - "github.com/gogits/gogs/pkg/tool" "github.com/gogits/gogs/pkg/context" "github.com/gogits/gogs/pkg/setting" + "github.com/gogits/gogs/pkg/tool" ) const ( - COMMITS tool.TplName = "repo/commits" - DIFF tool.TplName = "repo/diff/page" + COMMITS = "repo/commits" + DIFF = "repo/diff/page" ) func RefCommits(ctx *context.Context) { diff --git a/routers/repo/editor.go b/routers/repo/editor.go index 710e70df..a8ce490a 100644 --- a/routers/repo/editor.go +++ b/routers/repo/editor.go @@ -15,18 +15,18 @@ import ( "github.com/gogits/git-module" "github.com/gogits/gogs/models" - "github.com/gogits/gogs/pkg/tool" "github.com/gogits/gogs/pkg/context" "github.com/gogits/gogs/pkg/form" "github.com/gogits/gogs/pkg/setting" "github.com/gogits/gogs/pkg/template" + "github.com/gogits/gogs/pkg/tool" ) const ( - EDIT_FILE tool.TplName = "repo/editor/edit" - EDIT_DIFF_PREVIEW tool.TplName = "repo/editor/diff_preview" - DELETE_FILE tool.TplName = "repo/editor/delete" - UPLOAD_FILE tool.TplName = "repo/editor/upload" + EDIT_FILE = "repo/editor/edit" + EDIT_DIFF_PREVIEW = "repo/editor/diff_preview" + DELETE_FILE = "repo/editor/delete" + UPLOAD_FILE = "repo/editor/upload" ) // getParentTreeFields returns list of parent tree names and corresponding tree paths diff --git a/routers/repo/issue.go b/routers/repo/issue.go index 74501477..875ff8fe 100644 --- a/routers/repo/issue.go +++ b/routers/repo/issue.go @@ -19,23 +19,23 @@ import ( "github.com/gogits/gogs/models" "github.com/gogits/gogs/models/errors" - "github.com/gogits/gogs/pkg/tool" "github.com/gogits/gogs/pkg/context" "github.com/gogits/gogs/pkg/form" "github.com/gogits/gogs/pkg/markup" "github.com/gogits/gogs/pkg/setting" + "github.com/gogits/gogs/pkg/tool" ) const ( - ISSUES tool.TplName = "repo/issue/list" - ISSUE_NEW tool.TplName = "repo/issue/new" - ISSUE_VIEW tool.TplName = "repo/issue/view" + ISSUES = "repo/issue/list" + ISSUE_NEW = "repo/issue/new" + ISSUE_VIEW = "repo/issue/view" - LABELS tool.TplName = "repo/issue/labels" + LABELS = "repo/issue/labels" - MILESTONE tool.TplName = "repo/issue/milestones" - MILESTONE_NEW tool.TplName = "repo/issue/milestone_new" - MILESTONE_EDIT tool.TplName = "repo/issue/milestone_edit" + MILESTONE = "repo/issue/milestones" + MILESTONE_NEW = "repo/issue/milestone_new" + MILESTONE_EDIT = "repo/issue/milestone_edit" ISSUE_TEMPLATE_KEY = "IssueTemplate" ) diff --git a/routers/repo/pull.go b/routers/repo/pull.go index fc1a3817..6d420121 100644 --- a/routers/repo/pull.go +++ b/routers/repo/pull.go @@ -16,17 +16,17 @@ import ( "github.com/gogits/gogs/models" "github.com/gogits/gogs/models/errors" - "github.com/gogits/gogs/pkg/tool" "github.com/gogits/gogs/pkg/context" "github.com/gogits/gogs/pkg/form" "github.com/gogits/gogs/pkg/setting" + "github.com/gogits/gogs/pkg/tool" ) const ( - FORK tool.TplName = "repo/pulls/fork" - COMPARE_PULL tool.TplName = "repo/pulls/compare" - PULL_COMMITS tool.TplName = "repo/pulls/commits" - PULL_FILES tool.TplName = "repo/pulls/files" + FORK = "repo/pulls/fork" + COMPARE_PULL = "repo/pulls/compare" + PULL_COMMITS = "repo/pulls/commits" + PULL_FILES = "repo/pulls/files" PULL_REQUEST_TEMPLATE_KEY = "PullRequestTemplate" ) diff --git a/routers/repo/release.go b/routers/repo/release.go index b9fe3ada..3643ce69 100644 --- a/routers/repo/release.go +++ b/routers/repo/release.go @@ -11,7 +11,6 @@ import ( log "gopkg.in/clog.v1" "github.com/gogits/gogs/models" - "github.com/gogits/gogs/pkg/tool" "github.com/gogits/gogs/pkg/context" "github.com/gogits/gogs/pkg/form" "github.com/gogits/gogs/pkg/markup" @@ -19,8 +18,8 @@ import ( ) const ( - RELEASES tool.TplName = "repo/release/list" - RELEASE_NEW tool.TplName = "repo/release/new" + RELEASES = "repo/release/list" + RELEASE_NEW = "repo/release/new" ) // calReleaseNumCommitsBehind calculates given release has how many commits behind release target. diff --git a/routers/repo/repo.go b/routers/repo/repo.go index 2e00a80e..2781da9a 100644 --- a/routers/repo/repo.go +++ b/routers/repo/repo.go @@ -17,15 +17,15 @@ import ( "github.com/gogits/gogs/models" "github.com/gogits/gogs/models/errors" - "github.com/gogits/gogs/pkg/tool" "github.com/gogits/gogs/pkg/context" "github.com/gogits/gogs/pkg/form" "github.com/gogits/gogs/pkg/setting" + "github.com/gogits/gogs/pkg/tool" ) const ( - CREATE tool.TplName = "repo/create" - MIGRATE tool.TplName = "repo/migrate" + CREATE = "repo/create" + MIGRATE = "repo/migrate" ) func MustBeNotBare(ctx *context.Context) { @@ -85,7 +85,7 @@ func Create(ctx *context.Context) { ctx.HTML(200, CREATE) } -func handleCreateError(ctx *context.Context, owner *models.User, err error, name string, tpl tool.TplName, form interface{}) { +func handleCreateError(ctx *context.Context, owner *models.User, err error, name, tpl string, form interface{}) { switch { case models.IsErrReachLimitOfRepo(err): ctx.RenderWithErr(ctx.Tr("repo.form.reach_limit_of_creation", owner.RepoCreationNum()), tpl, form) diff --git a/routers/repo/setting.go b/routers/repo/setting.go index 70533118..6a049ead 100644 --- a/routers/repo/setting.go +++ b/routers/repo/setting.go @@ -15,7 +15,6 @@ import ( "github.com/gogits/gogs/models" "github.com/gogits/gogs/models/errors" - "github.com/gogits/gogs/pkg/tool" "github.com/gogits/gogs/pkg/context" "github.com/gogits/gogs/pkg/form" "github.com/gogits/gogs/pkg/mailer" @@ -23,13 +22,13 @@ import ( ) const ( - SETTINGS_OPTIONS tool.TplName = "repo/settings/options" - SETTINGS_COLLABORATION tool.TplName = "repo/settings/collaboration" - SETTINGS_BRANCHES tool.TplName = "repo/settings/branches" - SETTINGS_PROTECTED_BRANCH tool.TplName = "repo/settings/protected_branch" - SETTINGS_GITHOOKS tool.TplName = "repo/settings/githooks" - SETTINGS_GITHOOK_EDIT tool.TplName = "repo/settings/githook_edit" - SETTINGS_DEPLOY_KEYS tool.TplName = "repo/settings/deploy_keys" + SETTINGS_OPTIONS = "repo/settings/options" + SETTINGS_COLLABORATION = "repo/settings/collaboration" + SETTINGS_BRANCHES = "repo/settings/branches" + SETTINGS_PROTECTED_BRANCH = "repo/settings/protected_branch" + SETTINGS_GITHOOKS = "repo/settings/githooks" + SETTINGS_GITHOOK_EDIT = "repo/settings/githook_edit" + SETTINGS_DEPLOY_KEYS = "repo/settings/deploy_keys" ) func Settings(ctx *context.Context) { diff --git a/routers/repo/view.go b/routers/repo/view.go index 1559b984..0efa8ba2 100644 --- a/routers/repo/view.go +++ b/routers/repo/view.go @@ -18,19 +18,19 @@ import ( "github.com/gogits/git-module" "github.com/gogits/gogs/models" - "github.com/gogits/gogs/pkg/tool" "github.com/gogits/gogs/pkg/context" "github.com/gogits/gogs/pkg/markup" "github.com/gogits/gogs/pkg/setting" "github.com/gogits/gogs/pkg/template" "github.com/gogits/gogs/pkg/template/highlight" + "github.com/gogits/gogs/pkg/tool" ) const ( - BARE tool.TplName = "repo/bare" - HOME tool.TplName = "repo/home" - WATCHERS tool.TplName = "repo/watchers" - FORKS tool.TplName = "repo/forks" + BARE = "repo/bare" + HOME = "repo/home" + WATCHERS = "repo/watchers" + FORKS = "repo/forks" ) func renderDirectory(ctx *context.Context, treeLink string) { @@ -304,7 +304,7 @@ func Home(ctx *context.Context) { ctx.HTML(200, HOME) } -func RenderUserCards(ctx *context.Context, total int, getter func(page int) ([]*models.User, error), tpl tool.TplName) { +func RenderUserCards(ctx *context.Context, total int, getter func(page int) ([]*models.User, error), tpl string) { page := ctx.QueryInt("page") if page <= 0 { page = 1 diff --git a/routers/repo/webhook.go b/routers/repo/webhook.go index d41ffa09..a0888877 100644 --- a/routers/repo/webhook.go +++ b/routers/repo/webhook.go @@ -16,16 +16,15 @@ import ( "github.com/gogits/gogs/models" "github.com/gogits/gogs/models/errors" - "github.com/gogits/gogs/pkg/tool" "github.com/gogits/gogs/pkg/context" "github.com/gogits/gogs/pkg/form" "github.com/gogits/gogs/pkg/setting" ) const ( - WEBHOOKS tool.TplName = "repo/settings/webhook/base" - WEBHOOK_NEW tool.TplName = "repo/settings/webhook/new" - ORG_WEBHOOK_NEW tool.TplName = "org/settings/webhook_new" + WEBHOOKS = "repo/settings/webhook/base" + WEBHOOK_NEW = "repo/settings/webhook/new" + ORG_WEBHOOK_NEW = "org/settings/webhook_new" ) func Webhooks(ctx *context.Context) { @@ -49,7 +48,7 @@ type OrgRepoCtx struct { OrgID int64 RepoID int64 Link string - NewTemplate tool.TplName + NewTemplate string } // getOrgRepoCtx determines whether this is a repo context or organization context. diff --git a/routers/repo/wiki.go b/routers/repo/wiki.go index fbaccfe5..bea4628c 100644 --- a/routers/repo/wiki.go +++ b/routers/repo/wiki.go @@ -12,17 +12,16 @@ import ( "github.com/gogits/git-module" "github.com/gogits/gogs/models" - "github.com/gogits/gogs/pkg/tool" "github.com/gogits/gogs/pkg/context" "github.com/gogits/gogs/pkg/form" "github.com/gogits/gogs/pkg/markup" ) const ( - WIKI_START tool.TplName = "repo/wiki/start" - WIKI_VIEW tool.TplName = "repo/wiki/view" - WIKI_NEW tool.TplName = "repo/wiki/new" - WIKI_PAGES tool.TplName = "repo/wiki/pages" + WIKI_START = "repo/wiki/start" + WIKI_VIEW = "repo/wiki/view" + WIKI_NEW = "repo/wiki/new" + WIKI_PAGES = "repo/wiki/pages" ) func MustEnableWiki(ctx *context.Context) { diff --git a/routers/user/auth.go b/routers/user/auth.go index 7290da75..bdbcb7e3 100644 --- a/routers/user/auth.go +++ b/routers/user/auth.go @@ -13,7 +13,6 @@ import ( "github.com/gogits/gogs/models" "github.com/gogits/gogs/models/errors" - "github.com/gogits/gogs/pkg/tool" "github.com/gogits/gogs/pkg/context" "github.com/gogits/gogs/pkg/form" "github.com/gogits/gogs/pkg/mailer" @@ -21,11 +20,11 @@ import ( ) const ( - SIGNIN tool.TplName = "user/auth/signin" - SIGNUP tool.TplName = "user/auth/signup" - ACTIVATE tool.TplName = "user/auth/activate" - FORGOT_PASSWORD tool.TplName = "user/auth/forgot_passwd" - RESET_PASSWORD tool.TplName = "user/auth/reset_passwd" + SIGNIN = "user/auth/signin" + SIGNUP = "user/auth/signup" + ACTIVATE = "user/auth/activate" + FORGOT_PASSWORD = "user/auth/forgot_passwd" + RESET_PASSWORD = "user/auth/reset_passwd" ) // AutoSignIn reads cookie and try to auto-login. diff --git a/routers/user/home.go b/routers/user/home.go index 728ff5bd..b556a176 100644 --- a/routers/user/home.go +++ b/routers/user/home.go @@ -13,17 +13,16 @@ import ( "github.com/gogits/gogs/models" "github.com/gogits/gogs/models/errors" - "github.com/gogits/gogs/pkg/tool" "github.com/gogits/gogs/pkg/context" "github.com/gogits/gogs/pkg/setting" ) const ( - DASHBOARD tool.TplName = "user/dashboard/dashboard" - NEWS_FEED tool.TplName = "user/dashboard/feeds" - ISSUES tool.TplName = "user/dashboard/issues" - PROFILE tool.TplName = "user/profile" - ORG_HOME tool.TplName = "org/home" + DASHBOARD = "user/dashboard/dashboard" + NEWS_FEED = "user/dashboard/feeds" + ISSUES = "user/dashboard/issues" + PROFILE = "user/profile" + ORG_HOME = "org/home" ) // getDashboardContextUser finds out dashboard is viewing as which context user. diff --git a/routers/user/profile.go b/routers/user/profile.go index 6e118d03..baf9a941 100644 --- a/routers/user/profile.go +++ b/routers/user/profile.go @@ -13,15 +13,14 @@ import ( "github.com/gogits/gogs/models" "github.com/gogits/gogs/models/errors" - "github.com/gogits/gogs/pkg/tool" "github.com/gogits/gogs/pkg/context" "github.com/gogits/gogs/pkg/setting" "github.com/gogits/gogs/routers/repo" ) const ( - FOLLOWERS tool.TplName = "user/meta/followers" - STARS tool.TplName = "user/meta/stars" + FOLLOWERS = "user/meta/followers" + STARS = "user/meta/stars" ) func GetUserByName(ctx *context.Context, name string) *models.User { diff --git a/routers/user/setting.go b/routers/user/setting.go index cb427dd6..9d22f038 100644 --- a/routers/user/setting.go +++ b/routers/user/setting.go @@ -14,25 +14,25 @@ import ( "github.com/gogits/gogs/models" "github.com/gogits/gogs/models/errors" - "github.com/gogits/gogs/pkg/tool" "github.com/gogits/gogs/pkg/context" "github.com/gogits/gogs/pkg/form" "github.com/gogits/gogs/pkg/mailer" "github.com/gogits/gogs/pkg/setting" + "github.com/gogits/gogs/pkg/tool" ) const ( - SETTINGS_PROFILE tool.TplName = "user/settings/profile" - SETTINGS_AVATAR tool.TplName = "user/settings/avatar" - SETTINGS_PASSWORD tool.TplName = "user/settings/password" - SETTINGS_EMAILS tool.TplName = "user/settings/email" - SETTINGS_SSH_KEYS tool.TplName = "user/settings/sshkeys" - SETTINGS_SECURITY tool.TplName = "user/settings/security" - SETTINGS_REPOSITORIES tool.TplName = "user/settings/repositories" - SETTINGS_ORGANIZATIONS tool.TplName = "user/settings/organizations" - SETTINGS_APPLICATIONS tool.TplName = "user/settings/applications" - SETTINGS_DELETE tool.TplName = "user/settings/delete" - NOTIFICATION tool.TplName = "user/notification" + SETTINGS_PROFILE = "user/settings/profile" + SETTINGS_AVATAR = "user/settings/avatar" + SETTINGS_PASSWORD = "user/settings/password" + SETTINGS_EMAILS = "user/settings/email" + SETTINGS_SSH_KEYS = "user/settings/sshkeys" + SETTINGS_SECURITY = "user/settings/security" + SETTINGS_REPOSITORIES = "user/settings/repositories" + SETTINGS_ORGANIZATIONS = "user/settings/organizations" + SETTINGS_APPLICATIONS = "user/settings/applications" + SETTINGS_DELETE = "user/settings/delete" + NOTIFICATION = "user/notification" ) func Settings(c *context.Context) {