mirror of
https://github.com/golang/go.git
synced 2025-05-05 15:43:04 +00:00
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>
This commit is contained in:
parent
d78e5d2552
commit
41b76ca51c
@ -391,18 +391,9 @@ article > .video {
|
|||||||
margin-top: 40px;
|
margin-top: 40px;
|
||||||
}
|
}
|
||||||
|
|
||||||
article > .background {
|
article.background {
|
||||||
position: absolute;
|
background-size: contain;
|
||||||
top: 0;
|
background-repeat: round;
|
||||||
left: 0;
|
|
||||||
right: 0;
|
|
||||||
bottom: 0;
|
|
||||||
z-index: -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
article > .background > img {
|
|
||||||
max-height: 100%;
|
|
||||||
max-width: 100%;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
table {
|
table {
|
||||||
|
@ -55,7 +55,7 @@
|
|||||||
|
|
||||||
{{range $i, $s := .Sections}}
|
{{range $i, $s := .Sections}}
|
||||||
<!-- start of slide {{$s.Number}} -->
|
<!-- start of slide {{$s.Number}} -->
|
||||||
<article>
|
<article {{$s.HTMLAttributes}}>
|
||||||
{{if $s.Elem}}
|
{{if $s.Elem}}
|
||||||
<h3>{{$s.Title}}</h3>
|
<h3>{{$s.Title}}</h3>
|
||||||
{{range $s.Elem}}{{elem $.Template .}}{{end}}
|
{{range $s.Elem}}{{elem $.Template .}}{{end}}
|
||||||
|
@ -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
|
|
||||||
}
|
|
@ -96,12 +96,32 @@ func (p *Author) TextElem() (elems []Elem) {
|
|||||||
// Section represents a section of a document (such as a presentation slide)
|
// Section represents a section of a document (such as a presentation slide)
|
||||||
// comprising a title and a list of elements.
|
// comprising a title and a list of elements.
|
||||||
type Section struct {
|
type Section struct {
|
||||||
Number []int
|
Number []int
|
||||||
Title string
|
Title string
|
||||||
Elem []Elem
|
Elem []Elem
|
||||||
Notes []string
|
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) {
|
func (s Section) Sections() (sections []Section) {
|
||||||
for _, e := range s.Elem {
|
for _, e := range s.Elem {
|
||||||
if section, ok := e.(Section); ok {
|
if section, ok := e.(Section); ok {
|
||||||
@ -366,6 +386,11 @@ func parseSections(ctx *Context, name string, lines *Lines, number []int) ([]Sec
|
|||||||
}
|
}
|
||||||
case strings.HasPrefix(text, "."):
|
case strings.HasPrefix(text, "."):
|
||||||
args := strings.Fields(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]]
|
parser := parsers[args[0]]
|
||||||
if parser == nil {
|
if parser == nil {
|
||||||
return nil, fmt.Errorf("%s:%d: unknown command %q\n", name, lines.line, text)
|
return nil, fmt.Errorf("%s:%d: unknown command %q\n", name, lines.line, text)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user