1 | // Copyright 2013 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("iframe", parseIframe) |
14 | } |
15 | |
16 | type Iframe struct { |
17 | Cmd string // original command from present source |
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 | // no size parameters |
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 |
Members