present: add background image element for slides

Fixes golang/go#11470

Change-Id: I665622197bea48b95adc839be8de7d03bf812f37
Reviewed-on: https://go-review.googlesource.com/18360
Reviewed-by: Andrew Gerrand <adg@golang.org>
This commit is contained in:
Timothy Studd 2016-01-06 16:52:04 -08:00 committed by Andrew Gerrand
parent 791f468ced
commit 1e63c6ac3b
4 changed files with 53 additions and 1 deletions

View File

@ -384,6 +384,20 @@ article > .image {
margin-top: 40px; margin-top: 40px;
} }
article > .background {
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
z-index: -1;
}
article > .background > img {
max-height: 100%;
max-width: 100%;
}
table { table {
width: 100%; width: 100%;
border-collapse: collapse; border-collapse: collapse;

View File

@ -37,6 +37,12 @@ It determines how the formatting actions are rendered.
</div> </div>
{{end}} {{end}}
{{define "background"}}
<div class="background">
<img src="{{.URL}}">
</div>
{{end}}
{{define "iframe"}} {{define "iframe"}}
<iframe src="{{.URL}}"{{with .Height}} height="{{.}}"{{end}}{{with .Width}} width="{{.}}"{{end}}></iframe> <iframe src="{{.URL}}"{{with .Height}} height="{{.}}"{{end}}{{with .Width}} width="{{.}}"{{end}}></iframe>
{{end}} {{end}}

25
present/background.go Normal file
View File

@ -0,0 +1,25 @@
// Copyright 2016 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 present
import (
"strings"
)
func init() {
Register("background", parseBackground)
}
type Background struct {
URL string
}
func (i Background) TemplateName() string { return "background" }
func parseBackground(ctx *Context, fileName string, lineno int, text string) (Elem, error) {
args := strings.Fields(text)
background := Background{URL: args[1]}
return background, nil
}

View File

@ -58,6 +58,7 @@ After that come slides/sections, each after a blank line:
.code x.go /^func main/,/^}/ .code x.go /^func main/,/^}/
.play y.go .play y.go
.image image.jpg .image image.jpg
.background image.jpg
.iframe http://foo .iframe http://foo
.link http://foo label .link http://foo label
.html file.html .html file.html
@ -177,6 +178,12 @@ preserves the aspect ratio of the image when scaling.
.image images/janet.jpg _ 300 .image images/janet.jpg _ 300
background:
The template uses the function "background" to set the background image for
a slide. The only argument is the file name of the image.
.background images/susan.jpg
caption: caption: