[release-branch.go1.3] go.tools/present: allow intentionally empty parameters
««« CL 105070043 / 1e6e75afb0cd go.tools/present: allow intentionally empty parameters Fixes golang/go#7613. LGTM=r R=adg, r CC=golang-codereviews https://golang.org/cl/105070043 »»» LGTM=dsymonds R=dsymonds CC=golang-codereviews https://golang.org/cl/148300043
This commit is contained in:
parent
84ece76229
commit
0f9e347959
|
@ -238,6 +238,8 @@ func parseArgs(name string, line int, args []string) (res []interface{}, err err
|
||||||
res[i] = v
|
res[i] = v
|
||||||
case '$':
|
case '$':
|
||||||
res[i] = "$"
|
res[i] = "$"
|
||||||
|
case '_':
|
||||||
|
// Do nothing; '_' indicates an intentionally empty parameter.
|
||||||
default:
|
default:
|
||||||
return nil, fmt.Errorf("%s:%d bad code argument %q", name, line, v)
|
return nil, fmt.Errorf("%s:%d bad code argument %q", name, line, v)
|
||||||
}
|
}
|
||||||
|
|
|
@ -168,10 +168,14 @@ The template uses the function "image" to inject picture files.
|
||||||
The syntax is simple: 1 or 3 space-separated arguments.
|
The syntax is simple: 1 or 3 space-separated arguments.
|
||||||
The first argument is always the file name.
|
The first argument is always the file name.
|
||||||
If there are more arguments, they are the height and width;
|
If there are more arguments, they are the height and width;
|
||||||
both must be present.
|
both must be present, or substituted with an underscore.
|
||||||
|
Replacing a dimension argument with the underscore parameter
|
||||||
|
preserves the aspect ratio of the image when scaling.
|
||||||
|
|
||||||
.image images/betsy.jpg 100 200
|
.image images/betsy.jpg 100 200
|
||||||
|
|
||||||
|
.image images/janet.jpg _ 300
|
||||||
|
|
||||||
iframe:
|
iframe:
|
||||||
|
|
||||||
The function "iframe" injects iframes (pages inside pages).
|
The function "iframe" injects iframes (pages inside pages).
|
||||||
|
|
|
@ -32,6 +32,11 @@ func parseImage(ctx *Context, fileName string, lineno int, text string) (Elem, e
|
||||||
case 0:
|
case 0:
|
||||||
// no size parameters
|
// no size parameters
|
||||||
case 2:
|
case 2:
|
||||||
|
// If a parameter is empty (underscore) or invalid
|
||||||
|
// leave the field set to zero. The "image" action
|
||||||
|
// template will then omit that img tag attribute and
|
||||||
|
// the browser will calculate the value to preserve
|
||||||
|
// the aspect ratio.
|
||||||
if v, ok := a[0].(int); ok {
|
if v, ok := a[0].(int); ok {
|
||||||
img.Height = v
|
img.Height = v
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue