| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 package templates | 5 package templates |
| 6 | 6 |
| 7 import ( | 7 import ( |
| 8 "bytes" | 8 "bytes" |
| 9 "text/template" | 9 "text/template" |
| 10 | 10 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 | 27 |
| 28 if err != nil { | 28 if err != nil { |
| 29 panic(err) | 29 panic(err) |
| 30 } | 30 } |
| 31 return src | 31 return src |
| 32 } | 32 } |
| 33 | 33 |
| 34 func init() { | 34 func init() { |
| 35 // We parse the subtemplates only once. | 35 // We parse the subtemplates only once. |
| 36 goFileTmpl = template.New("GoFileTemplate") | 36 goFileTmpl = template.New("GoFileTemplate") |
| 37 |
| 37 template.Must(goFileTmpl.Parse(goFileTemplate)) | 38 template.Must(goFileTmpl.Parse(goFileTemplate)) |
| 38 template.Must(goFileTmpl.Parse(nonNullableFieldDecodingTmplText)) | |
| 39 template.Must(goFileTmpl.Parse(fieldDecodingTmplText)) | |
| 40 | 39 |
| 41 » template.Must(goFileTmpl.Parse(nonNullableFieldEncodingTmplText)) | 40 » initEncodingTemplates() |
| 42 » template.Must(goFileTmpl.Parse(fieldEncodingTmplText)) | 41 » initDecodingTemplates() |
| 43 » template.Must(goFileTmpl.Parse(structEncodingTmplText)) | 42 » initStructTemplates() |
| 44 » template.Must(goFileTmpl.Parse(structDeclTmplText)) | 43 » initUnionTemplates() |
| 45 » template.Must(goFileTmpl.Parse(structVersions)) | |
| 46 » template.Must(goFileTmpl.Parse(structDecodingTmplText)) | |
| 47 } | 44 } |
| 48 | 45 |
| 49 const goFileTemplate = ` | 46 const goFileTemplate = ` |
| 50 {{- define "FileTemplate" -}} | 47 {{- define "FileTemplate" -}} |
| 51 {{- $fileTmpl := . -}} | 48 {{- $fileTmpl := . -}} |
| 52 package {{$fileTmpl.PackageName}} | 49 package {{$fileTmpl.PackageName}} |
| 53 | 50 |
| 54 import ( | 51 import ( |
| 55 {{range $import := $fileTmpl.Imports}} | 52 {{range $import := $fileTmpl.Imports}} |
| 56 {{$import.PackageName}} "{{$import.PackagePath}}" | 53 {{$import.PackageName}} "{{$import.PackagePath}}" |
| 57 {{end}} | 54 {{end}} |
| 58 ) | 55 ) |
| 59 | 56 |
| 60 {{- range $struct := $fileTmpl.Structs}} | 57 {{- range $struct := $fileTmpl.Structs}} |
| 61 » {{ template "StructDecl" $struct }} | 58 » {{ template "Struct" $struct }} |
| 59 {{- end}} |
| 62 | 60 |
| 63 » {{ template "StructEncodingTmpl" $struct }} | 61 {{- range $union := $fileTmpl.Unions}} |
| 64 | 62 » {{ template "Union" $union }} |
| 65 » {{ template "StructVersions" $struct }} | |
| 66 | |
| 67 » {{ template "StructDecodingTmpl" $struct }} | |
| 68 {{- end}} | 63 {{- end}} |
| 69 {{- end -}} | 64 {{- end -}} |
| 70 ` | 65 ` |
| OLD | NEW |