Browse Source

Little code refactoring

Unknwon 3 years ago
parent
commit
f70343660d
6 changed files with 22 additions and 27 deletions
  1. 0 1
      Makefile
  2. 1 1
      README.md
  3. 1 1
      gogs.go
  4. 3 8
      modules/template/template.go
  5. 16 15
      routers/repo/view.go
  6. 1 1
      templates/.VERSION

+ 0 - 1
Makefile

@@ -17,7 +17,6 @@ GOVET = go tool vet -composites=false -methods=false -structtags=false
17 17
 
18 18
 .IGNORE: public/css/gogs.css
19 19
 
20
-# FIXME: find a way to ignore /vendor/ and /data/ directories.
21 20
 govet:
22 21
 	$(GOVET) gogs.go 
23 22
 	$(GOVET) models modules routers

+ 1 - 1
README.md

@@ -3,7 +3,7 @@ Gogs - Go Git Service [![Build Status](https://travis-ci.org/gogits/gogs.svg?bra
3 3
 
4 4
 ![](https://github.com/gogits/gogs/blob/master/public/img/gogs-large-resize.png?raw=true)
5 5
 
6
-##### Current tip version: 0.9.68 (see [Releases](https://github.com/gogits/gogs/releases) for binary versions)
6
+##### Current tip version: 0.9.69 (see [Releases](https://github.com/gogits/gogs/releases) for binary versions)
7 7
 
8 8
 | Web | UI  | Preview  |
9 9
 |:-------------:|:-------:|:-------:|

+ 1 - 1
gogs.go

@@ -17,7 +17,7 @@ import (
17 17
 	"github.com/gogits/gogs/modules/setting"
18 18
 )
19 19
 
20
-const APP_VER = "0.9.68.0808"
20
+const APP_VER = "0.9.69.0808"
21 21
 
22 22
 func init() {
23 23
 	runtime.GOMAXPROCS(runtime.NumCPU())

+ 3 - 8
modules/template/template.go

@@ -96,7 +96,6 @@ func NewFuncMap() []template.FuncMap {
96 96
 		"ShortSha":          base.ShortSha,
97 97
 		"MD5":               base.EncodeMD5,
98 98
 		"ActionContent2Commits": ActionContent2Commits,
99
-		"ToUtf8":                ToUtf8,
100 99
 		"EscapePound": func(str string) string {
101 100
 			return strings.NewReplacer("%", "%25", "#", "%23", " ", "%20").Replace(str)
102 101
 		},
@@ -115,10 +114,6 @@ func Str2html(raw string) template.HTML {
115 114
 	return template.HTML(markdown.Sanitizer.Sanitize(raw))
116 115
 }
117 116
 
118
-func Range(l int) []int {
119
-	return make([]int, l)
120
-}
121
-
122 117
 func List(l *list.List) chan interface{} {
123 118
 	e := l.Front()
124 119
 	c := make(chan interface{})
@@ -136,7 +131,7 @@ func Sha1(str string) string {
136 131
 	return base.EncodeSha1(str)
137 132
 }
138 133
 
139
-func ToUtf8WithErr(content []byte) (error, string) {
134
+func ToUTF8WithErr(content []byte) (error, string) {
140 135
 	charsetLabel, err := base.DetectEncoding(content)
141 136
 	if err != nil {
142 137
 		return err, ""
@@ -159,8 +154,8 @@ func ToUtf8WithErr(content []byte) (error, string) {
159 154
 	return err, result
160 155
 }
161 156
 
162
-func ToUtf8(content string) string {
163
-	_, res := ToUtf8WithErr([]byte(content))
157
+func ToUTF8(content string) string {
158
+	_, res := ToUTF8WithErr([]byte(content))
164 159
 	return res
165 160
 }
166 161
 

+ 16 - 15
routers/repo/view.go

@@ -5,14 +5,13 @@
5 5
 package repo
6 6
 
7 7
 import (
8
-	"fmt"
9 8
 	"bytes"
9
+	"fmt"
10
+	gotemplate "html/template"
10 11
 	"io/ioutil"
11 12
 	"path"
12 13
 	"strings"
13 14
 
14
-	htmltemplate "html/template"
15
-
16 15
 	"github.com/Unknwon/paginater"
17 16
 
18 17
 	"github.com/gogits/git-module"
@@ -119,27 +118,29 @@ func Home(ctx *context.Context) {
119 118
 					if readmeExist {
120 119
 						ctx.Data["FileContent"] = string(markdown.Render(buf, path.Dir(treeLink), ctx.Repo.Repository.ComposeMetas()))
121 120
 					} else {
122
-						filecontent := ""
123
-						if err, content := template.ToUtf8WithErr(buf); err != nil {
121
+						// Building code view blocks with line number on server side.
122
+						var filecontent string
123
+						if err, content := template.ToUTF8WithErr(buf); err != nil {
124 124
 							if err != nil {
125
-								log.Error(4, "Convert content encoding: %s", err)
125
+								log.Error(4, "ToUTF8WithErr: %s", err)
126 126
 							}
127 127
 							filecontent = string(buf)
128 128
 						} else {
129 129
 							filecontent = content
130 130
 						}
131
+
131 132
 						var output bytes.Buffer
132 133
 						lines := strings.Split(filecontent, "\n")
133 134
 						for index, line := range lines {
134
-							output.WriteString(fmt.Sprintf(`<li class="L%d" rel="L%d">%s</li>`, index+1, index+1, htmltemplate.HTMLEscapeString(line)) + "\n")
135
+							output.WriteString(fmt.Sprintf(`<li class="L%d" rel="L%d">%s</li>`, index+1, index+1, gotemplate.HTMLEscapeString(line)) + "\n")
135 136
 						}
136
-						ctx.Data["FileContent"] = htmltemplate.HTML(output.String())
137
+						ctx.Data["FileContent"] = gotemplate.HTML(output.String())
137 138
 
138 139
 						output.Reset()
139 140
 						for i := 0; i < len(lines); i++ {
140 141
 							output.WriteString(fmt.Sprintf(`<span id="L%d">%d</span>`, i+1, i+1))
141 142
 						}
142
-						ctx.Data["LineNums"] = htmltemplate.HTML(output.String())
143
+						ctx.Data["LineNums"] = gotemplate.HTML(output.String())
143 144
 					}
144 145
 				}
145 146
 			}
@@ -225,21 +226,21 @@ func Home(ctx *context.Context) {
225 226
 	ctx.Data["Reponame"] = repoName
226 227
 
227 228
 	var treenames []string
228
-	Paths := make([]string, 0)
229
+	paths := make([]string, 0)
229 230
 
230 231
 	if len(treename) > 0 {
231 232
 		treenames = strings.Split(treename, "/")
232
-		for i, _ := range treenames {
233
-			Paths = append(Paths, strings.Join(treenames[0:i+1], "/"))
233
+		for i := range treenames {
234
+			paths = append(paths, strings.Join(treenames[0:i+1], "/"))
234 235
 		}
235 236
 
236 237
 		ctx.Data["HasParentPath"] = true
237
-		if len(Paths)-2 >= 0 {
238
-			ctx.Data["ParentPath"] = "/" + Paths[len(Paths)-2]
238
+		if len(paths)-2 >= 0 {
239
+			ctx.Data["ParentPath"] = "/" + paths[len(paths)-2]
239 240
 		}
240 241
 	}
241 242
 
242
-	ctx.Data["Paths"] = Paths
243
+	ctx.Data["Paths"] = paths
243 244
 	ctx.Data["TreeName"] = treename
244 245
 	ctx.Data["Treenames"] = treenames
245 246
 	ctx.Data["TreePath"] = treePath

+ 1 - 1
templates/.VERSION

@@ -1 +1 @@
1
-0.9.68.0808
1
+0.9.69.0808