Merge pull request #2528 from andreynering/diff-sintax-highlight-733

Enable syntax highlighting on diff view
This commit is contained in:
Unknwon 2016-02-07 11:49:11 -05:00
commit f15a2f9b25
10 changed files with 88 additions and 61 deletions

View file

@ -28,7 +28,7 @@ import (
"github.com/gogits/gogs/modules/middleware"
"github.com/gogits/gogs/modules/setting"
"github.com/gogits/gogs/modules/ssh"
"github.com/gogits/gogs/modules/template"
"github.com/gogits/gogs/modules/template/highlight"
"github.com/gogits/gogs/modules/user"
)
@ -56,7 +56,7 @@ func NewServices() {
// GlobalInit is for global configuration reload-able.
func GlobalInit() {
setting.NewContext()
template.NewContext()
highlight.NewContext()
log.Trace("Custom path: %s", setting.CustomPath)
log.Trace("Log path: %s", setting.LogRootPath)
models.LoadConfigs()

View file

@ -183,6 +183,7 @@ func Diff(ctx *middleware.Context) {
ctx.Data["BeforeSourcePath"] = setting.AppSubUrl + "/" + path.Join(userName, repoName, "src", parents[0])
}
ctx.Data["RawPath"] = setting.AppSubUrl + "/" + path.Join(userName, repoName, "raw", commitID)
ctx.Data["RequireHighlightJS"] = true
ctx.HTML(200, DIFF)
}

View file

@ -362,6 +362,7 @@ func ViewPullFiles(ctx *middleware.Context) {
ctx.Data["SourcePath"] = setting.AppSubUrl + "/" + path.Join(headTarget, "src", endCommitID)
ctx.Data["BeforeSourcePath"] = setting.AppSubUrl + "/" + path.Join(headTarget, "src", startCommitID)
ctx.Data["RawPath"] = setting.AppSubUrl + "/" + path.Join(headTarget, "raw", endCommitID)
ctx.Data["RequireHighlightJS"] = true
ctx.HTML(200, PULL_FILES)
}
@ -538,6 +539,7 @@ func CompareAndPullRequest(ctx *middleware.Context) {
ctx.Data["Title"] = ctx.Tr("repo.pulls.compare_changes")
ctx.Data["PageIsComparePull"] = true
ctx.Data["IsDiffCompare"] = true
ctx.Data["RequireHighlightJS"] = true
renderAttachmentSettings(ctx)
headUser, headRepo, headGitRepo, prInfo, baseBranch, headBranch := ParseCompareInfo(ctx)

View file

@ -19,6 +19,7 @@ import (
"github.com/gogits/gogs/modules/log"
"github.com/gogits/gogs/modules/middleware"
"github.com/gogits/gogs/modules/template"
"github.com/gogits/gogs/modules/template/highlight"
)
const (
@ -79,7 +80,7 @@ func Home(ctx *middleware.Context) {
ctx.Data["FileSize"] = blob.Size()
ctx.Data["IsFile"] = true
ctx.Data["FileName"] = blob.Name()
ctx.Data["HighlightClass"] = template.FileNameToHighlightClass(blob.Name())
ctx.Data["HighlightClass"] = highlight.FileNameToHighlightClass(blob.Name())
ctx.Data["FileLink"] = rawLink + "/" + treename
buf := make([]byte, 1024)