summaryrefslogtreecommitdiff
path: root/vendor/golang.org/x/tools/present/iframe.go
blob: 46649f0f1e6103175fe6706d16bc625539b1e255 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
// Copyright 2013 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package present

import (
	"fmt"
	"strings"
)

func init() {
	Register("iframe", parseIframe)
}

type Iframe struct {
	URL    string
	Width  int
	Height int
}

func (i Iframe) TemplateName() string { return "iframe" }

func parseIframe(ctx *Context, fileName string, lineno int, text string) (Elem, error) {
	args := strings.Fields(text)
	i := Iframe{URL: args[1]}
	a, err := parseArgs(fileName, lineno, args[2:])
	if err != nil {
		return nil, err
	}
	switch len(a) {
	case 0:
		// no size parameters
	case 2:
		if v, ok := a[0].(int); ok {
			i.Height = v
		}
		if v, ok := a[1].(int); ok {
			i.Width = v
		}
	default:
		return nil, fmt.Errorf("incorrect iframe invocation: %q", text)
	}
	return i, nil
}