1
0
mirror of https://github.com/golang/go synced 2024-11-05 14:46:11 -07:00
go/present/iframe.go
Andrew Gerrand 9fc516408c go.tools/godoc/present: move present package from go.talks
Godoc depends on go.talks/pkg/present by way of go.tools/pkg/blog.
Better to keep all godoc dependencies in one place.

R=golang-dev, dsymonds, r
CC=golang-dev
https://golang.org/cl/13656047
2013-09-19 10:55:46 +10:00

46 lines
867 B
Go

// 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 image invocation: %q", text)
}
return i, nil
}