Debian Codegraph @

present/image.go

raw symbols SCIP
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
5 package presentscip-go gomod golang.org/x/tools . `golang.org/x/tools/present`/
6
7 import (
8 "fmtscip-go gomod github.com/golang/go/src go1.25.0 fmt/"
9 "stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/"
10 )
11
12 func initscip-go gomod golang.org/x/tools . `golang.org/x/tools/present`/init().() {
13 Registerscip-go gomod golang.org/x/tools . `golang.org/x/tools/present`/Register().("image", parseImagescip-go gomod golang.org/x/tools . `golang.org/x/tools/present`/parseImage().)
14 }
15
16 type Imagescip-go gomod golang.org/x/tools . `golang.org/x/tools/present`/Image# struct {
17 Cmdscip-go gomod golang.org/x/tools . `golang.org/x/tools/present`/Image#Cmd. string // original command from present source
18 URLscip-go gomod golang.org/x/tools . `golang.org/x/tools/present`/Image#URL. string
19 Widthscip-go gomod golang.org/x/tools . `golang.org/x/tools/present`/Image#Width. int
20 Heightscip-go gomod golang.org/x/tools . `golang.org/x/tools/present`/Image#Height. int
21 }
22
23 func (i Imagescip-go gomod golang.org/x/tools . `golang.org/x/tools/present`/Image#) PresentCmdscip-go gomod golang.org/x/tools . `golang.org/x/tools/present`/Image#PresentCmd().() string { return i.Cmdscip-go gomod golang.org/x/tools . `golang.org/x/tools/present`/Image#Cmd. }
24 func (i Imagescip-go gomod golang.org/x/tools . `golang.org/x/tools/present`/Image#) TemplateNamescip-go gomod golang.org/x/tools . `golang.org/x/tools/present`/Image#TemplateName().() string { return "image" }
25
26 func parseImagescip-go gomod golang.org/x/tools . `golang.org/x/tools/present`/parseImage().(ctx *Contextscip-go gomod golang.org/x/tools . `golang.org/x/tools/present`/Context#, fileName string, lineno int, text string) (Elemscip-go gomod golang.org/x/tools . `golang.org/x/tools/present`/Elem#, error) {
27 args := stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/.Fieldsscip-go gomod github.com/golang/go/src go1.25.0 strings/Fields().(text)
28 if len(args) < 2 {
29 return nil, fmtscip-go gomod github.com/golang/go/src go1.25.0 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.25.0 fmt/Errorf().("incorrect image invocation: %q", text)
30 }
31 img := Imagescip-go gomod golang.org/x/tools . `golang.org/x/tools/present`/Image#{Cmdscip-go gomod golang.org/x/tools . `golang.org/x/tools/present`/Image#Cmd.: text, URLscip-go gomod golang.org/x/tools . `golang.org/x/tools/present`/Image#URL.: args[1]}
32 a, err := parseArgsscip-go gomod golang.org/x/tools . `golang.org/x/tools/present`/parseArgs().(fileName, lineno, args[2:])
33 if err != nil {
34 return nil, err
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 v, ok := a[0].(int); ok {
46 img.Heightscip-go gomod golang.org/x/tools . `golang.org/x/tools/present`/Image#Height. = v
47 }
48 if v, ok := a[1].(int); ok {
49 img.Widthscip-go gomod golang.org/x/tools . `golang.org/x/tools/present`/Image#Width. = v
50 }
51 default:
52 return nil, fmtscip-go gomod github.com/golang/go/src go1.25.0 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.25.0 fmt/Errorf().("incorrect image invocation: %q", text)
53 }
54 return img, nil
55 }