forked from fzipp/pythia
-
Notifications
You must be signed in to change notification settings - Fork 0
/
template.go
33 lines (27 loc) · 964 Bytes
/
template.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
// Copyright 2013 Frederik Zipp. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package main
import (
"go/ast"
"go/build"
"html/template"
"path/filepath"
"strings"
"github.com/fzipp/pythia/static"
)
var funcs = template.FuncMap{
"filename": func(f *ast.File) string { return prog.Fset.File(f.Pos()).Name() },
"base": filepath.Base,
"stdpkg": isStandardPackage,
}
// parseTemplate reads and parses an HTML template from the static file map.
func parseTemplate(file string) *template.Template {
return template.Must(template.New(file).Funcs(funcs).Parse(static.Files[file]))
}
// isStandardPackage returns true if the package for the given import
// path is a package of the standard library.
func isStandardPackage(path string) bool {
p, _ := build.Import(path, "", build.FindOnly)
return p.Goroot && p.ImportPath != "" && !strings.Contains(p.ImportPath, ".")
}