Esempio n. 1
0
func ExampleAppendStr() {
	s := []string{"a"}
	s = com.AppendStr(s, "a")
	s = com.AppendStr(s, "b")
	fmt.Println(s)
	// Output: [a b]
}
Esempio n. 2
0
func InitSetting() {
	var err error
	WorkDir, err = os.Getwd()
	if err != nil {
		log.Fatal("Fail to get work directory: %v", err)
	}

	confPath := path.Join(WorkDir, ".bra.toml")
	if !com.IsFile(confPath) {
		log.Fatal(".bra.toml not found in work directory")
	} else if _, err = toml.DecodeFile(confPath, &Cfg); err != nil {
		log.Fatal("Fail to decode .bra.toml: %v", err)
	}

	if Cfg.Run.InterruptTimeout == 0 {
		Cfg.Run.InterruptTimeout = 15
	}

	// Init default ignore lists.
	Cfg.Run.IgnoreDirs = com.AppendStr(Cfg.Run.IgnoreDirs, ".git")
	Cfg.Run.IgnoreRegexps = make([]*regexp.Regexp, len(Cfg.Run.IgnoreFiles))
	for i, regStr := range Cfg.Run.IgnoreFiles {
		Cfg.Run.IgnoreRegexps[i], err = regexp.Compile(regStr)
		if err != nil {
			log.Fatal("Invalid regexp[%s]: %v", regStr, err)
		}
	}
}
Esempio n. 3
0
// Render renders source code to HTML.
// Note that you have to call Build before you call this method.
func (w *Walker) Render() (map[string][]byte, error) {
	htmls := make(map[string][]byte)
	files := make(map[string]File)
	srcs := w.SrcFiles
	imports := make([]string, 0, 10)

	for name, src := range srcs {
		pkg, err := w.Build(&WalkRes{
			WalkDepth: WD_All,
			WalkType:  WT_Memory,
			WalkMode:  WM_NoReadme | WM_NoExample,
			Srcs:      []*Source{src},
			BuildAll:  true,
		})

		if err != nil {
			return nil, errors.New("hv.Walker.Render -> " + err.Error())
		}

		files[name] = pkg.File

		for _, v := range w.Pdoc.Imports {
			imports = com.AppendStr(imports, v)
		}
	}

	r := Render{
		Links:     GetLinks(w.Pdoc.ImportPath, imports, files),
		FilteList: make(map[string]bool),
	}

	for name := range srcs {
		htmls[name] = r.Render(name, srcs[name].Data())
		//com.SaveFile(name+".hmtl", htmls[name])
	}
	return htmls, nil
}