You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

45 lines
868 B

  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. package present
  5. import (
  6. "fmt"
  7. "strings"
  8. )
  9. func init() {
  10. Register("iframe", parseIframe)
  11. }
  12. type Iframe struct {
  13. URL string
  14. Width int
  15. Height int
  16. }
  17. func (i Iframe) TemplateName() string { return "iframe" }
  18. func parseIframe(ctx *Context, fileName string, lineno int, text string) (Elem, error) {
  19. args := strings.Fields(text)
  20. i := Iframe{URL: args[1]}
  21. a, err := parseArgs(fileName, lineno, args[2:])
  22. if err != nil {
  23. return nil, err
  24. }
  25. switch len(a) {
  26. case 0:
  27. // no size parameters
  28. case 2:
  29. if v, ok := a[0].(int); ok {
  30. i.Height = v
  31. }
  32. if v, ok := a[1].(int); ok {
  33. i.Width = v
  34. }
  35. default:
  36. return nil, fmt.Errorf("incorrect iframe invocation: %q", text)
  37. }
  38. return i, nil
  39. }