OLD | NEW |
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 package present | 5 package present |
6 | 6 |
7 import ( | 7 import ( |
8 "bytes" | 8 "bytes" |
9 "errors" | 9 "errors" |
10 "fmt" | 10 "fmt" |
(...skipping 22 matching lines...) Expand all Loading... |
33 func (d *Doc) Render(w io.Writer, t *template.Template) error { | 33 func (d *Doc) Render(w io.Writer, t *template.Template) error { |
34 data := struct { | 34 data := struct { |
35 *Doc | 35 *Doc |
36 Template *template.Template | 36 Template *template.Template |
37 }{d, t} | 37 }{d, t} |
38 return t.ExecuteTemplate(w, "root", data) | 38 return t.ExecuteTemplate(w, "root", data) |
39 } | 39 } |
40 | 40 |
41 type ParseFunc func(fileName string, lineNumber int, inputLine string) (Elem, er
ror) | 41 type ParseFunc func(fileName string, lineNumber int, inputLine string) (Elem, er
ror) |
42 | 42 |
43 // Register binds the named action, which does not being with a period, to the | 43 // Register binds the named action, which does not begin with a period, to the |
44 // specified parser to be invoked when the name, with a period, appears in the | 44 // specified parser to be invoked when the name, with a period, appears in the |
45 // present input text. | 45 // present input text. |
46 func Register(name string, parser ParseFunc) { | 46 func Register(name string, parser ParseFunc) { |
47 if len(name) == 0 || name[0] == ';' { | 47 if len(name) == 0 || name[0] == ';' { |
48 panic("bad name in Register: " + name) | 48 panic("bad name in Register: " + name) |
49 } | 49 } |
50 parsers["."+name] = parser | 50 parsers["."+name] = parser |
51 } | 51 } |
52 | 52 |
53 // Doc represents an entire document. | 53 // Doc represents an entire document. |
(...skipping 401 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
455 return t, true | 455 return t, true |
456 } | 456 } |
457 t, err = time.Parse("2 Jan 2006", text) | 457 t, err = time.Parse("2 Jan 2006", text) |
458 if err == nil { | 458 if err == nil { |
459 // at 11am UTC it is the same date everywhere | 459 // at 11am UTC it is the same date everywhere |
460 t = t.Add(time.Hour * 11) | 460 t = t.Add(time.Hour * 11) |
461 return t, true | 461 return t, true |
462 } | 462 } |
463 return time.Time{}, false | 463 return time.Time{}, false |
464 } | 464 } |
OLD | NEW |