GoPLS Viewer

Home|gopls/present/image.go
1// Copyright 2012 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
5package present
6
7import (
8    "fmt"
9    "strings"
10)
11
12func init() {
13    Register("image"parseImage)
14}
15
16type Image struct {
17    Cmd    string // original command from present source
18    URL    string
19    Width  int
20    Height int
21}
22
23func (i ImagePresentCmd() string   { return i.Cmd }
24func (i ImageTemplateName() string { return "image" }
25
26func parseImage(ctx *ContextfileName stringlineno inttext string) (Elemerror) {
27    args := strings.Fields(text)
28    if len(args) < 2 {
29        return nilfmt.Errorf("incorrect image invocation: %q"text)
30    }
31    img := Image{CmdtextURLargs[1]}
32    aerr := parseArgs(fileNamelinenoargs[2:])
33    if err != nil {
34        return nilerr
35    }
36    switch len(a) {
37    case 0:
38        // no size parameters
39    case 2:
40        // If a parameter is empty (underscore) or invalid
41        // leave the field set to zero. The "image" action
42        // template will then omit that img tag attribute and
43        // the browser will calculate the value to preserve
44        // the aspect ratio.
45        if vok := a[0].(int); ok {
46            img.Height = v
47        }
48        if vok := a[1].(int); ok {
49            img.Width = v
50        }
51    default:
52        return nilfmt.Errorf("incorrect image invocation: %q"text)
53    }
54    return imgnil
55}
56
MembersX
Image.URL
Image.PresentCmd
Image.TemplateName.i
Image.Cmd
Image.TemplateName
parseImage.err
Image.PresentCmd.i
parseImage.text
parseImage.args
Image
Image.Width
Image.Height
parseImage.lineno
parseImage.img
parseImage.a
parseImage
parseImage.ctx
parseImage.fileName
Members
X