Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(4)

Delta Between Two Patch Sets: doc/tmpltohtml.go

Issue 5415060: code review 5415060: text/template: new, simpler API (Closed)
Left Patch Set: Created 13 years, 3 months ago
Right Patch Set: diff -r 75348d679279 https://go.googlecode.com/hg/ Created 13 years, 3 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Right: Side by side diff | Download
« no previous file with change/comment | « doc/codelab/wiki/index.html ('k') | src/pkg/Makefile » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
(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
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
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 }
LEFTRIGHT

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b