godoc: Implement Unordered Output.

When an Example's output is listed as being Unordered this will make
godoc display "Unordered output:" rather than the normal "Output:".

For an example of where this is useful, see the recently added example
for math.rand.Perm().

Change-Id: I737c901102dca46434f46a48300445bb43ce34e0
Reviewed-on: https://go-review.googlesource.com/20458
Reviewed-by: Andrew Gerrand <adg@golang.org>
This commit is contained in:
Brady Catherman 2016-03-08 22:32:41 -07:00 committed by Andrew Gerrand
parent c5b51756ce
commit 3d2dab63d9
3 changed files with 11 additions and 3 deletions

View File

@ -491,8 +491,8 @@ func (p *Presentation) example_htmlFunc(info *PageInfo, funcName string) string
err := p.ExampleHTML.Execute(&buf, struct {
Name, Doc, Code, Play, Output string
Share bool
}{eg.Name, eg.Doc, code, play, out, info.Share})
Share, Unordered bool
}{eg.Name, eg.Doc, code, play, out, info.Share, eg.Unordered})
if err != nil {
log.Print(err)
}
@ -587,7 +587,7 @@ func startsWithUppercase(s string) bool {
return unicode.IsUpper(r)
}
var exampleOutputRx = regexp.MustCompile(`(?i)//[[:space:]]*output:`)
var exampleOutputRx = regexp.MustCompile(`(?i)//([[:space:]]*unordered)?[[:space:]]*output:`)
// stripExampleSuffix strips lowercase braz in Foo_braz or Foo_Bar_braz from name
// while keeping uppercase Braz in Foo_Braz.

View File

@ -22,7 +22,11 @@
<p>Code:</p>
<pre class="code">{{.Code}}</pre>
{{with .Output}}
{{if $.Unordered}}
<p>Unordered Output:</p>
{{else}}
<p>Output:</p>
{{end}}
<pre class="output">{{html .}}</pre>
{{end}}
{{end}}

View File

@ -450,7 +450,11 @@ var Files = map[string]string{
<p>Code:</p>
<pre class="code">{{.Code}}</pre>
{{with .Output}}
{{if $.Unordered}}
<p>Unordered Output:</p>
{{else}}
<p>Output:</p>
{{end}}
<pre class="output">{{html .}}</pre>
{{end}}
{{end}}