aboutsummaryrefslogtreecommitdiff
path: root/present
diff options
context:
space:
mode:
authorFrancesc Campoy <campoy@golang.org>2013-11-26 10:04:08 +0100
committerFrancesc Campoy <campoy@golang.org>2013-11-26 10:04:08 +0100
commit6cb29d8d47f40d5a0266329d5695ad3e2c4c37ab (patch)
tree2aaea296e398c2fcb33b4e3600002c1159d297fa /present
parent8880e2e9d7c91822cf2239609626deca8d9745c0 (diff)
downloadgolang-x-tools-6cb29d8d47f40d5a0266329d5695ad3e2c4c37ab.tar.gz
go.tools/present: add Raw content to Code for new go-tour.
R=adg CC=golang-dev https://golang.org/cl/26390044
Diffstat (limited to 'present')
-rw-r--r--present/code.go2
-rw-r--r--present/parse.go10
2 files changed, 12 insertions, 0 deletions
diff --git a/present/code.go b/present/code.go
index 6fd9dade2..de1554310 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 a78a85b6a..449d5ed5c 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