Giant blob of minor changes
[dotfiles/.git] / .config / coc / extensions / coc-go-data / tools / pkg / mod / golang.org / x / tools@v0.0.0-20201105173854-bc9fc8d8c4bc / present / video.go
1 // Copyright 2016 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
4
5 package present
6
7 import (
8         "fmt"
9         "strings"
10 )
11
12 func init() {
13         Register("video", parseVideo)
14 }
15
16 type Video struct {
17         Cmd        string // original command from present source
18         URL        string
19         SourceType string
20         Width      int
21         Height     int
22 }
23
24 func (v Video) PresentCmd() string   { return v.Cmd }
25 func (v Video) TemplateName() string { return "video" }
26
27 func parseVideo(ctx *Context, fileName string, lineno int, text string) (Elem, error) {
28         args := strings.Fields(text)
29         if len(args) < 3 {
30                 return nil, fmt.Errorf("incorrect video invocation: %q", text)
31         }
32         vid := Video{Cmd: text, URL: args[1], SourceType: args[2]}
33         a, err := parseArgs(fileName, lineno, args[3:])
34         if err != nil {
35                 return nil, err
36         }
37         switch len(a) {
38         case 0:
39                 // no size parameters
40         case 2:
41                 // If a parameter is empty (underscore) or invalid
42                 // leave the field set to zero. The "video" action
43                 // template will then omit that vid tag attribute and
44                 // the browser will calculate the value to preserve
45                 // the aspect ratio.
46                 if v, ok := a[0].(int); ok {
47                         vid.Height = v
48                 }
49                 if v, ok := a[1].(int); ok {
50                         vid.Width = v
51                 }
52         default:
53                 return nil, fmt.Errorf("incorrect video invocation: %q", text)
54         }
55         return vid, nil
56 }