1
0
mirror of https://github.com/golang/go synced 2024-11-21 15:14:43 -07:00

tmpltohtml: put a DO NOT EDIT mark automatically in the output

R=r, rsc, r
CC=golang-dev
https://golang.org/cl/5469045
This commit is contained in:
Rob Pike 2011-12-08 11:26:49 -08:00
parent 0397b28a90
commit 1ddedbae31
5 changed files with 25 additions and 1 deletions

View File

@ -1,4 +1,9 @@
<!-- Effective Go -->
<!--
DO NOT EDIT: created by
tmpltohtml effective_go.tmpl
-->
<h2 id="introduction">Introduction</h2>

View File

@ -1,4 +1,5 @@
<!-- Effective Go -->
{{donotedit}}
<h2 id="introduction">Introduction</h2>

View File

@ -1,4 +1,10 @@
<!-- A Tutorial for the Go Programming Language -->
<!--
DO NOT EDIT: created by
tmpltohtml go_tutorial.tmpl
-->
<h2>Introduction</h2>
<p>
This document is a tutorial introduction to the basics of the Go programming

View File

@ -1,4 +1,6 @@
<!-- A Tutorial for the Go Programming Language -->
{{donotedit}}
<h2>Introduction</h2>
<p>
This document is a tutorial introduction to the basics of the Go programming

View File

@ -35,6 +35,11 @@ func Usage() {
os.Exit(2)
}
var templateFuncs = template.FuncMap{
"code": code,
"donotedit": donotedit,
}
func main() {
flag.Usage = Usage
flag.Parse()
@ -44,7 +49,7 @@ func main() {
// Read and parse the input.
name := flag.Args()[0]
tmpl := template.New(name).Funcs(template.FuncMap{"code": code})
tmpl := template.New(name).Funcs(templateFuncs)
if _, err := tmpl.ParseFiles(name); err != nil {
log.Fatal(err)
}
@ -80,6 +85,11 @@ func format(arg interface{}) string {
return ""
}
func donotedit() string {
// No editing please.
return fmt.Sprintf("<!--\n DO NOT EDIT: created by\n tmpltohtml %s\n-->\n", flag.Args()[0])
}
func code(file string, arg ...interface{}) (string, error) {
text := contents(file)
var command string