mirror of
https://github.com/golang/go
synced 2024-11-18 08:54:45 -07:00
go.tools/present: add Raw content to Code for new go-tour.
R=adg CC=golang-dev https://golang.org/cl/26390044
This commit is contained in:
parent
8880e2e9d7
commit
6cb29d8d47
@ -32,6 +32,7 @@ type Code struct {
|
||||
Text template.HTML
|
||||
Play bool // runnable code
|
||||
Ext string // file extension
|
||||
Raw []byte // content of the file
|
||||
}
|
||||
|
||||
func (c Code) TemplateName() string { return "code" }
|
||||
@ -130,6 +131,7 @@ func parseCode(ctx *Context, sourceFile string, sourceLine int, cmd string) (Ele
|
||||
Text: template.HTML(buf.String()),
|
||||
Play: play,
|
||||
Ext: filepath.Ext(filename),
|
||||
Raw: textBytes,
|
||||
}, nil
|
||||
}
|
||||
|
||||
|
@ -41,6 +41,16 @@ func (d *Doc) Render(w io.Writer, t *template.Template) error {
|
||||
return t.ExecuteTemplate(w, "root", data)
|
||||
}
|
||||
|
||||
// Render renders the section to the given writer using the provided template.
|
||||
func (s *Section) Render(w io.Writer, t *template.Template) error {
|
||||
data := struct {
|
||||
*Section
|
||||
Template *template.Template
|
||||
PlayEnabled bool
|
||||
}{s, t, PlayEnabled}
|
||||
return t.ExecuteTemplate(w, "section", data)
|
||||
}
|
||||
|
||||
type ParseFunc func(ctx *Context, fileName string, lineNumber int, inputLine string) (Elem, error)
|
||||
|
||||
// Register binds the named action, which does not begin with a period, to the
|
||||
|
Loading…
Reference in New Issue
Block a user