present: Set the background using CSS
This allowed me to better match the background image to the size of
the slides.
Change-Id: Ieaae93cd78582a3059ed6c3e64e740dea9088af5
Reviewed-on: https://go-review.googlesource.com/47130
Reviewed-by: Andrew Gerrand <adg@golang.org>
Run-TryBot: Andrew Gerrand <adg@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
diff --git a/cmd/present/static/styles.css b/cmd/present/static/styles.css
index d877682..bd24e4c 100644
--- a/cmd/present/static/styles.css
+++ b/cmd/present/static/styles.css
@@ -391,18 +391,9 @@
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%;
+article.background {
+ background-size: contain;
+ background-repeat: round;
}
table {
diff --git a/cmd/present/templates/slides.tmpl b/cmd/present/templates/slides.tmpl
index 878440b..3748400 100644
--- a/cmd/present/templates/slides.tmpl
+++ b/cmd/present/templates/slides.tmpl
@@ -55,7 +55,7 @@
{{range $i, $s := .Sections}}
<!-- start of slide {{$s.Number}} -->
- <article>
+ <article {{$s.HTMLAttributes}}>
{{if $s.Elem}}
<h3>{{$s.Title}}</h3>
{{range $s.Elem}}{{elem $.Template .}}{{end}}
diff --git a/present/background.go b/present/background.go
deleted file mode 100644
index 0a6216a..0000000
--- a/present/background.go
+++ /dev/null
@@ -1,25 +0,0 @@
-// 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
-}
diff --git a/present/parse.go b/present/parse.go
index b26d65b..d7289db 100644
--- a/present/parse.go
+++ b/present/parse.go
@@ -96,12 +96,32 @@
// Section represents a section of a document (such as a presentation slide)
// comprising a title and a list of elements.
type Section struct {
- Number []int
- Title string
- Elem []Elem
- Notes []string
+ Number []int
+ Title string
+ Elem []Elem
+ Notes []string
+ Classes []string
+ Styles []string
}
+// HTMLAttributes for the section
+func (s Section) HTMLAttributes() template.HTMLAttr {
+ if len(s.Classes) == 0 && len(s.Styles) == 0 {
+ return ""
+ }
+
+ var class string
+ if len(s.Classes) > 0 {
+ class = fmt.Sprintf(`class=%q`, strings.Join(s.Classes, " "))
+ }
+ var style string
+ if len(s.Styles) > 0 {
+ style = fmt.Sprintf(`style=%q`, strings.Join(s.Styles, " "))
+ }
+ return template.HTMLAttr(strings.Join([]string{class, style}, " "))
+}
+
+// Sections contained within the section.
func (s Section) Sections() (sections []Section) {
for _, e := range s.Elem {
if section, ok := e.(Section); ok {
@@ -366,6 +386,11 @@
}
case strings.HasPrefix(text, "."):
args := strings.Fields(text)
+ if args[0] == ".background" {
+ section.Classes = append(section.Classes, "background")
+ section.Styles = append(section.Styles, "background-image: url('"+args[1]+"')")
+ break
+ }
parser := parsers[args[0]]
if parser == nil {
return nil, fmt.Errorf("%s:%d: unknown command %q\n", name, lines.line, text)