]> Cypherpunks repositories - gostls13.git/commitdiff
godoc: show example function doc comments in UI
authorAndrew Gerrand <adg@golang.org>
Thu, 16 Feb 2012 01:43:22 +0000 (12:43 +1100)
committerAndrew Gerrand <adg@golang.org>
Thu, 16 Feb 2012 01:43:22 +0000 (12:43 +1100)
R=gri
CC=golang-dev
https://golang.org/cl/5677061

lib/godoc/example.html
src/cmd/godoc/godoc.go
src/pkg/go/ast/example.go

index f70e447d9e695bd8b46b8b302129b4a82e3c7d70..d7b219371ab6066c23a87b067df8988d43df31f4 100644 (file)
@@ -4,11 +4,12 @@
        </div>
        <div class="expanded">
                <p class="exampleHeading">▾ Example{{example_suffix .Name}}</p>
+               {{with .Doc}}<p>{{html .}}</p>{{end}}
                <p>Code:</p>
                <pre class="code">{{.Code}}</pre>
-               {{if .Output}}
+               {{with .Output}}
                <p>Output:</p>
-               <pre class="output">{{html .Output}}</pre>
+               <pre class="output">{{html .}}</pre>
                {{end}}
        </div>
 </div>
index 5652547238ef39d64b1854d7ac964639f2dd3710..19f3cb8f6d4de5286478ca4d3c00f59db4dceaa6 100644 (file)
@@ -539,8 +539,8 @@ func example_htmlFunc(funcName string, examples []*ast.Example, fset *token.File
                }
 
                err := exampleHTML.Execute(&buf, struct {
-                       Name, Code, Output string
-               }{eg.Name, code, out})
+                       Name, Doc, Code, Output string
+               }{eg.Name, eg.Doc, code, out})
                if err != nil {
                        log.Print(err)
                }
index dd6bb6faa3c65d6cd66dcb7aab9308bee03709de..33a836894a2f526737aa66635913d9e5769be6c5 100644 (file)
@@ -16,6 +16,7 @@ import (
 
 type Example struct {
        Name     string // name of the item being exemplified
+       Doc      string // example function doc string
        Code     Node
        Comments []*CommentGroup
        Output   string // expected output
@@ -45,8 +46,13 @@ func Examples(files ...*File) []*Example {
                        if !isTest(name, "Example") {
                                continue
                        }
+                       var doc string
+                       if f.Doc != nil {
+                               doc = f.Doc.Text()
+                       }
                        flist = append(flist, &Example{
                                Name:     name[len("Example"):],
+                               Doc:      doc,
                                Code:     f.Body,
                                Comments: file.Comments,
                                Output:   exampleOutput(f, file.Comments),