GoPLS Viewer

Home|gopls/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
5package present
6
7import (
8    "fmt"
9    "strings"
10)
11
12func init() {
13    Register("video"parseVideo)
14}
15
16type Video struct {
17    Cmd        string // original command from present source
18    URL        string
19    SourceType string
20    Width      int
21    Height     int
22}
23
24func (v VideoPresentCmd() string   { return v.Cmd }
25func (v VideoTemplateName() string { return "video" }
26
27func parseVideo(ctx *ContextfileName stringlineno inttext string) (Elemerror) {
28    args := strings.Fields(text)
29    if len(args) < 3 {
30        return nilfmt.Errorf("incorrect video invocation: %q"text)
31    }
32    vid := Video{CmdtextURLargs[1], SourceTypeargs[2]}
33    aerr := parseArgs(fileNamelinenoargs[3:])
34    if err != nil {
35        return nilerr
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 vok := a[0].(int); ok {
47            vid.Height = v
48        }
49        if vok := a[1].(int); ok {
50            vid.Width = v
51        }
52    default:
53        return nilfmt.Errorf("incorrect video invocation: %q"text)
54    }
55    return vidnil
56}
57
MembersX
Video.SourceType
Video.PresentCmd.v
parseVideo.fileName
parseVideo.lineno
Video.TemplateName.v
parseVideo.vid
parseVideo.a
Video.Cmd
Video.Width
Video.Height
Video.PresentCmd
Video.TemplateName
parseVideo.ctx
parseVideo.args
parseVideo.err
Video
Video.URL
parseVideo
parseVideo.text
Members
X