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
5package present
6
7import (
8	"fmt"
9	"strings"
10)
11
12func init() {
13	Register("iframe", parseIframe)
14}
15
16type Iframe struct {
17	URL    string
18	Width  int
19	Height int
20}
21
22func (i Iframe) TemplateName() string { return "iframe" }
23
24func 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:
42		return nil, fmt.Errorf("incorrect iframe invocation: %q", text)
43	}
44	return i, nil
45}
46