mirror of
https://github.com/golang/go
synced 2024-11-25 11:57:58 -07:00
godoc: add -template flag to specify custom templates
R=gri, niemeyer, rsc1 CC=golang-dev https://golang.org/cl/4291059
This commit is contained in:
parent
76061f7240
commit
005fe41125
@ -65,6 +65,7 @@ var (
|
|||||||
tabwidth = flag.Int("tabwidth", 4, "tab width")
|
tabwidth = flag.Int("tabwidth", 4, "tab width")
|
||||||
showTimestamps = flag.Bool("timestamps", true, "show timestamps with directory listings")
|
showTimestamps = flag.Bool("timestamps", true, "show timestamps with directory listings")
|
||||||
maxResults = flag.Int("maxresults", 10000, "maximum number of full text search results shown")
|
maxResults = flag.Int("maxresults", 10000, "maximum number of full text search results shown")
|
||||||
|
templateDir = flag.String("templates", "", "directory containing alternate template files")
|
||||||
|
|
||||||
// file system mapping
|
// file system mapping
|
||||||
fsMap Mapping // user-defined mapping
|
fsMap Mapping // user-defined mapping
|
||||||
@ -635,6 +636,14 @@ var fmap = template.FormatterMap{
|
|||||||
|
|
||||||
func readTemplate(name string) *template.Template {
|
func readTemplate(name string) *template.Template {
|
||||||
path := filepath.Join(*goroot, "lib", "godoc", name)
|
path := filepath.Join(*goroot, "lib", "godoc", name)
|
||||||
|
if *templateDir != "" {
|
||||||
|
defaultpath := path
|
||||||
|
path = filepath.Join(*templateDir, name)
|
||||||
|
if _, err := os.Stat(path); err != nil {
|
||||||
|
log.Print("readTemplate:", err)
|
||||||
|
path = defaultpath
|
||||||
|
}
|
||||||
|
}
|
||||||
data, err := ioutil.ReadFile(path)
|
data, err := ioutil.ReadFile(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("ReadFile %s: %v", path, err)
|
log.Fatalf("ReadFile %s: %v", path, err)
|
||||||
|
Loading…
Reference in New Issue
Block a user