Commit 2e394c51 authored by Robert Griesemer's avatar Robert Griesemer

godoc: moving to new template package

- first step; rough conversion of all template files
- there is plenty of opportunity for cleanups/simplifications (next CLs)
- html and text output as before

R=r, dsymonds
CC=golang-dev
https://golang.org/cl/4852048
parent bca65e39
......@@ -18,9 +18,9 @@
<img title="View code in new window" alt="Pop Out Code" src="/doc/codewalk/popout.png" style="display: block; float: right;"/>
</a>
<select id="code-selector">
{.repeated section File}
<option value="/doc/codewalk/?fileprint=/{@|html-esc}">{@|html-esc}</option>
{.end}
{{range .File}}
<option value="/doc/codewalk/?fileprint=/{{.|urlquery_esc}}">{{.|html_esc}}</option>
{{end}}
</select>
</div>
<div id="code">
......@@ -35,19 +35,19 @@
</div>
<div class="right" id="comment-column">
<div id="comment-area">
{.repeated section Step}
{{range .Step}}
<div class="comment first last">
<a class="comment-link" href="/doc/codewalk/?fileprint=/{File|html-esc}&lo={Lo|html-esc}&hi={Hi|html-esc}#mark" target="code-display"></a>
<div class="comment-title">{Title|html-esc}</div>
<a class="comment-link" href="/doc/codewalk/?fileprint=/{{.File|urlquery_esc}}&lo={{.Lo|html_esc}}&hi={{.Hi|html_esc}}#mark" target="code-display"></a>
<div class="comment-title">{{.Title|html_esc}}</div>
<div class="comment-text">
{.section Err}
ERROR LOADING FILE: {Err|html-esc}<br/><br/>
{.end}
{XML}
{{with .Err}}
ERROR LOADING FILE: {{.|html_esc}}<br/><br/>
{{end}}
{{.XML}}
</div>
<div class="comment-text file-name"><span class="path-file">{@|html-esc}</span></div>
<div class="comment-text file-name"><span class="path-file">{{.|html_esc}}</span></div>
</div>
{.end}
{{end}}
</div>
<div id="comment-options" class="setting">
<a id="prev-comment" href="#"><span class="hotkey">p</span>revious step</a>
......
......@@ -5,11 +5,11 @@
-->
<table class="layout">
{.repeated section @}
{{range .}}
<tr>
<td><a href="{Name|html-esc}">{Name|html-esc}</a></td>
<td><a href="{{.Name|html_esc}}">{{.Name|html_esc}}</a></td>
<td width="25">&nbsp;</td>
<td>{Title|html-esc}</td>
<td>{{.Title|html_esc}}</td>
</tr>
{.end}
{{end}}
</table>
......@@ -16,14 +16,15 @@
<tr>
<td><a href="..">..</a></td>
</tr>
{.repeated section @}
{{range .}}
<tr>
<td align="left"><a href="{@|fileInfoName}">{@|fileInfoName}</a></td>
<td align="left"><a href="{{.|fileInfoName}}">{{.|fileInfoName}}</a></td>
<td></td>
<td align="right">{@|fileInfoSize}</td>
<td align="right">{{.|fileInfoSize}}</td>
<td></td>
<td align="left">{@|fileInfoTime}</td>
<td align="left">{{.|fileInfoTime}}</td>
</tr>
{.end}
{{end}}
</table>
</p>
......@@ -5,5 +5,5 @@
-->
<p>
<span class="alert" style="font-size:120%">{@|html-esc}</span>
<span class="alert" style="font-size:120%">{{.|html_esc}}</span>
</p>
......@@ -2,11 +2,11 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
{.section Title}
<title>{@|html-esc} - The Go Programming Language</title>
{.or}
{{with .Title}}
<title>{{.|html_esc}} - The Go Programming Language</title>
{{else}}
<title>The Go Programming Language</title>
{.end}
{{end}}
<link rel="stylesheet" href="/doc/all.css" type="text/css" media="all" charset="utf-8">
<!--[if lt IE 8]>
<link rel="stylesheet" href="/doc/ie.css" type="text/css">
......@@ -23,19 +23,19 @@
</ul>
<div class="quickref">
<form method="GET" action="/search">
{.section PkgRoots}
{.repeated section PkgRoots}
<a href="/pkg/{@|html-esc}">{@|html-esc}</a> <span class="sep">|</span>
{.end}
{.or}
{{with .PkgRoots}}
{{range .PkgRoots}}
<a href="/pkg/{{.|html_esc}}">{{.|html_esc}}</a> <span class="sep">|</span>
{{end}}
{{else}}
References:
{.end}
{{end}}
<a href="/pkg/">Packages</a> <span class="sep">|</span>
<a href="/cmd/">Commands</a> <span class="sep">|</span>
<a href="/doc/go_spec.html">Specification</a>
{.section SearchBox}
<input id="search" type="search" name="q" value="{.section Query}{Query|html-esc}{.end}" class="{.section Query}{.or}inactive{.end}" placeholder="code search" results="0" />
{.end}
{{if .SearchBox}}
<input id="search" type="search" name="q" value="{{if .Query}}{{.Query|html_esc}}{{end}}" class="{{if .Query}}{{else}}inactive{{end}}" placeholder="code search" results="0" />
{{end}}
</form>
</div>
</div>
......@@ -43,28 +43,28 @@
</div>
<div id="content">
<!-- Menu is HTML-escaped elsewhere -->
{.section Menu}
{{with .Menu}}
<div id="menu">
{@}
{{printf "%s" .}}
</div>
{.end}
{{end}}
{.section Title}
<h1 id="generatedHeader">{@|html-esc}</h1>
{.end}
{.section Subtitle}
<span class="subtitle">{@|html-esc}</span>
{.end}
{{with .Title}}
<h1 id="generatedHeader">{{.|html_esc}}</h1>
{{end}}
{{with .Subtitle}}
<span class="subtitle">{{.|html_esc}}</span>
{{end}}
<!-- The Table of Contents is automatically inserted in this <div>.
Do not delete this <div>. -->
<div id="nav"></div>
<!-- Content is HTML-escaped elsewhere -->
{Content}
{{printf "%s" .Content}}
</div>
<div id="site-info">
<p>Build version {Version|html-esc}. Except as noted, this content is licensed under a <a rel="license" href="http://creativecommons.org/licenses/by/3.0/">Creative Commons Attribution 3.0 License</a>.</p>
<p>Build version {{.Version|html_esc}}. Except as noted, this content is licensed under a <a rel="license" href="http://creativecommons.org/licenses/by/3.0/">Creative Commons Attribution 3.0 License</a>.</p>
</div>
</div>
</body>
......
......@@ -3,119 +3,120 @@
Use of this source code is governed by a BSD-style
license that can be found in the LICENSE file.
-->
{.section PAst}
<pre>{@ FSet|html-esc}</pre>
{.end}
{.section PDoc}
{{$FSet := .FSet}}
{{$Info := .}}
{{with .PAst}}
<pre>{{html_esc . $FSet}}</pre>
{{end}}
{{with .PDoc}}
<!-- PackageName is printed as title by the top-level template -->
{.section IsPkg}
{# ImportPath is a string - no need for FSet}
<p><code>import "{ImportPath|html-esc}"</code></p>
{.end}
{Doc|html-comment}
{.section IsPkg}
{.section Filenames}
{# Filenames are strings - no need for FSet}
{{if $Info.IsPkg}}
{{/* ImportPath is a string - no need for FSet */}}
<p><code>import "{{.ImportPath|html_esc}}"</code></p>
{{end}}
{{.Doc|html_comment}}
{{if $Info.IsPkg}}
{{with .Filenames}}
{{/* Filenames are strings - no need for FSet */}}
<p>
<h4>Package files</h4>
<span style="font-size:90%">
{.repeated section @}
<a href="/{@|url-src}">{@|localname}</a>
{.end}
{{range .}}
<a href="/{{.|url_src}}">{{.|localname}}</a>
{{end}}
</span>
</p>
{.end}
{.end}
{.section Consts}
{{end}}
{{end}}
{{with .Consts}}
<h2 id="Constants">Constants</h2>
{.repeated section @}
{Doc|html-comment}
<pre>{Decl FSet|html-esc}</pre>
{.end}
{.end}
{.section Vars}
{{range .}}
{{html_comment .Doc}}
<pre>{{html_esc .Decl $FSet}}</pre>
{{end}}
{{end}}
{{with .Vars}}
<h2 id="Variables">Variables</h2>
{.repeated section @}
{Doc|html-comment}
<pre>{Decl FSet|html-esc}</pre>
{.end}
{.end}
{.section Funcs}
{.repeated section @}
{# Name is a string - no need for FSet}
<h2 id="{Name|html-esc}">func <a href="/{Decl FSet|url-pos}">{Name|html-esc}</a></h2>
<p><code>{Decl FSet|html-esc}</code></p>
{Doc|html-comment}
{.end}
{.end}
{.section Types}
{.repeated section @}
<h2 id="{Type.Name FSet|html-esc}">type <a href="/{Decl FSet|url-pos}">{Type.Name FSet|html-esc}</a></h2>
{Doc|html-comment}
<p><pre>{Decl FSet|html-esc}</pre></p>
{.repeated section Consts}
{Doc|html-comment}
<pre>{Decl FSet|html-esc}</pre>
{.end}
{.repeated section Vars}
{Doc|html-comment}
<pre>{Decl FSet|html-esc}</pre>
{.end}
{.repeated section Factories}
<h3 id="{Type.Name FSet|html-esc}.{Name|html-esc}">func <a href="/{Decl FSet|url-pos}">{Name|html-esc}</a></h3>
<p><code>{Decl FSet|html-esc}</code></p>
{Doc|html-comment}
{.end}
{.repeated section Methods}
<h3 id="{Type.Name FSet|html-esc}.{Name|html-esc}">func ({Recv FSet|html-esc}) <a href="/{Decl FSet|url-pos}">{Name|html-esc}</a></h3>
<p><code>{Decl FSet|html-esc}</code></p>
{Doc|html-comment}
{.end}
{.end}
{.end}
{.section Bugs}
{{range .}}
{{html_comment .Doc}}
<pre>{{html_esc .Decl $FSet}}</pre>
{{end}}
{{end}}
{{with .Funcs}}
{{range .}}
{{/* Name is a string - no need for FSet */}}
<h2 id="{{.Name|html_esc}}">func <a href="/{{url_pos .Decl $FSet}}">{{.Name|html_esc}}</a></h2>
<p><code>{{html_esc .Decl $FSet}}</code></p>
{{.Doc|html_comment}}
{{end}}
{{end}}
{{with .Types}}
{{range $type := .}}
<h2 id="{{html_esc .Type.Name $FSet}}">type <a href="/{{url_pos .Decl $FSet}}">{{html_esc .Type.Name $FSet}}</a></h2>
{{.Doc|html_comment}}
<p><pre>{{html_esc .Decl $FSet}}</pre></p>
{{range .Consts}}
{{.Doc|html_comment}}
<pre>{{html_esc .Decl $FSet}}</pre>
{{end}}
{{range .Vars}}
{{.Doc|html_comment}}
<pre>{{html_esc .Decl $FSet}}</pre>
{{end}}
{{range .Factories}}
<h3 id="{{html_esc $type.Type.Name $FSet}}.{{.Name|html_esc}}">func <a href="/{{url_pos .Decl $FSet}}">{{.Name|html_esc}}</a></h3>
<p><code>{{html_esc .Decl $FSet}}</code></p>
{{.Doc|html_comment}}
{{end}}
{{range .Methods}}
<h3 id="{{html_esc $type.Type.Name $FSet}}.{{.Name|html_esc}}">func ({{html_esc .Recv $FSet}}) <a href="/{{url_pos .Decl $FSet}}">{{.Name|html_esc}}</a></h3>
<p><code>{{html_esc .Decl $FSet}}</code></p>
{{.Doc|html_comment}}
{{end}}
{{end}}
{{end}}
{{with .Bugs}}
<h2 id="Bugs">Bugs</h2>
{.repeated section @}
{@|html-comment}
{.end}
{.end}
{.end}
{.section PList}
{{range .}}
{{.|html_comment}}
{{end}}
{{end}}
{{end}}
{{with .PList}}
<h2>Other packages</h2>
<p>
{# PLIst entries are strings - no need for FSet}
{.repeated section @}
<a href="?p={@|html-esc}">{@|html-esc}</a><br />
{.end}
{{/* PList entries are strings - no need for FSet */}}
{{range .}}
<a href="?p={{html .}}">{{html .}}</a><br />
{{end}}
</p>
{.end}
{.section Dirs}
{{end}}
{{with .Dirs}}
<p class="detail">
Need more packages? The
<a href="http://godashboard.appspot.com/package">Package Dashboard</a>
provides a list of <a href="/cmd/goinstall/">goinstallable</a> packages.
</p>
{# DirList entries are numbers and strings - no need for FSet}
{{/* DirList entries are numbers and strings - no need for FSet */}}
<h2 id="Subdirectories">Subdirectories</h2>
<p>
<table class="layout">
<tr>
<th align="left" colspan="{MaxHeight|html-esc}">Name</th>
<th align="left" colspan="{{.MaxHeight|html_esc}}">Name</th>
<td width="25">&nbsp;</td>
<th align="left">Synopsis</th>
</tr>
<tr>
<th align="left"><a href="..">..</a></th>
</tr>
{.repeated section List}
{{range .List}}
<tr>
{Depth|padding}
<td align="left" colspan="{Height|html-esc}"><a href="{Path|html-esc}">{Name|html-esc}</a></td>
{{.Depth|padding}}
<td align="left" colspan="{{html .Height}}"><a href="{{html .Path}}">{{html .Name}}</a></td>
<td></td>
<td align="left">{Synopsis|html-esc}</td>
<td align="left">{{html .Synopsis}}</td>
</tr>
{.end}
{{end}}
</table>
</p>
{.end}
{{end}}
{.section PAst}
{@ FSet}
{.end}
{.section PDoc}
{.section IsPkg}
PACKAGE
package {PackageName}
import "{ImportPath}"
{.or}
COMMAND DOCUMENTATION
{.end}
{.section Doc}
{@ FSet}
{.end}
{.section Consts}
{{$FSet := .FSet}}{{$Info := .}}{{/*
---------------------------------------
*/}}{{with .PAst}}{{text . $FSet}}{{end}}{{/*
---------------------------------------
*/}}{{with .PDoc}}{{if $Info.IsPkg}}PACKAGE
package {{.PackageName}}
import "{{.ImportPath}}"
{{else}}COMMAND DOCUMENTATION
{{end}}{{/*
---------------------------------------
*/}}{{with .Doc}}{{text . $FSet}}
{{end}}{{/*
---------------------------------------
*/}}{{with .Consts}}
CONSTANTS
{.repeated section @}
{Decl FSet}
{Doc}
{.end}
{.end}
{.section Vars}
{{range .}}{{text .Decl $FSet}}
{{.Doc}}{{end}}
{{end}}{{/*
---------------------------------------
*/}}{{with .Vars}}
VARIABLES
{.repeated section @}
{Decl FSet}
{Doc}
{.end}
{.end}
{.section Funcs}
{{range .}}{{.Decl $FSet}}
{{.Doc}}{{end}}
{{end}}{{/*
---------------------------------------
*/}}{{with .Funcs}}
FUNCTIONS
{.repeated section @}
{Decl FSet}
{Doc}
{.end}
{.end}
{.section Types}
{{range .}}{{text .Decl $FSet}}
{{.Doc}}
{{end}}{{end}}{{/*
TYPES
---------------------------------------
{.repeated section @}
{Decl FSet}
{Doc}
{.repeated section Consts}
{Decl FSet}
{Doc}
{.end}
{.repeated section Vars}
{Decl FSet}
{Doc}
{.end}
{.repeated section Factories}
{Decl FSet}
{Doc}
{.end}
{.repeated section Methods}
{Decl FSet}
{Doc}
{.end}
{.end}
{.end}
{.section Bugs}
*/}}{{with .Types}}
TYPES
{{range .}}{{text .Decl $FSet}}
{{.Doc}}
{{range .Consts}}{{text .Decl $FSet}}
{{.Doc}}
{{end}}{{range .Vars}}{{text .Decl $FSet}}
{{.Doc}}
{{end}}{{range .Factories}}{{text .Decl $FSet}}
{{.Doc}}
{{end}}{{range .Methods}}{{text .Decl $FSet}}
{{.Doc}}
{{end}}{{end}}{{end}}{{/*
---------------------------------------
*/}}{{with .Bugs}}
BUGS
{.repeated section @}
{@}
{.end}
{.end}
{.end}
{.section PList}
{{range .}}{{.}}
{{end}}{{end}}{{end}}{{/*
---------------------------------------
*/}}{{with .PList}}
OTHER PACKAGES
{.repeated section @}
{@}
{.end}
{.end}
{.section Dirs}
{.section Dirs}
{{range .}}
{{.}}{{end}}
{{end}}{{/*
---------------------------------------
*/}}{{with .Dirs}}
SUBDIRECTORIES
{.repeated section List}
{Name}
{.end}
{.end}
{.end}
{{range .List}}
{{.Name}}{{end}}
{{end}}
......@@ -3,93 +3,91 @@
Use of this source code is governed by a BSD-style
license that can be found in the LICENSE file.
-->
{.section Alert}
{{$SearchResult := .}}
{{with .Alert}}
<p>
<span class="alert" style="font-size:120%">{@}</span>
<span class="alert" style="font-size:120%">{{.}}</span>
</p>
{.end}
{.section Alt}
{{end}}
{{with .Alt}}
<p>
<span class="alert" style="font-size:120%">Did you mean: </span>
{.repeated section Alts}
<a href="search?q={@|html-esc}" style="font-size:120%">{@|html-esc}</a>
{.end}
{{range .Alts}}
<a href="search?q={{.|urlquery_esc}}" style="font-size:120%">{{.|html_esc}}</a>
{{end}}
</p>
{.end}
{.section Hit}
{.section Decls}
{{end}}
{{with .Hit}}
{{with .Decls}}
<h2 id="Global">Package-level declarations</h2>
{.repeated section @}
<h3 id="Global_{Pak.Path|url-pkg}">package <a href="/{Pak.Path|url-pkg}">{Pak.Name|html-esc}</a></h3>
{.repeated section Files}
{.repeated section Groups}
{.repeated section Infos}
<a href="/{File.Path|url-src}?h={Query|urlquery-esc}#L{@|infoLine}">{File.Path|url-src}:{@|infoLine}</a>
{@|infoSnippet}
{.end}
{.end}
{.end}
{.end}
{.end}
{.section Others}
{{range .}}
<h3 id="Global_{{.Pak.Path|url_pkg}}">package <a href="/{{.Pak.Path|url_pkg}}">{{.Pak.Name|html_esc}}</a></h3>
{{range $File := .Files}}
{{range .Groups}}
{{range .Infos}}
<a href="/{{$File.File.Path|url_src}}?h={{$SearchResult.Query|urlquery_esc}}#L{{.|infoLine}}">{{$File.File.Path|url_src}}:{{.|infoLine}}</a>
{{.|infoSnippet}}
{{end}}
{{end}}
{{end}}
{{end}}
{{end}}
{{with .Others}}
<h2 id="Local">Local declarations and uses</h2>
{.repeated section @}
<h3 id="Local_{Pak.Path|url-pkg}">package <a href="/{Pak.Path|url-pkg}">{Pak.Name|html-esc}</a></h3>
{.repeated section Files}
<a href="/{File.Path|url-src}?h={Query|urlquery-esc}">{File.Path|url-src}</a>
{{range .}}
<h3 id="Local_{{.Pak.Path|url_pkg}}">package <a href="/{{.Pak.Path|url_pkg}}">{{.Pak.Name|html_esc}}</a></h3>
{{range $File := .Files}}
<a href="/{{.File.Path|url_src}}?h={{$SearchResult.Query|urlquery_esc}}">{{.File.Path|url_src}}</a>
<table class="layout">
{.repeated section Groups}
{{range .Groups}}
<tr>
<td width="25"></td>
<th align="left" valign="top">{Kind|infoKind}</th>
<th align="left" valign="top">{{.Kind|infoKind}}</th>
<td align="left" width="4"></td>
<td>
{.repeated section Infos}
<a href="/{File.Path|url-src}?h={Query|urlquery-esc}#L{@|infoLine}">{@|infoLine}</a>
{.end}
{{range .Infos}}
<a href="/{{$File.File.Path|url_src}}?h={{$SearchResult.Query|urlquery_esc}}#L{{.|infoLine}}">{{.|infoLine}}</a>
{{end}}
</td>
</tr>
{.end}
{{end}}
</table>
{.end}
{.end}
{.end}
{.end}
{.section Textual}
{.section Complete}
<h2 id="Textual">{Found|html-esc} textual occurrences</h2>
{.or}
<h2 id="Textual">More than {Found|html-esc} textual occurrences</h2>
{{end}}
{{end}}
{{end}}
{{end}}
{{with .Textual}}
{{if $SearchResult.Complete}}
<h2 id="Textual">{{$SearchResult.Found|html_esc}} textual occurrences</h2>
{{else}}
<h2 id="Textual">More than {{$SearchResult.Found|html_esc}} textual occurrences</h2>
<p>
<span class="alert" style="font-size:120%">Not all files or lines containing "{Query|html-esc}" are shown.</span>
<span class="alert" style="font-size:120%">Not all files or lines containing "{{$SearchResult.Query|html_esc}}" are shown.</span>
</p>
{.end}
{{end}}
<p>
<table class="layout">
{.repeated section @}
{{range $File := .}}
<tr>
<td align="left" valign="top">
<a href="/{Filename|url-src}?h={Query|urlquery-esc}">{Filename|url-src}</a>:
<a href="/{{.Filename|url_src}}?h={{$SearchResult.Query|urlquery_esc}}">{{.Filename|url_src}}</a>:
</td>
<td align="left" width="4"></td>
<th align="left" valign="top">{Lines|numlines}</th>
<th align="left" valign="top">{{.Lines|numlines}}</th>
<td align="left" width="4"></td>
<td align="left">
{.repeated section Lines}
<a href="/{Filename|url-src}?h={Query|urlquery-esc}#L{@|html-esc}">{@|html-esc}</a>
{.end}
{.section Complete}
{.or}
{{range .Lines}}
<a href="/{{$File.Filename|url_src}}?h={{$SearchResult.Query|urlquery_esc}}#L{{.|html_esc}}">{{.|html_esc}}</a>
{{end}}
{{if not $SearchResult.Complete}}
...
{.end}
{{end}}
</td>
</tr>
{.end}
{.section Complete}
{.or}
{{end}}
{{if not $SearchResult.Complete}}
<tr><td align="left">...</td></tr>
{.end}
{{end}}
</table>
</p>
{.end}
{{end}}
QUERY
{Query}
{{.Query}}
{{with .Alert}}
{{.}}
{{end}}{{/* .Alert */}}{{/*
{.section Alert}
{@}
---------------------------------------
{.end}
{.section Alt}
*/}}{{with .Alt}}
DID YOU MEAN
{.repeated section Alts}
{@}
{.end}
{{range .Alts}} {{.}}
{{end}}{{end}}{{/* .Alts */}}{{/*
{.end}
{.section Hit}
{.section Decls}
---------------------------------------
*/}}{{with .Hit}}{{with .Decls}}
PACKAGE-LEVEL DECLARATIONS
{.repeated section @}
package {Pak.Name}
{.repeated section Files}
{.repeated section Groups}
{.repeated section Infos}
{File.Path|url-src}:{@|infoLine}
{.end}
{.end}
{.end}
{.end}
{.end}
{.section Others}
{{range .}}package {{.Pak.Name}}
{{range $File := .Files}}{{range .Groups}}{{range .Infos}} {{$File.File.Path|url_src}}:{{.|infoLine}}{{end}}
{{end}}{{end}}{{/* .Files */}}{{end}}{{end}}{{/* .Decls */}}{{/*
---------------------------------------
*/}}{{with .Others}}
LOCAL DECLARATIONS AND USES
{.repeated section @}
package {Pak.Name}
{.repeated section Files}
{.repeated section Groups}
{.repeated section Infos}
{File.Path|url-src}:{@|infoLine}
{.end}
{.end}
{.end}
{.end}
{.end}
{.end}
{.section Textual}
{.section Complete}
{Found} TEXTUAL OCCURRENCES
{.or}
MORE THAN {Found} TEXTUAL OCCURRENCES
{.end}
{.repeated section @}
{Lines|numlines} {Filename|url-src}
{.end}
{.section Complete}
{.or}
... ...
{.end}
{.end}
{{range .}}package {{.Pak.Name}}
{{range $File := .Files}}{{range .Groups}}{{range .Infos}} {{$File.File.Path|url_src}}:{{.|infoLine}}
{{end}}{{end}}{{end}}{{/* .Files */}}
{{end}}{{end}}{{/* .Others */}}{{end}}{{/* .Hit */}}{{/*
---------------------------------------
*/}}{{if .Textual}}{{if .Complete}}{{.Found}} TEXTUAL OCCURRENCES{{else}}MORE THAN {{.Found}} TEXTUAL OCCURRENCES{{end}}
{{range .Textual}}{{.Lines|numlines}} {{.Filename|url_src}}
{{end}}{{if not .Complete}}... ...
{{end}}{{end}}
......@@ -14,6 +14,7 @@ package main
import (
"container/vector"
"exp/template"
"fmt"
"http"
"io"
......@@ -23,7 +24,6 @@ import (
"sort"
"strconv"
"strings"
"template"
"utf8"
"xml"
)
......
......@@ -11,13 +11,13 @@
package main
import (
"exp/template"
"fmt"
"go/scanner"
"go/token"
"io"
"regexp"
"strconv"
"template"
)
// ----------------------------------------------------------------------------
......
......@@ -6,6 +6,7 @@ package main
import (
"bytes"
"exp/template"
"flag"
"fmt"
"go/ast"
......@@ -23,7 +24,6 @@ import (
"runtime"
"sort"
"strings"
"template"
"time"
)
......@@ -481,16 +481,16 @@ func urlFmt(w io.Writer, format string, x ...interface{}) {
// and assume the url-pkg format instead
log.Printf("INTERNAL ERROR: urlFmt(%s)", format)
fallthrough
case "url-pkg":
case "url_pkg":
// because of the irregular mapping under goroot
// we need to correct certain relative paths
if strings.HasPrefix(relpath, "src/pkg/") {
relpath = relpath[len("src/pkg/"):]
}
template.HTMLEscape(w, []byte(pkgHandler.pattern[1:]+relpath)) // remove trailing '/' for relative URL
case "url-src":
case "url_src":
template.HTMLEscape(w, []byte(relpath))
case "url-pos":
case "url_pos":
template.HTMLEscape(w, []byte(relpath))
// selection ranges are of form "s=low:high"
if low < high {
......@@ -600,14 +600,32 @@ func numlinesFmt(w io.Writer, format string, x ...interface{}) {
fmt.Fprintf(w, "%d", len(list))
}
var fmap = template.FormatterMap{
"": textFmt,
"html-esc": htmlEscFmt,
"html-comment": htmlCommentFmt,
"urlquery-esc": urlQueryEscFmt,
"url-pkg": urlFmt,
"url-src": urlFmt,
"url-pos": urlFmt,
// TODO(gri): Remove this type once fmtMap2funcMap is gone.
type FormatterMap map[string]func(io.Writer, string, ...interface{})
// TODO(gri): Remove the need for this conversion function by rewriting
// the old template formatters into new template functions.
func fmtMap2funcMap(fmtMap FormatterMap) template.FuncMap {
funcMap := make(template.FuncMap)
for n, f := range fmtMap {
name, fmt := n, f // separate instance of name, fmt for each closure!
funcMap[name] = func(args ...interface{}) string {
var buf bytes.Buffer
fmt(&buf, name, args...)
return buf.String()
}
}
return funcMap
}
var fmap = fmtMap2funcMap(FormatterMap{
"text": textFmt,
"html_esc": htmlEscFmt,
"html_comment": htmlCommentFmt,
"urlquery_esc": urlQueryEscFmt,
"url_pkg": urlFmt,
"url_src": urlFmt,
"url_pos": urlFmt,
"infoKind": infoKindFmt,
"infoLine": infoLineFmt,
"infoSnippet": infoSnippetFmt,
......@@ -617,7 +635,7 @@ var fmap = template.FormatterMap{
"fileInfoTime": fileInfoTimeFmt,
"localname": localnameFmt,
"numlines": numlinesFmt,
}
})
func readTemplate(name string) *template.Template {
path := filepath.Join(*goroot, "lib", "godoc", name)
......@@ -629,15 +647,7 @@ func readTemplate(name string) *template.Template {
path = defaultpath
}
}
data, err := fs.ReadFile(path)
if err != nil {
log.Fatalf("ReadFile %s: %v", path, err)
}
t, err := template.Parse(string(data), fmap)
if err != nil {
log.Fatalf("%s: %v", name, err)
}
return t
return template.Must(template.New(name).Funcs(fmap).ParseFile(path))
}
var (
......
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