diff options
Diffstat (limited to 'lib/godoc')
-rw-r--r-- | lib/godoc/codewalk.html | 2 | ||||
-rw-r--r-- | lib/godoc/example.html | 23 | ||||
-rw-r--r-- | lib/godoc/godoc.html | 42 | ||||
-rw-r--r-- | lib/godoc/package.html | 125 | ||||
-rw-r--r-- | lib/godoc/package.txt | 31 |
5 files changed, 155 insertions, 68 deletions
diff --git a/lib/godoc/codewalk.html b/lib/godoc/codewalk.html index 2835c6e82..313f1f663 100644 --- a/lib/godoc/codewalk.html +++ b/lib/godoc/codewalk.html @@ -4,8 +4,6 @@ license that can be found in the LICENSE file. --> -<script src="http://www.google.com/jsapi"></script> -<script>google.load("jquery", "1.3.2");</script> <style type='text/css'>@import "/doc/codewalk/codewalk.css";</style> <script type="text/javascript" src="/doc/codewalk/codewalk.js"></script> diff --git a/lib/godoc/example.html b/lib/godoc/example.html index ede31d61f..cda2a8491 100644 --- a/lib/godoc/example.html +++ b/lib/godoc/example.html @@ -5,11 +5,24 @@ <div class="expanded"> <p class="exampleHeading toggleButton">▾ <span class="text">Example{{example_suffix .Name}}</span></p> {{with .Doc}}<p>{{html .}}</p>{{end}} - <p>Code:</p> - <pre class="code">{{.Code}}</pre> - {{with .Output}} - <p>Output:</p> - <pre class="output">{{html .}}</pre> + {{$output := .Output}} + {{with .Play}} + <div class="play"> + <div class="input"><textarea class="code">{{html .}}</textarea></div> + <div class="output"><pre>{{html $output}}</pre></div> + <div class="buttons"> + <a class="run" title="Run this code [shift-enter]">Run</a> + <a class="fmt" title="Format this code">Format</a> + <a class="share" title="Share this code">Share</a> + </div> + </div> + {{else}} + <p>Code:</p> + <pre class="code">{{.Code}}</pre> + {{with .Output}} + <p>Output:</p> + <pre class="output">{{html .}}</pre> + {{end}} {{end}} </div> </div> diff --git a/lib/godoc/godoc.html b/lib/godoc/godoc.html index fd6032927..b7a772cb2 100644 --- a/lib/godoc/godoc.html +++ b/lib/godoc/godoc.html @@ -8,6 +8,11 @@ <title>The Go Programming Language</title> {{end}} <link type="text/css" rel="stylesheet" href="/doc/style.css"> +<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script> +<script type="text/javascript">window.jQuery || document.write(unescape("%3Cscript src='/doc/jquery.js' type='text/javascript'%3E%3C/script%3E"));</script> +{{if .Playground}} +<script type="text/javascript" src="/doc/play/playground.js"></script> +{{end}} <script type="text/javascript" src="/doc/godocs.js"></script> {{if .SearchBox}} <link rel="search" type="application/opensearchdescription+xml" title="godoc" href="/opensearch.xml" /> @@ -15,7 +20,7 @@ </head> <body> -<div id="topbar"><div class="container{{if .Title}} wide{{end}}"> +<div id="topbar"{{if .Title}} class="wide"{{end}}><div class="container"> <form method="GET" action="/search"> <div id="menu"> @@ -24,14 +29,36 @@ <a href="/pkg/">Packages</a> <a href="/project/">The Project</a> <a href="/help/">Help</a> -<input type="text" id="search" name="q" class="inactive" value="Search"> +{{if .Playground}} +<a id="playgroundButton" href="http://play.golang.org/" title="Show Go Playground">Play</a> +{{end}} +<input type="text" id="search" name="q" class="inactive" value="Search" placeholder="Search"> </div> <div id="heading"><a href="/">The Go Programming Language</a></div> </form> </div></div> +{{if .Playground}} +<div id="playground" class="play"> + <div class="input"><textarea class="code">package main + +import "fmt" + +func main() { + fmt.Println("Hello, 世界") +}</textarea></div> + <div class="output"></div> + <div class="buttons"> + <a class="run" title="Run this code [shift-enter]">Run</a> + <a class="fmt" title="Format this code">Format</a> + <a class="share" title="Share this code">Share</a> + </div> +</div> +{{end}} + <div id="page"{{if .Title}} class="wide"{{end}}> +<div class="container"> {{with .Title}} <div id="plusone"><g:plusone size="small" annotation="none"></g:plusone></div> @@ -45,10 +72,8 @@ Do not delete this <div>. */}} <div id="nav"></div> -{{/* Content is HTML-escaped elsewhere */}} -{{printf "%s" .Content}} - -</div> +{{/* Body is HTML-escaped elsewhere */}} +{{printf "%s" .Body}} <div id="footer"> Build version {{html .Version}}.<br> @@ -57,9 +82,12 @@ the content of this page is licensed under the Creative Commons Attribution 3.0 License, and code is licensed under a <a href="/LICENSE">BSD license</a>.<br> <a href="/doc/tos.html">Terms of Service</a> | -<a href="http://www.google.com/intl/en/privacy/privacy-policy.html">Privacy Policy</a> +<a href="http://www.google.com/intl/en/policies/privacy/">Privacy Policy</a> </div> +</div><!-- .container --> +</div><!-- #page --> + </body> <script type="text/javascript"> (function() { diff --git a/lib/godoc/package.html b/lib/godoc/package.html index 5b7fce8d7..1df1f9151 100644 --- a/lib/godoc/package.html +++ b/lib/godoc/package.html @@ -3,25 +3,31 @@ 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 $.IsPkg}} + {{if not $.IsMain}} <div id="short-nav"> <dl> <dd><code>import "{{html .ImportPath}}"</code></dd> </dl> <dl> - <dd><a href="#overview" class="overviewLink">Overview</a></dd> - <dd><a href="#index">Index</a></dd> + <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="#examples">Examples</a></dd> + <dd><a href="#pkg-examples" class="examplesLink">Examples</a></dd> {{end}} {{if $.Dirs}} - <dd><a href="#subdirectories">Subdirectories</a></dd> + <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="overview" class="toggleVisible"> + <div id="pkg-overview" class="toggleVisible"> <div class="collapsed"> <h2 class="toggleButton" title="Click to show Overview section">Overview ▹</h2> </div> @@ -31,16 +37,22 @@ </div> </div> {{example_html "" $.Examples $.FSet}} - - <h2 id="index">Index</h2> + + <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"> + <div id="manual-nav"> <dl> {{if .Consts}} - <dd><a href="#constants">Constants</a></dd> + <dd><a href="#pkg-constants">Constants</a></dd> {{end}} {{if .Vars}} - <dd><a href="#variables">Variables</a></dd> + <dd><a href="#pkg-variables">Variables</a></dd> {{end}} {{range .Funcs}} {{$name_html := html .Name}} @@ -58,20 +70,25 @@ <dd> <a href="#{{$tname_html}}.{{$name_html}}">{{node_html .Decl $.FSet}}</a></dd> {{end}} {{end}} - {{if .Bugs}} - <dd><a href="#bugs">Bugs</a></dd> + {{if $.Notes}} + {{range $marker, $item := $.Notes}} + <dd><a href="#pkg-note-{{$marker}}">{{noteTitle $marker | html}}s</a></dd> + {{end}} {{end}} - </dl> + </dl> + </div><!-- #manual-nav --> {{if $.Examples}} - <h4 id="examples">Examples</h4> + <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> @@ -82,16 +99,18 @@ </span> </p> {{end}} + </div><!-- .expanded --> + </div><!-- #pkg-index --> {{with .Consts}} - <h2 id="constants">Constants</h2> + <h2 id="pkg-constants">Constants</h2> {{range .}} <pre>{{node_html .Decl $.FSet}}</pre> {{comment_html .Doc}} {{end}} {{end}} {{with .Vars}} - <h2 id="variables">Variables</h2> + <h2 id="pkg-variables">Variables</h2> {{range .}} <pre>{{node_html .Decl $.FSet}}</pre> {{comment_html .Doc}} @@ -141,15 +160,16 @@ {{example_html $name $.Examples $.FSet}} {{end}} {{end}} - </div> {{else}} {{/* not a package; is a command */}} {{comment_html .Doc}} {{end}} - {{with .Bugs}} - <h2 id="bugs">Bugs</h2> - {{range .}} - {{comment_html .}} + {{with $.Notes}} + {{range $marker, $content := .}} + <h2 id="pkg-note-{{$marker}}">{{noteTitle $marker | html}}s</h2> + {{range .}} + {{comment_html .}} + {{end}} {{end}} {{end}} {{end}} @@ -158,20 +178,10 @@ <pre>{{node_html . $.FSet}}</pre> {{end}} -{{with .PList}} - <h2>Other packages</h2> - <p> - {{/* PList entries are strings - no need for FSet */}} - {{range .}} - <a href="?p={{urlquery .}}">{{html .}}</a><br /> - {{end}} - </p> -{{end}} - {{with .Dirs}} {{/* DirList entries are numbers and strings - no need for FSet */}} {{if $.PDoc}} - <h2 id="subdirectories">Subdirectories</h2> + <h2 id="pkg-subdirectories">Subdirectories</h2> {{else}} <div class="pkgGopher"> <img class="gopher" src="/doc/gopher/pkg.png"/> @@ -192,14 +202,14 @@ {{if $.DirFlat}} {{if .HasPkg}} <tr> - <td class="name"><a href="{{html .Path}}">{{html .Path}}</a></td> + <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 class="name">{{repeat ` ` .Depth}}<a href="{{html .Path}}/">{{html .Name}}</a></td> <td> </td> <td style="width: auto">{{html .Synopsis}}</td> </tr> @@ -207,6 +217,47 @@ {{end}} </table> {{if $.PDoc}}{{else}} - <p>Need more packages? Take a look at the <a href="http://godashboard.appspot.com/">Go Project Dashboard</a>.</p> + <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) { + var built = false; + $(el).closest('.toggle').click(function() { + // Only set up playground once. + if (built) { + return; + } + built = true; + + // Set up playground. + 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. + }); + }); +}); +</script> +{{end}} diff --git a/lib/godoc/package.txt b/lib/godoc/package.txt index 3f3c396f0..94239ca1a 100644 --- a/lib/godoc/package.txt +++ b/lib/godoc/package.txt @@ -2,14 +2,15 @@ --------------------------------------- -*/}}{{with .PDoc}}{{if $.IsPkg}}PACKAGE +*/}}{{with .PDoc}}{{if not $.IsMain}}PACKAGE package {{.Name}} import "{{.ImportPath}}" {{else}}COMMAND DOCUMENTATION -{{end}}{{comment_text .Doc " " "\t"}}{{/* +{{end}}{{comment_text .Doc " " "\t"}} +{{example_text "" $.Examples $.FSet " "}}{{/* --------------------------------------- @@ -36,6 +37,7 @@ FUNCTIONS {{range .}}{{node .Decl $.FSet}} {{comment_text .Doc " " "\t"}} +{{example_text .Name $.Examples $.FSet " "}} {{end}}{{end}}{{/* --------------------------------------- @@ -43,34 +45,29 @@ FUNCTIONS */}}{{with .Types}} TYPES -{{range .}}{{node .Decl $.FSet}} +{{range .}}{{$tname := .Name}}{{node .Decl $.FSet}} {{comment_text .Doc " " "\t"}} {{range .Consts}}{{node .Decl $.FSet}} {{comment_text .Doc " " "\t"}} {{end}}{{range .Vars}}{{node .Decl $.FSet}} {{comment_text .Doc " " "\t"}} -{{end}}{{range .Funcs}}{{node .Decl $.FSet}} +{{end}}{{example_text .Name $.Examples $.FSet " "}} +{{range .Funcs}}{{node .Decl $.FSet}} {{comment_text .Doc " " "\t"}} +{{example_text .Name $.Examples $.FSet " "}} {{end}}{{range .Methods}}{{node .Decl $.FSet}} {{comment_text .Doc " " "\t"}} +{{$name := printf "%s_%s" $tname .Name}}{{example_text $name $.Examples $.FSet " "}} {{end}}{{end}}{{end}}{{/* --------------------------------------- -*/}}{{with .Bugs}} -BUGS - -{{range .}}{{comment_text . " " "\t"}} -{{end}}{{end}}{{end}}{{/* +*/}}{{with $.Notes}} +{{range $marker, $content := .}} +{{noteTitle $marker}}s ---------------------------------------- - -*/}}{{with .PList}} -OTHER PACKAGES - -{{range .}} -{{.}}{{end}} -{{end}}{{/* +{{range $content}}{{comment_text . " " "\t"}} +{{end}}{{end}}{{end}}{{end}}{{/* --------------------------------------- |