chore: rename few consts to camel case ()

pull/6728/head
Joe Chen 2022-01-13 11:27:16 +08:00 committed by GitHub
parent c8476b1c2e
commit 9ae80a6173
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 39 additions and 39 deletions

View File

@ -228,7 +228,7 @@ func (repo *Repository) AfterSet(colName string, _ xorm.Cell) {
repo.NumOpenMilestones = repo.NumMilestones - repo.NumClosedMilestones
case "external_tracker_style":
if len(repo.ExternalTrackerStyle) == 0 {
repo.ExternalTrackerStyle = markup.ISSUE_NAME_STYLE_NUMERIC
repo.ExternalTrackerStyle = markup.IssueNameStyleNumeric
}
case "created_unix":
repo.Created = time.Unix(repo.CreatedUnix, 0).Local()
@ -445,10 +445,10 @@ func (repo *Repository) ComposeMetas() map[string]string {
repo.ExternalMetas["format"] = repo.ExternalTrackerFormat
switch repo.ExternalTrackerStyle {
case markup.ISSUE_NAME_STYLE_ALPHANUMERIC:
repo.ExternalMetas["style"] = markup.ISSUE_NAME_STYLE_ALPHANUMERIC
case markup.IssueNameStyleAlphanumeric:
repo.ExternalMetas["style"] = markup.IssueNameStyleAlphanumeric
default:
repo.ExternalMetas["style"] = markup.ISSUE_NAME_STYLE_NUMERIC
repo.ExternalMetas["style"] = markup.IssueNameStyleNumeric
}
}

View File

@ -35,15 +35,15 @@ func TestRepository_ComposeMetas(t *testing.T) {
repo.EnableExternalTracker = true
// Default to numeric issue style
assert.Equal(t, markup.ISSUE_NAME_STYLE_NUMERIC, repo.ComposeMetas()["style"])
assert.Equal(t, markup.IssueNameStyleNumeric, repo.ComposeMetas()["style"])
repo.ExternalMetas = nil
repo.ExternalTrackerStyle = markup.ISSUE_NAME_STYLE_NUMERIC
assert.Equal(t, markup.ISSUE_NAME_STYLE_NUMERIC, repo.ComposeMetas()["style"])
repo.ExternalTrackerStyle = markup.IssueNameStyleNumeric
assert.Equal(t, markup.IssueNameStyleNumeric, repo.ComposeMetas()["style"])
repo.ExternalMetas = nil
repo.ExternalTrackerStyle = markup.ISSUE_NAME_STYLE_ALPHANUMERIC
assert.Equal(t, markup.ISSUE_NAME_STYLE_ALPHANUMERIC, repo.ComposeMetas()["style"])
repo.ExternalTrackerStyle = markup.IssueNameStyleAlphanumeric
assert.Equal(t, markup.IssueNameStyleAlphanumeric, repo.ComposeMetas()["style"])
repo.ExternalMetas = nil
metas := repo.ComposeMetas()

View File

@ -105,7 +105,7 @@ func (r *MarkdownRenderer) AutoLink(out *bytes.Buffer, link []byte, kind int) {
}
// ListItem defines how list items should be processed to produce corresponding HTML elements.
func (options *MarkdownRenderer) ListItem(out *bytes.Buffer, text []byte, flags int) {
func (r *MarkdownRenderer) ListItem(out *bytes.Buffer, text []byte, flags int) {
// Detect procedures to draw checkboxes.
switch {
case bytes.HasPrefix(text, []byte("[ ] ")):
@ -113,7 +113,7 @@ func (options *MarkdownRenderer) ListItem(out *bytes.Buffer, text []byte, flags
case bytes.HasPrefix(text, []byte("[x] ")):
text = append([]byte(`<input type="checkbox" disabled="" checked="" />`), text[3:]...)
}
options.Renderer.ListItem(out, text, flags)
r.Renderer.ListItem(out, text, flags)
}
// RawMarkdown renders content in Markdown syntax to HTML without handling special links.
@ -162,5 +162,5 @@ func RawMarkdown(body []byte, urlPrefix string) []byte {
// Markdown takes a string or []byte and renders to HTML in Markdown syntax with special links.
func Markdown(input interface{}, urlPrefix string, metas map[string]string) []byte {
return Render(MARKDOWN, input, urlPrefix, metas)
return Render(TypeMarkdown, input, urlPrefix, metas)
}

View File

@ -29,8 +29,8 @@ func IsIPythonNotebook(name string) bool {
}
const (
ISSUE_NAME_STYLE_NUMERIC = "numeric"
ISSUE_NAME_STYLE_ALPHANUMERIC = "alphanumeric"
IssueNameStyleNumeric = "numeric"
IssueNameStyleAlphanumeric = "alphanumeric"
)
var (
@ -90,7 +90,7 @@ func RenderIssueIndexPattern(rawBytes []byte, urlPrefix string, metas map[string
urlPrefix = cutoutVerbosePrefix(urlPrefix)
pattern := IssueNumericPattern
if metas["style"] == ISSUE_NAME_STYLE_ALPHANUMERIC {
if metas["style"] == IssueNameStyleAlphanumeric {
pattern = IssueAlphanumericPattern
}
@ -105,7 +105,7 @@ func RenderIssueIndexPattern(rawBytes []byte, urlPrefix string, metas map[string
link = fmt.Sprintf(`<a href="%s/issues/%s">%s</a>`, urlPrefix, m[1:], m)
} else {
// Support for external issue tracker
if metas["style"] == ISSUE_NAME_STYLE_ALPHANUMERIC {
if metas["style"] == IssueNameStyleAlphanumeric {
metas["index"] = string(m)
} else {
metas["index"] = string(m[1:])
@ -243,7 +243,7 @@ func postProcessHTML(rawHTML []byte, urlPrefix string, metas map[string]string)
buf := bytes.NewBuffer(nil)
tokenizer := html.NewTokenizer(bytes.NewReader(rawHTML))
OUTER_LOOP:
outerLoop:
for html.ErrorToken != tokenizer.Next() {
token := tokenizer.Token()
switch token.Type {
@ -255,7 +255,7 @@ OUTER_LOOP:
if tagName == "img" {
wrapImgWithLink(urlPrefix, buf, token)
continue OUTER_LOOP
continue outerLoop
}
buf.WriteString(token.String())
@ -268,7 +268,7 @@ OUTER_LOOP:
// Copy the token to the output verbatim
buf.WriteString(token.String())
// Stack number doesn't increate for tags without end tags.
// Stack number doesn't increase for tags without end tags.
if token.Type == html.StartTagToken && !com.IsSliceContainsStr(noEndTags, token.Data) {
stackNum++
}
@ -281,7 +281,7 @@ OUTER_LOOP:
}
}
}
continue OUTER_LOOP
continue outerLoop
}
if !com.IsSliceContainsStr(noEndTags, tagName) {
@ -315,23 +315,23 @@ OUTER_LOOP:
type Type string
const (
UNRECOGNIZED Type = "unrecognized"
MARKDOWN Type = "markdown"
ORG_MODE Type = "orgmode"
IPYTHON_NOTEBOOK Type = "ipynb"
TypeUnrecognized Type = "unrecognized"
TypeMarkdown Type = "markdown"
TypeOrgMode Type = "orgmode"
TypeIPythonNotebook Type = "ipynb"
)
// Detect returns best guess of a markup type based on file name.
func Detect(filename string) Type {
switch {
case IsMarkdownFile(filename):
return MARKDOWN
return TypeMarkdown
case IsOrgModeFile(filename):
return ORG_MODE
return TypeOrgMode
case IsIPythonNotebook(filename):
return IPYTHON_NOTEBOOK
return TypeIPythonNotebook
default:
return UNRECOGNIZED
return TypeUnrecognized
}
}
@ -350,9 +350,9 @@ func Render(typ Type, input interface{}, urlPrefix string, metas map[string]stri
urlPrefix = strings.TrimRight(strings.Replace(urlPrefix, " ", "%20", -1), "/")
var rawHTML []byte
switch typ {
case MARKDOWN:
case TypeMarkdown:
rawHTML = RawMarkdown(rawBytes, urlPrefix)
case ORG_MODE:
case TypeOrgMode:
rawHTML = RawOrgMode(rawBytes, urlPrefix)
default:
return rawBytes // Do nothing if syntax type is not recognized

View File

@ -110,7 +110,7 @@ func Test_RenderIssueIndexPattern(t *testing.T) {
"format": "https://someurl.com/{user}/{repo}/{index}",
"user": "someuser",
"repo": "somerepo",
"style": ISSUE_NAME_STYLE_NUMERIC,
"style": IssueNameStyleNumeric,
}
tests := []struct {
@ -156,7 +156,7 @@ func Test_RenderIssueIndexPattern(t *testing.T) {
"format": "https://someurl.com/{user}/{repo}/?b={index}",
"user": "someuser",
"repo": "somerepo",
"style": ISSUE_NAME_STYLE_ALPHANUMERIC,
"style": IssueNameStyleAlphanumeric,
}
tests := []struct {

View File

@ -36,5 +36,5 @@ func RawOrgMode(body []byte, urlPrefix string) (result []byte) {
// OrgMode takes a string or []byte and renders to HTML in Org-mode syntax with special links.
func OrgMode(input interface{}, urlPrefix string, metas map[string]string) []byte {
return Render(ORG_MODE, input, urlPrefix, metas)
return Render(TypeOrgMode, input, urlPrefix, metas)
}

View File

@ -85,13 +85,13 @@ func renderDirectory(c *context.Context, treeLink string) {
c.Data["FileName"] = readmeFile.Name()
if isTextFile {
switch markup.Detect(readmeFile.Name()) {
case markup.MARKDOWN:
case markup.TypeMarkdown:
c.Data["IsMarkdown"] = true
p = markup.Markdown(p, treeLink, c.Repo.Repository.ComposeMetas())
case markup.ORG_MODE:
case markup.TypeOrgMode:
c.Data["IsMarkdown"] = true
p = markup.OrgMode(p, treeLink, c.Repo.Repository.ComposeMetas())
case markup.IPYTHON_NOTEBOOK:
case markup.TypeIPythonNotebook:
c.Data["IsIPythonNotebook"] = true
c.Data["RawFileLink"] = c.Repo.RepoLink + "/raw/" + path.Join(c.Repo.BranchName, c.Repo.TreePath, readmeFile.Name())
default:
@ -154,13 +154,13 @@ func renderFile(c *context.Context, entry *git.TreeEntry, treeLink, rawLink stri
c.Data["ReadmeExist"] = markup.IsReadmeFile(blob.Name())
switch markup.Detect(blob.Name()) {
case markup.MARKDOWN:
case markup.TypeMarkdown:
c.Data["IsMarkdown"] = true
c.Data["FileContent"] = string(markup.Markdown(p, path.Dir(treeLink), c.Repo.Repository.ComposeMetas()))
case markup.ORG_MODE:
case markup.TypeOrgMode:
c.Data["IsMarkdown"] = true
c.Data["FileContent"] = string(markup.OrgMode(p, path.Dir(treeLink), c.Repo.Repository.ComposeMetas()))
case markup.IPYTHON_NOTEBOOK:
case markup.TypeIPythonNotebook:
c.Data["IsIPythonNotebook"] = true
default:
// Building code view blocks with line number on server side.