2013-09-19 04:55:46 +04:00
|
|
|
// 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 {
|
2020-03-10 05:20:35 +03:00
|
|
|
Cmd string // original command from present source
|
2013-09-19 04:55:46 +04:00
|
|
|
URL string
|
|
|
|
Width int
|
|
|
|
Height int
|
|
|
|
}
|
|
|
|
|
2020-03-10 05:20:35 +03:00
|
|
|
func (i Iframe) PresentCmd() string { return i.Cmd }
|
2013-09-19 04:55:46 +04:00
|
|
|
func (i Iframe) TemplateName() string { return "iframe" }
|
|
|
|
|
|
|
|
func parseIframe(ctx *Context, fileName string, lineno int, text string) (Elem, error) {
|
|
|
|
args := strings.Fields(text)
|
2019-10-25 19:20:13 +03:00
|
|
|
if len(args) < 2 {
|
|
|
|
return nil, fmt.Errorf("incorrect iframe invocation: %q", text)
|
|
|
|
}
|
2020-03-10 05:20:35 +03:00
|
|
|
i := Iframe{Cmd: text, URL: args[1]}
|
2013-09-19 04:55:46 +04:00
|
|
|
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:
|
2017-01-15 23:31:16 +03:00
|
|
|
return nil, fmt.Errorf("incorrect iframe invocation: %q", text)
|
2013-09-19 04:55:46 +04:00
|
|
|
}
|
|
|
|
return i, nil
|
|
|
|
}
|