GoPLS Viewer

Home|gopls/godoc/static/gen.go
1// Copyright 2014 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 static
6
7//go:generate go run makestatic.go
8
9import (
10    "bytes"
11    "fmt"
12    "go/format"
13    "io/ioutil"
14    "unicode"
15)
16
17var files = []string{
18    "analysis/call3.png",
19    "analysis/call-eg.png",
20    "analysis/callers1.png",
21    "analysis/callers2.png",
22    "analysis/chan1.png",
23    "analysis/chan2a.png",
24    "analysis/chan2b.png",
25    "analysis/error1.png",
26    "analysis/help.html",
27    "analysis/ident-def.png",
28    "analysis/ident-field.png",
29    "analysis/ident-func.png",
30    "analysis/ipcg-func.png",
31    "analysis/ipcg-pkg.png",
32    "analysis/typeinfo-pkg.png",
33    "analysis/typeinfo-src.png",
34    "callgraph.html",
35    "dirlist.html",
36    "error.html",
37    "example.html",
38    "favicon.ico",
39    "godoc.html",
40    "godocs.js",
41    "gopher/pkg.png",
42    "images/minus.gif",
43    "images/plus.gif",
44    "images/treeview-black-line.gif",
45    "images/treeview-black.gif",
46    "images/treeview-default-line.gif",
47    "images/treeview-default.gif",
48    "images/treeview-gray-line.gif",
49    "images/treeview-gray.gif",
50    "implements.html",
51    "jquery.js",
52    "jquery.treeview.css",
53    "jquery.treeview.edit.js",
54    "jquery.treeview.js",
55    "methodset.html",
56    "package.html",
57    "packageroot.html",
58    "play.js",
59    "playground.js",
60    "search.html",
61    "searchcode.html",
62    "searchdoc.html",
63    "searchtxt.html",
64    "style.css",
65}
66
67// Generate reads a set of files and returns a file buffer that declares
68// a map of string constants containing contents of the input files.
69func Generate() ([]byteerror) {
70    buf := new(bytes.Buffer)
71    fmt.Fprintf(buf"%v\n\n%v\n\npackage static\n\n"licensewarning)
72    fmt.Fprintf(buf"var Files = map[string]string{\n")
73    for _fn := range files {
74        berr := ioutil.ReadFile(fn)
75        if err != nil {
76            return berr
77        }
78        fmt.Fprintf(buf"\t%q: "fn)
79        appendQuote(bufb)
80        fmt.Fprintf(buf",\n\n")
81    }
82    fmt.Fprintln(buf"}")
83    return format.Source(buf.Bytes())
84}
85
86// appendQuote is like strconv.AppendQuote, but we avoid the latter
87// because it changes when Unicode evolves, breaking gen_test.go.
88func appendQuote(out *bytes.Bufferdata []byte) {
89    out.WriteByte('"')
90    for _b := range data {
91        if b == '\\' || b == '"' {
92            out.WriteByte('\\')
93            out.WriteByte(b)
94        } else if b <= unicode.MaxASCII && unicode.IsPrint(rune(b)) && !unicode.IsSpace(rune(b)) {
95            out.WriteByte(b)
96        } else {
97            fmt.Fprintf(out"\\x%02x"b)
98        }
99    }
100    out.WriteByte('"')
101}
102
103const warning = `// Code generated by "makestatic"; DO NOT EDIT.`
104
105const license = `// Copyright 2013 The Go Authors. All rights reserved.
106// Use of this source code is governed by a BSD-style
107// license that can be found in the LICENSE file.`
108
MembersX
fmt
Generate
Generate.RangeStmt_1699.BlockStmt.b
appendQuote
license
unicode
Generate.RangeStmt_1699.BlockStmt.err
appendQuote.out
format
ioutil
Generate.RangeStmt_1699.fn
appendQuote.data
appendQuote.RangeStmt_2151.b
warning
bytes
Generate.buf
Members
X