...
1
2
3
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
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
40 case 2:
41
42
43
44
45
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 }
57
View as plain text