summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorUnknwon <u@gogs.io>2016-08-09 12:56:00 -0700
committerUnknwon <u@gogs.io>2016-08-09 12:56:00 -0700
commitf70343660dc4cb585d2d322fcfb33f73f371683e (patch)
tree658bdcc07d2f360006c9b394565ab7b139b68271
parentc8b45ecc2762a9d64dbe83cafd68b137661448a5 (diff)
downloadgitea-f70343660dc4cb585d2d322fcfb33f73f371683e.tar.gz
gitea-f70343660dc4cb585d2d322fcfb33f73f371683e.zip
Little code refactoring
-rw-r--r--Makefile1
-rw-r--r--README.md2
-rw-r--r--gogs.go2
-rw-r--r--modules/template/template.go11
-rw-r--r--routers/repo/view.go31
-rw-r--r--templates/.VERSION2
6 files changed, 22 insertions, 27 deletions
diff --git a/Makefile b/Makefile
index 33cb7355d9..80ea032880 100644
--- a/Makefile
+++ b/Makefile
@@ -17,7 +17,6 @@ GOVET = go tool vet -composites=false -methods=false -structtags=false
.IGNORE: public/css/gogs.css
-# FIXME: find a way to ignore /vendor/ and /data/ directories.
govet:
$(GOVET) gogs.go
$(GOVET) models modules routers
diff --git a/README.md b/README.md
index ab8457813f..76c3624969 100644
--- a/README.md
+++ b/README.md
@@ -3,7 +3,7 @@ Gogs - Go Git Service [![Build Status](https://travis-ci.org/gogits/gogs.svg?bra
![](https://github.com/gogits/gogs/blob/master/public/img/gogs-large-resize.png?raw=true)
-##### Current tip version: 0.9.68 (see [Releases](https://github.com/gogits/gogs/releases) for binary versions)
+##### Current tip version: 0.9.69 (see [Releases](https://github.com/gogits/gogs/releases) for binary versions)
| Web | UI | Preview |
|:-------------:|:-------:|:-------:|
diff --git a/gogs.go b/gogs.go
index bf3dcfb6ad..09d8590c6c 100644
--- a/gogs.go
+++ b/gogs.go
@@ -17,7 +17,7 @@ import (
"github.com/gogits/gogs/modules/setting"
)
-const APP_VER = "0.9.68.0808"
+const APP_VER = "0.9.69.0808"
func init() {
runtime.GOMAXPROCS(runtime.NumCPU())
diff --git a/modules/template/template.go b/modules/template/template.go
index ed5b08a2ec..76ab66bcb4 100644
--- a/modules/template/template.go
+++ b/modules/template/template.go
@@ -96,7 +96,6 @@ func NewFuncMap() []template.FuncMap {
"ShortSha": base.ShortSha,
"MD5": base.EncodeMD5,
"ActionContent2Commits": ActionContent2Commits,
- "ToUtf8": ToUtf8,
"EscapePound": func(str string) string {
return strings.NewReplacer("%", "%25", "#", "%23", " ", "%20").Replace(str)
},
@@ -115,10 +114,6 @@ func Str2html(raw string) template.HTML {
return template.HTML(markdown.Sanitizer.Sanitize(raw))
}
-func Range(l int) []int {
- return make([]int, l)
-}
-
func List(l *list.List) chan interface{} {
e := l.Front()
c := make(chan interface{})
@@ -136,7 +131,7 @@ func Sha1(str string) string {
return base.EncodeSha1(str)
}
-func ToUtf8WithErr(content []byte) (error, string) {
+func ToUTF8WithErr(content []byte) (error, string) {
charsetLabel, err := base.DetectEncoding(content)
if err != nil {
return err, ""
@@ -159,8 +154,8 @@ func ToUtf8WithErr(content []byte) (error, string) {
return err, result
}
-func ToUtf8(content string) string {
- _, res := ToUtf8WithErr([]byte(content))
+func ToUTF8(content string) string {
+ _, res := ToUTF8WithErr([]byte(content))
return res
}
diff --git a/routers/repo/view.go b/routers/repo/view.go
index c13f57f426..9c495b701c 100644
--- a/routers/repo/view.go
+++ b/routers/repo/view.go
@@ -5,14 +5,13 @@
package repo
import (
- "fmt"
"bytes"
+ "fmt"
+ gotemplate "html/template"
"io/ioutil"
"path"
"strings"
- htmltemplate "html/template"
-
"github.com/Unknwon/paginater"
"github.com/gogits/git-module"
@@ -119,27 +118,29 @@ func Home(ctx *context.Context) {
if readmeExist {
ctx.Data["FileContent"] = string(markdown.Render(buf, path.Dir(treeLink), ctx.Repo.Repository.ComposeMetas()))
} else {
- filecontent := ""
- if err, content := template.ToUtf8WithErr(buf); err != nil {
+ // Building code view blocks with line number on server side.
+ var filecontent string
+ if err, content := template.ToUTF8WithErr(buf); err != nil {
if err != nil {
- log.Error(4, "Convert content encoding: %s", err)
+ log.Error(4, "ToUTF8WithErr: %s", err)
}
filecontent = string(buf)
} else {
filecontent = content
}
+
var output bytes.Buffer
lines := strings.Split(filecontent, "\n")
for index, line := range lines {
- output.WriteString(fmt.Sprintf(`<li class="L%d" rel="L%d">%s</li>`, index+1, index+1, htmltemplate.HTMLEscapeString(line)) + "\n")
+ output.WriteString(fmt.Sprintf(`<li class="L%d" rel="L%d">%s</li>`, index+1, index+1, gotemplate.HTMLEscapeString(line)) + "\n")
}
- ctx.Data["FileContent"] = htmltemplate.HTML(output.String())
+ ctx.Data["FileContent"] = gotemplate.HTML(output.String())
output.Reset()
for i := 0; i < len(lines); i++ {
output.WriteString(fmt.Sprintf(`<span id="L%d">%d</span>`, i+1, i+1))
}
- ctx.Data["LineNums"] = htmltemplate.HTML(output.String())
+ ctx.Data["LineNums"] = gotemplate.HTML(output.String())
}
}
}
@@ -225,21 +226,21 @@ func Home(ctx *context.Context) {
ctx.Data["Reponame"] = repoName
var treenames []string
- Paths := make([]string, 0)
+ paths := make([]string, 0)
if len(treename) > 0 {
treenames = strings.Split(treename, "/")
- for i, _ := range treenames {
- Paths = append(Paths, strings.Join(treenames[0:i+1], "/"))
+ for i := range treenames {
+ paths = append(paths, strings.Join(treenames[0:i+1], "/"))
}
ctx.Data["HasParentPath"] = true
- if len(Paths)-2 >= 0 {
- ctx.Data["ParentPath"] = "/" + Paths[len(Paths)-2]
+ if len(paths)-2 >= 0 {
+ ctx.Data["ParentPath"] = "/" + paths[len(paths)-2]
}
}
- ctx.Data["Paths"] = Paths
+ ctx.Data["Paths"] = paths
ctx.Data["TreeName"] = treename
ctx.Data["Treenames"] = treenames
ctx.Data["TreePath"] = treePath
diff --git a/templates/.VERSION b/templates/.VERSION
index 834353f944..ec9912cd1e 100644
--- a/templates/.VERSION
+++ b/templates/.VERSION
@@ -1 +1 @@
-0.9.68.0808 \ No newline at end of file
+0.9.69.0808 \ No newline at end of file