コード例 #1
0
ファイル: main.go プロジェクト: nathankerr/godocbook
func newDoc() *doc {
	d := doc{}

	// build an fs including GOROOT and GOPATH
	d.fs = vfs.NameSpace{}
	fsGate := make(chan bool, 20)
	d.fs.Bind("/", gatefs.New(vfs.OS(runtime.GOROOT()), fsGate), "/", vfs.BindReplace)

	box, err := rice.FindBox("templates")
	if err != nil {
		log.Fatalln(err)
	}

	// create a presentation based on the fs
	corpus := godoc.NewCorpus(d.fs)
	d.pres = godoc.NewPresentation(corpus)
	packageText, err := box.String("package.txt")
	if err != nil {
		log.Fatalln(err)
	}
	d.pres.PackageText, err = template.New("package.txt").Funcs(d.pres.FuncMap()).Delims("[", "]").Parse(packageText)
	if err != nil {
		log.Fatalln(err)
	}

	return &d
}
コード例 #2
0
ファイル: cmdline.go プロジェクト: nathankerr/godocbook
// paths determines the paths to use.
//
// If we are passed an operating system path like . or ./foo or /foo/bar or c:\mysrc,
// we need to map that path somewhere in the fs name space so that routines
// like getPageInfo will see it.  We use the arbitrarily-chosen virtual path "/target"
// for this.  That is, if we get passed a directory like the above, we map that
// directory so that getPageInfo sees it as /target.
// Returns the absolute and relative paths.
func paths(fs vfs.NameSpace, pres *Presentation, path string) (string, string) {
	if filepath.IsAbs(path) {
		fs.Bind(target, vfs.OS(path), "/", vfs.BindReplace)
		return target, target
	}
	if build.IsLocalImport(path) {
		cwd, _ := os.Getwd() // ignore errors
		path = filepath.Join(cwd, path)
		fs.Bind(target, vfs.OS(path), "/", vfs.BindReplace)
		return target, target
	}
	if bp, _ := build.Import(path, "", build.FindOnly); bp.Dir != "" && bp.ImportPath != "" {
		fs.Bind(target, vfs.OS(bp.Dir), "/", vfs.BindReplace)
		return target, bp.ImportPath
	}
	return pathpkg.Join(pres.PkgFSRoot(), path), path
}