Andrew Gerrand | 9fc5164 | 2013-09-19 10:55:46 +1000 | [diff] [blame] | 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 | URL string |
| 18 | Width int |
| 19 | Height int |
| 20 | } |
| 21 | |
| 22 | func (i Iframe) TemplateName() string { return "iframe" } |
| 23 | |
| 24 | func parseIframe(ctx *Context, fileName string, lineno int, text string) (Elem, error) { |
| 25 | args := strings.Fields(text) |
| 26 | i := Iframe{URL: args[1]} |
| 27 | a, err := parseArgs(fileName, lineno, args[2:]) |
| 28 | if err != nil { |
| 29 | return nil, err |
| 30 | } |
| 31 | switch len(a) { |
| 32 | case 0: |
| 33 | // no size parameters |
| 34 | case 2: |
| 35 | if v, ok := a[0].(int); ok { |
| 36 | i.Height = v |
| 37 | } |
| 38 | if v, ok := a[1].(int); ok { |
| 39 | i.Width = v |
| 40 | } |
| 41 | default: |
gulyasm | 608c3b0 | 2017-01-15 20:31:16 +0000 | [diff] [blame] | 42 | return nil, fmt.Errorf("incorrect iframe invocation: %q", text) |
Andrew Gerrand | 9fc5164 | 2013-09-19 10:55:46 +1000 | [diff] [blame] | 43 | } |
| 44 | return i, nil |
| 45 | } |