LEFT | RIGHT |
(no file at all) | |
1 // Copyright 2011 The Go Authors. All rights reserved. | 1 // Copyright 2011 The Go Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style | 2 // Use of this source code is governed by a BSD-style |
3 // license that can be found in the LICENSE file. | 3 // license that can be found in the LICENSE file. |
4 | 4 |
5 // The template uses the function "code" to inject program | 5 // The template uses the function "code" to inject program |
6 // source into the output by extracting code from files and | 6 // source into the output by extracting code from files and |
7 // injecting them as HTML-escaped <pre> blocks. | 7 // injecting them as HTML-escaped <pre> blocks. |
8 // | 8 // |
9 // The syntax is simple: 1, 2, or 3 space-separated arguments: | 9 // The syntax is simple: 1, 2, or 3 space-separated arguments: |
10 // | 10 // |
(...skipping 27 matching lines...) Expand all Loading... |
38 func main() { | 38 func main() { |
39 flag.Usage = Usage | 39 flag.Usage = Usage |
40 flag.Parse() | 40 flag.Parse() |
41 if len(flag.Args()) != 1 { | 41 if len(flag.Args()) != 1 { |
42 Usage() | 42 Usage() |
43 } | 43 } |
44 | 44 |
45 // Read and parse the input. | 45 // Read and parse the input. |
46 name := flag.Args()[0] | 46 name := flag.Args()[0] |
47 tmpl := template.New(name).Funcs(template.FuncMap{"code": code}) | 47 tmpl := template.New(name).Funcs(template.FuncMap{"code": code}) |
48 » if _, err := tmpl.ParseFile(name); err != nil { | 48 » if _, err := tmpl.ParseFiles(name); err != nil { |
49 log.Fatal(err) | 49 log.Fatal(err) |
50 } | 50 } |
51 | 51 |
52 // Execute the template. | 52 // Execute the template. |
53 if err := tmpl.Execute(os.Stdout, 0); err != nil { | 53 if err := tmpl.Execute(os.Stdout, 0); err != nil { |
54 log.Fatal(err) | 54 log.Fatal(err) |
55 } | 55 } |
56 } | 56 } |
57 | 57 |
58 // contents reads a file by name and returns its contents as a string. | 58 // contents reads a file by name and returns its contents as a string. |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
166 for i := start; i < len(lines); i++ { | 166 for i := start; i < len(lines); i++ { |
167 if re.MatchString(lines[i]) { | 167 if re.MatchString(lines[i]) { |
168 return i + 1 | 168 return i + 1 |
169 } | 169 } |
170 } | 170 } |
171 log.Fatalf("%s: no match for %#q", file, pattern) | 171 log.Fatalf("%s: no match for %#q", file, pattern) |
172 } | 172 } |
173 log.Fatalf("unrecognized pattern: %q", pattern) | 173 log.Fatalf("unrecognized pattern: %q", pattern) |
174 return 0 | 174 return 0 |
175 } | 175 } |
LEFT | RIGHT |