Commit 7c9662f4 authored by Andrew Gerrand's avatar Andrew Gerrand

godoc: show example function doc comments in UI

R=gri
CC=golang-dev
https://golang.org/cl/5677061
parent 11e113db
...@@ -4,11 +4,12 @@ ...@@ -4,11 +4,12 @@
</div> </div>
<div class="expanded"> <div class="expanded">
<p class="exampleHeading">▾ Example{{example_suffix .Name}}</p> <p class="exampleHeading">▾ Example{{example_suffix .Name}}</p>
{{with .Doc}}<p>{{html .}}</p>{{end}}
<p>Code:</p> <p>Code:</p>
<pre class="code">{{.Code}}</pre> <pre class="code">{{.Code}}</pre>
{{if .Output}} {{with .Output}}
<p>Output:</p> <p>Output:</p>
<pre class="output">{{html .Output}}</pre> <pre class="output">{{html .}}</pre>
{{end}} {{end}}
</div> </div>
</div> </div>
...@@ -539,8 +539,8 @@ func example_htmlFunc(funcName string, examples []*ast.Example, fset *token.File ...@@ -539,8 +539,8 @@ func example_htmlFunc(funcName string, examples []*ast.Example, fset *token.File
} }
err := exampleHTML.Execute(&buf, struct { err := exampleHTML.Execute(&buf, struct {
Name, Code, Output string Name, Doc, Code, Output string
}{eg.Name, code, out}) }{eg.Name, eg.Doc, code, out})
if err != nil { if err != nil {
log.Print(err) log.Print(err)
} }
......
...@@ -16,6 +16,7 @@ import ( ...@@ -16,6 +16,7 @@ import (
type Example struct { type Example struct {
Name string // name of the item being exemplified Name string // name of the item being exemplified
Doc string // example function doc string
Code Node Code Node
Comments []*CommentGroup Comments []*CommentGroup
Output string // expected output Output string // expected output
...@@ -45,8 +46,13 @@ func Examples(files ...*File) []*Example { ...@@ -45,8 +46,13 @@ func Examples(files ...*File) []*Example {
if !isTest(name, "Example") { if !isTest(name, "Example") {
continue continue
} }
var doc string
if f.Doc != nil {
doc = f.Doc.Text()
}
flist = append(flist, &Example{ flist = append(flist, &Example{
Name: name[len("Example"):], Name: name[len("Example"):],
Doc: doc,
Code: f.Body, Code: f.Body,
Comments: file.Comments, Comments: file.Comments,
Output: exampleOutput(f, file.Comments), Output: exampleOutput(f, file.Comments),
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment