1
0
mirror of https://github.com/golang/go synced 2024-11-05 17:46:16 -07:00

x/tools/present: add video element for slides

Change-Id: I19f7c181d9bd8148f7791925f04207a34c95ac1e
Reviewed-on: https://go-review.googlesource.com/18484
Reviewed-by: Andrew Gerrand <adg@golang.org>
This commit is contained in:
Timothy Studd 2016-01-10 14:03:33 -08:00 committed by Andrew Gerrand
parent f8ecfdb6b6
commit b57d82def5
4 changed files with 77 additions and 1 deletions

View File

@ -379,7 +379,8 @@ code {
color: black; color: black;
} }
article > .image { article > .image,
article > .video {
text-align: center; text-align: center;
margin-top: 40px; margin-top: 40px;
} }

View File

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

View File

@ -178,6 +178,22 @@ preserves the aspect ratio of the image when scaling.
.image images/janet.jpg _ 300 .image images/janet.jpg _ 300
video:
The template uses the function "video" to inject video files.
The syntax is simple: 2 or 4 space-separated arguments.
The first argument is always the file name.
The second argument is always the file content-type.
If there are more arguments, they are the height and width;
both must be present, or substituted with an underscore.
Replacing a dimension argument with the underscore parameter
preserves the aspect ratio of the video when scaling.
.video videos/evangeline.mp4 video/mp4 400 600
.video videos/mabel.ogg video/ogg 500 _
background: background:
The template uses the function "background" to set the background image for The template uses the function "background" to set the background image for

51
present/video.go Normal file
View File

@ -0,0 +1,51 @@
// 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 (
"fmt"
"strings"
)
func init() {
Register("video", parseVideo)
}
type Video struct {
URL string
SourceType string
Width int
Height int
}
func (v Video) TemplateName() string { return "video" }
func parseVideo(ctx *Context, fileName string, lineno int, text string) (Elem, error) {
args := strings.Fields(text)
vid := Video{URL: args[1], SourceType: args[2]}
a, err := parseArgs(fileName, lineno, args[3:])
if err != nil {
return nil, err
}
switch len(a) {
case 0:
// no size parameters
case 2:
// If a parameter is empty (underscore) or invalid
// leave the field set to zero. The "video" action
// template will then omit that vid tag attribute and
// the browser will calculate the value to preserve
// the aspect ratio.
if v, ok := a[0].(int); ok {
vid.Height = v
}
if v, ok := a[1].(int); ok {
vid.Width = v
}
default:
return nil, fmt.Errorf("incorrect video invocation: %q", text)
}
return vid, nil
}