From 6cb29d8d47f40d5a0266329d5695ad3e2c4c37ab Mon Sep 17 00:00:00 2001 From: Francesc Campoy Date: Tue, 26 Nov 2013 10:04:08 +0100 Subject: [PATCH] go.tools/present: add Raw content to Code for new go-tour. R=adg CC=golang-dev https://golang.org/cl/26390044 --- present/code.go | 2 ++ present/parse.go | 10 ++++++++++ 2 files changed, 12 insertions(+) diff --git a/present/code.go b/present/code.go index 6fd9dade26..de15543109 100644 --- a/present/code.go +++ b/present/code.go @@ -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 } diff --git a/present/parse.go b/present/parse.go index a78a85b6ac..449d5ed5c9 100644 --- a/present/parse.go +++ b/present/parse.go @@ -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