github.com/jgarto/itcv@v0.0.0-20180826224514-4eea09c1aa0d/_vendor/src/golang.org/x/tools/present/iframe.go (about)

     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:
    42  		return nil, fmt.Errorf("incorrect iframe invocation: %q", text)
    43  	}
    44  	return i, nil
    45  }