URL
https://opencores.org/ocsvn/openrisc/openrisc/trunk
Subversion Repositories openrisc
[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [libgo/] [go/] [old/] [template/] [doc.go] - Rev 747
Compare with Previous | Blame | View Log
// 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./*Package template implements data-driven templates for generating textualoutput such as HTML.Templates are executed by applying them to a data structure.Annotations in the template refer to elements of the datastructure (typically a field of a struct or a key in a map)to control execution and derive values to be displayed.The template walks the structure as it executes and the"cursor" @ represents the value at the current locationin the structure.Data items may be values or pointers; the interface hides theindirection.In the following, 'Field' is one of several things, according to the data.- The name of a field of a struct (result = data.Field),- The value stored in a map under that key (result = data["Field"]), or- The result of invoking a niladic single-valued method with that name(result = data.Field())If Field is a struct field or method name, it must be an exported(capitalized) name.Major constructs ({} are the default delimiters for template actions;[] are the notation in this comment for optional elements):{# comment }A one-line comment.{.section field} XXX [ {.or} YYY ] {.end}Set @ to the value of the field. It may be an explicit @to stay at the same point in the data. If the field is nilor empty, execute YYY; otherwise execute XXX.{.repeated section field} XXX [ {.alternates with} ZZZ ] [ {.or} YYY ] {.end}Like .section, but field must be an array or slice. XXXis executed for each element. If the array is nil or empty,YYY is executed instead. If the {.alternates with} markeris present, ZZZ is executed between iterations of XXX.{field}{field1 field2 ...}{field|formatter}{field1 field2...|formatter}{field|formatter1|formatter2}Insert the value of the fields into the output. Each field isfirst looked for in the cursor, as in .section and .repeated.If it is not found, the search continues in outer sectionsuntil the top level is reached.If the field value is a pointer, leading asterisks indicatethat the value to be inserted should be evaluated through thepointer. For example, if x.p is of type *int, {x.p} willinsert the value of the pointer but {*x.p} will insert thevalue of the underlying integer. If the value is nil or not apointer, asterisks have no effect.If a formatter is specified, it must be named in the formattermap passed to the template set up routines or in the defaultset ("html","str","") and is used to process the data foroutput. The formatter function has signaturefunc(wr io.Writer, formatter string, data ...interface{})where wr is the destination for output, data holds the fieldvalues at the instantiation, and formatter is its name atthe invocation site. The default formatter just concatenatesthe string representations of the fields.Multiple formatters separated by the pipeline character | areexecuted sequentially, with each formatter receiving the bytesemitted by the one to its left.As well as field names, one may use literals with Go syntax.Integer, floating-point, and string literals are supported.Raw strings may not span newlines.The delimiter strings get their default value, "{" and "}", fromJSON-template. They may be set to any non-empty, space-freestring using the SetDelims method. Their value can be printedin the output using {.meta-left} and {.meta-right}.*/package template
