mirror of
https://github.com/golang/go
synced 2024-11-18 17:34:51 -07:00
493538adbf
This fixes an issue where linking directly to an example makes it not runnable and visible only in a tiny window. To see the bug in action, visit this link: http://golang.org/pkg/strings/#example_Map R=golang-dev, r CC=golang-dev https://golang.org/cl/10679050
277 lines
7.4 KiB
HTML
277 lines
7.4 KiB
HTML
<!--
|
|
Copyright 2009 The Go Authors. All rights reserved.
|
|
Use of this source code is governed by a BSD-style
|
|
license that can be found in the LICENSE file.
|
|
-->
|
|
<!--
|
|
Note: Static (i.e., not template-generated) href and id
|
|
attributes start with "pkg-" to make it impossible for
|
|
them to conflict with generated attributes (some of which
|
|
correspond to Go identifiers).
|
|
-->
|
|
{{with .PDoc}}
|
|
{{if $.IsMain}}
|
|
{{/* command documentation */}}
|
|
{{comment_html .Doc}}
|
|
{{else}}
|
|
{{/* package documentation */}}
|
|
<div id="short-nav">
|
|
<dl>
|
|
<dd><code>import "{{html .ImportPath}}"</code></dd>
|
|
</dl>
|
|
<dl>
|
|
<dd><a href="#pkg-overview" class="overviewLink">Overview</a></dd>
|
|
<dd><a href="#pkg-index" class="indexLink">Index</a></dd>
|
|
{{if $.Examples}}
|
|
<dd><a href="#pkg-examples" class="examplesLink">Examples</a></dd>
|
|
{{end}}
|
|
{{if $.Dirs}}
|
|
<dd><a href="#pkg-subdirectories">Subdirectories</a></dd>
|
|
{{end}}
|
|
</dl>
|
|
</div>
|
|
<!-- The package's Name is printed as title by the top-level template -->
|
|
<div id="pkg-overview" class="toggleVisible">
|
|
<div class="collapsed">
|
|
<h2 class="toggleButton" title="Click to show Overview section">Overview ▹</h2>
|
|
</div>
|
|
<div class="expanded">
|
|
<h2 class="toggleButton" title="Click to hide Overview section">Overview ▾</h2>
|
|
{{comment_html .Doc}}
|
|
</div>
|
|
</div>
|
|
{{example_html $ ""}}
|
|
|
|
<div id="pkg-index" class="toggleVisible">
|
|
<div class="collapsed">
|
|
<h2 class="toggleButton" title="Click to show Index section">Index ▹</h2>
|
|
</div>
|
|
<div class="expanded">
|
|
<h2 class="toggleButton" title="Click to hide Index section">Index ▾</h2>
|
|
|
|
<!-- Table of contents for API; must be named manual-nav to turn off auto nav. -->
|
|
<div id="manual-nav">
|
|
<dl>
|
|
{{if .Consts}}
|
|
<dd><a href="#pkg-constants">Constants</a></dd>
|
|
{{end}}
|
|
{{if .Vars}}
|
|
<dd><a href="#pkg-variables">Variables</a></dd>
|
|
{{end}}
|
|
{{range .Funcs}}
|
|
{{$name_html := html .Name}}
|
|
<dd><a href="#{{$name_html}}">{{node_html $ .Decl false}}</a></dd>
|
|
{{end}}
|
|
{{range .Types}}
|
|
{{$tname_html := html .Name}}
|
|
<dd><a href="#{{$tname_html}}">type {{$tname_html}}</a></dd>
|
|
{{range .Funcs}}
|
|
{{$name_html := html .Name}}
|
|
<dd> <a href="#{{$name_html}}">{{node_html $ .Decl false}}</a></dd>
|
|
{{end}}
|
|
{{range .Methods}}
|
|
{{$name_html := html .Name}}
|
|
<dd> <a href="#{{$tname_html}}.{{$name_html}}">{{node_html $ .Decl false}}</a></dd>
|
|
{{end}}
|
|
{{end}}
|
|
{{if $.Notes}}
|
|
{{range $marker, $item := $.Notes}}
|
|
<dd><a href="#pkg-note-{{$marker}}">{{noteTitle $marker | html}}s</a></dd>
|
|
{{end}}
|
|
{{end}}
|
|
</dl>
|
|
</div><!-- #manual-nav -->
|
|
|
|
{{if $.Examples}}
|
|
<div id="pkg-examples">
|
|
<h4>Examples</h4>
|
|
<dl>
|
|
{{range $.Examples}}
|
|
<dd><a class="exampleLink" href="#example_{{.Name}}">{{example_name .Name}}</a></dd>
|
|
{{end}}
|
|
</dl>
|
|
</div>
|
|
{{end}}
|
|
|
|
{{with .Filenames}}
|
|
<h4>Package files</h4>
|
|
<p>
|
|
<span style="font-size:90%">
|
|
{{range .}}
|
|
<a href="{{.|srcLink|html}}">{{.|filename|html}}</a>
|
|
{{end}}
|
|
</span>
|
|
</p>
|
|
{{end}}
|
|
</div><!-- .expanded -->
|
|
</div><!-- #pkg-index -->
|
|
|
|
{{with .Consts}}
|
|
<h2 id="pkg-constants">Constants</h2>
|
|
{{range .}}
|
|
<pre>{{node_html $ .Decl true}}</pre>
|
|
{{comment_html .Doc}}
|
|
{{end}}
|
|
{{end}}
|
|
{{with .Vars}}
|
|
<h2 id="pkg-variables">Variables</h2>
|
|
{{range .}}
|
|
<pre>{{node_html $ .Decl true}}</pre>
|
|
{{comment_html .Doc}}
|
|
{{end}}
|
|
{{end}}
|
|
{{range .Funcs}}
|
|
{{/* Name is a string - no need for FSet */}}
|
|
{{$name_html := html .Name}}
|
|
<h2 id="{{$name_html}}">func <a href="{{posLink_url $ .Decl}}">{{$name_html}}</a></h2>
|
|
<pre>{{node_html $ .Decl true}}</pre>
|
|
{{comment_html .Doc}}
|
|
{{example_html $ .Name}}
|
|
{{end}}
|
|
{{range .Types}}
|
|
{{$tname := .Name}}
|
|
{{$tname_html := html .Name}}
|
|
<h2 id="{{$tname_html}}">type <a href="{{posLink_url $ .Decl}}">{{$tname_html}}</a></h2>
|
|
<pre>{{node_html $ .Decl true}}</pre>
|
|
{{comment_html .Doc}}
|
|
|
|
{{range .Consts}}
|
|
<pre>{{node_html $ .Decl true}}</pre>
|
|
{{comment_html .Doc}}
|
|
{{end}}
|
|
|
|
{{range .Vars}}
|
|
<pre>{{node_html $ .Decl true}}</pre>
|
|
{{comment_html .Doc}}
|
|
{{end}}
|
|
|
|
{{example_html $ $tname}}
|
|
|
|
{{range .Funcs}}
|
|
{{$name_html := html .Name}}
|
|
<h3 id="{{$name_html}}">func <a href="{{posLink_url $ .Decl}}">{{$name_html}}</a></h3>
|
|
<pre>{{node_html $ .Decl true}}</pre>
|
|
{{comment_html .Doc}}
|
|
{{example_html $ .Name}}
|
|
{{end}}
|
|
|
|
{{range .Methods}}
|
|
{{$name_html := html .Name}}
|
|
<h3 id="{{$tname_html}}.{{$name_html}}">func ({{html .Recv}}) <a href="{{posLink_url $ .Decl}}">{{$name_html}}</a></h3>
|
|
<pre>{{node_html $ .Decl true}}</pre>
|
|
{{comment_html .Doc}}
|
|
{{$name := printf "%s_%s" $tname .Name}}
|
|
{{example_html $ $name}}
|
|
{{end}}
|
|
{{end}}
|
|
{{end}}
|
|
|
|
{{with $.Notes}}
|
|
{{range $marker, $content := .}}
|
|
<h2 id="pkg-note-{{$marker}}">{{noteTitle $marker | html}}s</h2>
|
|
<ul style="list-style: none; padding: 0;">
|
|
{{range .}}
|
|
<li><a href="{{posLink_url $ .}}">☞</a> {{html .Body}}</li>
|
|
{{end}}
|
|
</ul>
|
|
{{end}}
|
|
{{end}}
|
|
{{end}}
|
|
|
|
{{with .PAst}}
|
|
<pre>{{node_html $ . false}}</pre>
|
|
{{end}}
|
|
|
|
{{with .Dirs}}
|
|
{{/* DirList entries are numbers and strings - no need for FSet */}}
|
|
{{if $.PDoc}}
|
|
<h2 id="pkg-subdirectories">Subdirectories</h2>
|
|
{{else}}
|
|
<div class="pkgGopher">
|
|
<img class="gopher" src="/doc/gopher/pkg.png"/>
|
|
</div>
|
|
{{end}}
|
|
<table class="dir">
|
|
<tr>
|
|
<th>Name</th>
|
|
<th> </th>
|
|
<th style="text-align: left; width: auto">Synopsis</th>
|
|
</tr>
|
|
{{if not $.DirFlat}}
|
|
<tr>
|
|
<td><a href="..">..</a></td>
|
|
</tr>
|
|
{{end}}
|
|
{{range .List}}
|
|
{{if $.DirFlat}}
|
|
{{if .HasPkg}}
|
|
<tr>
|
|
<td class="name"><a href="{{html .Path}}/">{{html .Path}}</a></td>
|
|
<td> </td>
|
|
<td style="width: auto">{{html .Synopsis}}</td>
|
|
</tr>
|
|
{{end}}
|
|
{{else}}
|
|
<tr>
|
|
<td class="name">{{repeat ` ` .Depth}}<a href="{{html .Path}}/">{{html .Name}}</a></td>
|
|
<td> </td>
|
|
<td style="width: auto">{{html .Synopsis}}</td>
|
|
</tr>
|
|
{{end}}
|
|
{{end}}
|
|
</table>
|
|
{{if $.PDoc}}{{else}}
|
|
<p>Need more packages? Take a look at the <a href="http://code.google.com/p/go-wiki/wiki/Projects">Go Projects wiki page</a>.</p>
|
|
{{end}}
|
|
{{end}}
|
|
|
|
{{if $.Examples}}
|
|
<script>
|
|
$(document).ready(function() {
|
|
'use strict';
|
|
// Set up playground when each element is toggled.
|
|
$('div.play').each(function (i, el) {
|
|
// Set up playground for this example.
|
|
var setup = function() {
|
|
var code = $('.code', el);
|
|
playground({
|
|
'codeEl': code,
|
|
'outputEl': $('.output', el),
|
|
'runEl': $('.run', el),
|
|
'fmtEl': $('.fmt', el),
|
|
'shareEl': $('.share', el),
|
|
'shareRedirect': 'http://play.golang.org/p/'
|
|
});
|
|
|
|
// Make the code textarea resize to fit content.
|
|
var resize = function() {
|
|
code.height(0);
|
|
var h = code[0].scrollHeight;
|
|
code.height(h+20); // minimize bouncing.
|
|
code.closest('.input').height(h);
|
|
};
|
|
code.on('keydown', resize);
|
|
code.on('keyup', resize);
|
|
code.keyup(); // resize now.
|
|
};
|
|
|
|
// If example already visible, set up playground now.
|
|
if ($(el).is(':visible')) {
|
|
setup();
|
|
return;
|
|
}
|
|
|
|
// Otherwise, set up playground when example is expanded.
|
|
var built = false;
|
|
$(el).closest('.toggle').click(function() {
|
|
// Only set up once.
|
|
if (!built) {
|
|
setup();
|
|
built = true;
|
|
}
|
|
});
|
|
});
|
|
});
|
|
</script>
|
|
{{end}}
|