mirror of
https://github.com/go-gitea/gitea.git
synced 2024-05-11 05:55:29 +00:00
move templateFuncs to one file, add middleware context.
This commit is contained in:
@@ -4,17 +4,9 @@
|
||||
|
||||
package base
|
||||
|
||||
import (
|
||||
"github.com/codegangsta/martini"
|
||||
)
|
||||
import ()
|
||||
|
||||
type (
|
||||
// Type TmplData represents data in the templates.
|
||||
TmplData map[string]interface{}
|
||||
)
|
||||
|
||||
func InitContext() martini.Handler {
|
||||
return func(context martini.Context) {
|
||||
context.Map(TmplData{})
|
||||
}
|
||||
}
|
||||
|
@@ -15,7 +15,11 @@ import (
|
||||
"github.com/Unknwon/goconfig"
|
||||
)
|
||||
|
||||
var Cfg *goconfig.ConfigFile
|
||||
var (
|
||||
AppVer string
|
||||
AppName string
|
||||
Cfg *goconfig.ConfigFile
|
||||
)
|
||||
|
||||
func exeDir() (string, error) {
|
||||
file, err := exec.LookPath(os.Args[0])
|
||||
@@ -52,4 +56,6 @@ func init() {
|
||||
}
|
||||
}
|
||||
Cfg.BlockMode = false
|
||||
|
||||
AppName = Cfg.MustValue("", "APP_NAME")
|
||||
}
|
||||
|
28
modules/base/template.go
Normal file
28
modules/base/template.go
Normal file
@@ -0,0 +1,28 @@
|
||||
// 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 base
|
||||
|
||||
import (
|
||||
"html/template"
|
||||
)
|
||||
|
||||
func Str2html(raw string) template.HTML {
|
||||
return template.HTML(raw)
|
||||
}
|
||||
|
||||
var TemplateFuncs template.FuncMap = map[string]interface{}{
|
||||
"AppName": func() string {
|
||||
return AppName
|
||||
},
|
||||
"AppVer": func() string {
|
||||
return AppVer
|
||||
},
|
||||
"str2html": Str2html,
|
||||
"TimeSince": TimeSince,
|
||||
"Subtract": Subtract,
|
||||
"ActionIcon": ActionIcon,
|
||||
"ActionDesc": ActionDesc,
|
||||
"DateFormat": DateFormat,
|
||||
}
|
@@ -8,7 +8,6 @@ import (
|
||||
"crypto/md5"
|
||||
"encoding/hex"
|
||||
"fmt"
|
||||
"html/template"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
@@ -30,10 +29,6 @@ const (
|
||||
Year = 12 * Month
|
||||
)
|
||||
|
||||
func Str2html(raw string) template.HTML {
|
||||
return template.HTML(raw)
|
||||
}
|
||||
|
||||
// TimeSince calculates the time interval and generate user-friendly string.
|
||||
func TimeSince(then time.Time) string {
|
||||
now := time.Now()
|
||||
|
Reference in New Issue
Block a user