github.com/jgarto/itcv@v0.0.0-20180826224514-4eea09c1aa0d/_vendor/src/golang.org/x/tools/present/video.go (about)

     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  	URL        string
    18  	SourceType string
    19  	Width      int
    20  	Height     int
    21  }
    22  
    23  func (v Video) TemplateName() string { return "video" }
    24  
    25  func parseVideo(ctx *Context, fileName string, lineno int, text string) (Elem, error) {
    26  	args := strings.Fields(text)
    27  	vid := Video{URL: args[1], SourceType: args[2]}
    28  	a, err := parseArgs(fileName, lineno, args[3:])
    29  	if err != nil {
    30  		return nil, err
    31  	}
    32  	switch len(a) {
    33  	case 0:
    34  		// no size parameters
    35  	case 2:
    36  		// If a parameter is empty (underscore) or invalid
    37  		// leave the field set to zero. The "video" action
    38  		// template will then omit that vid tag attribute and
    39  		// the browser will calculate the value to preserve
    40  		// the aspect ratio.
    41  		if v, ok := a[0].(int); ok {
    42  			vid.Height = v
    43  		}
    44  		if v, ok := a[1].(int); ok {
    45  			vid.Width = v
    46  		}
    47  	default:
    48  		return nil, fmt.Errorf("incorrect video invocation: %q", text)
    49  	}
    50  	return vid, nil
    51  }