File: video.go

package info (click to toggle)
golang-golang-x-tools 1%3A0.5.0%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bookworm-backports
  • size: 16,592 kB
  • sloc: javascript: 2,011; asm: 1,635; sh: 192; yacc: 155; makefile: 52; ansic: 8
file content (56 lines) | stat: -rw-r--r-- 1,371 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// 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 {
	Cmd        string // original command from present source
	URL        string
	SourceType string
	Width      int
	Height     int
}

func (v Video) PresentCmd() string   { return v.Cmd }
func (v Video) TemplateName() string { return "video" }

func parseVideo(ctx *Context, fileName string, lineno int, text string) (Elem, error) {
	args := strings.Fields(text)
	if len(args) < 3 {
		return nil, fmt.Errorf("incorrect video invocation: %q", text)
	}
	vid := Video{Cmd: text, 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
}