本文整理匯總了Golang中github.com/Unknwon/gowalker/hv.Package.UserExamples方法的典型用法代碼示例。如果您正苦於以下問題:Golang Package.UserExamples方法的具體用法?Golang Package.UserExamples怎麽用?Golang Package.UserExamples使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/Unknwon/gowalker/hv.Package
的用法示例。
在下文中一共展示了Package.UserExamples方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: renderDoc
func renderDoc(this *HomeRouter, pdoc *hv.Package, q, tag, docPath string) bool {
this.Data["PkgFullIntro"] = pdoc.Doc
var buf bytes.Buffer
links := make([]*utils.Link, 0, len(pdoc.Types)+len(pdoc.Imports)+len(pdoc.TestImports)+
len(pdoc.Funcs)+10)
// Get all types, functions and import packages
for _, t := range pdoc.Types {
links = append(links, &utils.Link{
Name: t.Name,
Comment: template.HTMLEscapeString(t.Doc),
})
buf.WriteString("'" + t.Name + "',")
}
for _, f := range pdoc.Funcs {
links = append(links, &utils.Link{
Name: f.Name,
Comment: template.HTMLEscapeString(f.Doc),
})
buf.WriteString("'" + f.Name + "',")
}
for _, t := range pdoc.Types {
for _, f := range t.Funcs {
links = append(links, &utils.Link{
Name: f.Name,
Comment: template.HTMLEscapeString(f.Doc),
})
buf.WriteString("'" + f.Name + "',")
}
for _, m := range t.Methods {
buf.WriteString("'" + t.Name + "_" + m.Name + "',")
}
}
// Ignore C.
for _, v := range append(pdoc.Imports, pdoc.TestImports...) {
if v != "C" {
links = append(links, &utils.Link{
Name: path.Base(v) + ".",
Path: v,
})
}
}
// Set exported objects type-ahead.
exportDataSrc := buf.String()
if len(exportDataSrc) > 0 {
pdoc.IsHasExport = true
this.Data["IsHasExports"] = true
exportDataSrc = exportDataSrc[:len(exportDataSrc)-1]
this.Data["ExportDataSrc"] = "<script>$('.search-export').typeahead({local: [" +
exportDataSrc + "],limit: 10});</script>"
}
pdoc.UserExamples = getUserExamples(pdoc.ImportPath)
pdoc.IsHasConst = len(pdoc.Consts) > 0
pdoc.IsHasVar = len(pdoc.Vars) > 0
if len(pdoc.Examples)+len(pdoc.UserExamples) > 0 {
pdoc.IsHasExample = true
this.Data["IsHasExample"] = pdoc.IsHasExample
this.Data["Examples"] = append(pdoc.Examples, pdoc.UserExamples...)
}
// Commented and total objects number.
var comNum, totalNum int
// Constants.
this.Data["IsHasConst"] = pdoc.IsHasConst
this.Data["Consts"] = pdoc.Consts
for i, v := range pdoc.Consts {
if len(v.Doc) > 0 {
buf.Reset()
godoc.ToHTML(&buf, v.Doc, nil)
v.Doc = buf.String()
}
buf.Reset()
v.Decl = template.HTMLEscapeString(v.Decl)
v.Decl = strings.Replace(v.Decl, """, "\"", -1)
utils.FormatCode(&buf, &v.Decl, links)
v.FmtDecl = buf.String()
pdoc.Consts[i] = v
}
// Variables.
this.Data["IsHasVar"] = pdoc.IsHasVar
this.Data["Vars"] = pdoc.Vars
for i, v := range pdoc.Vars {
if len(v.Doc) > 0 {
buf.Reset()
godoc.ToHTML(&buf, v.Doc, nil)
v.Doc = buf.String()
}
buf.Reset()
utils.FormatCode(&buf, &v.Decl, links)
v.FmtDecl = buf.String()
pdoc.Vars[i] = v
//.........這裏部分代碼省略.........