...
1
2
3
4
5 package present
6
7 import (
8 "fmt"
9 "strings"
10 )
11
12 func init() {
13 Register("iframe", parseIframe)
14 }
15
16 type Iframe struct {
17 Cmd string
18 URL string
19 Width int
20 Height int
21 }
22
23 func (i Iframe) PresentCmd() string { return i.Cmd }
24 func (i Iframe) TemplateName() string { return "iframe" }
25
26 func parseIframe(ctx *Context, fileName string, lineno int, text string) (Elem, error) {
27 args := strings.Fields(text)
28 if len(args) < 2 {
29 return nil, fmt.Errorf("incorrect iframe invocation: %q", text)
30 }
31 i := Iframe{Cmd: text, URL: args[1]}
32 a, err := parseArgs(fileName, lineno, args[2:])
33 if err != nil {
34 return nil, err
35 }
36 switch len(a) {
37 case 0:
38
39 case 2:
40 if v, ok := a[0].(int); ok {
41 i.Height = v
42 }
43 if v, ok := a[1].(int); ok {
44 i.Width = v
45 }
46 default:
47 return nil, fmt.Errorf("incorrect iframe invocation: %q", text)
48 }
49 return i, nil
50 }
51
View as plain text