Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(357)

Unified Diff: pkg/present/code.go

Issue 7312072: code review 7312072: go.talks/pkg/present: replace direct file system access...
Patch Set: diff -r 2e320f363bb2 https://code.google.com/p/go.talks Created 12 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | pkg/present/html.go » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/present/code.go
===================================================================
--- a/pkg/present/code.go
+++ b/pkg/present/code.go
@@ -7,7 +7,6 @@
import (
"fmt"
"html/template"
- "io/ioutil"
"log"
"path/filepath"
"regexp"
@@ -42,7 +41,7 @@
var highlightRE = regexp.MustCompile(`\s+HL([a-zA-Z0-9_]+)?$`)
var codeRE = regexp.MustCompile(`\.(code|play)\s+([^\s]+)(\s+)?(.*)?$`)
-func parseCode(sourceFile string, sourceLine int, cmd string) (Elem, error) {
+func parseCode(ctx *Context, sourceFile string, sourceLine int, cmd string) (Elem, error) {
cmd = strings.TrimSpace(cmd)
// Pull off the HL, if any, from the end of the input line.
@@ -68,7 +67,7 @@
// Read in code file and (optionally) match address.
filename := filepath.Join(filepath.Dir(sourceFile), file)
- textBytes, err := ioutil.ReadFile(filename)
+ textBytes, err := ctx.ReadFile(filename)
if err != nil {
return nil, fmt.Errorf("%s:%d: %v", sourceFile, sourceLine, err)
}
@@ -168,8 +167,8 @@
}
// oneLine returns the single line generated by a two-argument code invocation.
-func oneLine(file, text string, arg interface{}) (line, before, after string, err error) {
- contentBytes, err := ioutil.ReadFile(file)
+func oneLine(ctx *Context, file, text string, arg interface{}) (line, before, after string, err error) {
+ contentBytes, err := ctx.ReadFile(file)
if err != nil {
return "", "", "", err
}
@@ -192,8 +191,8 @@
}
// multipleLines returns the text generated by a three-argument code invocation.
-func multipleLines(file string, arg1, arg2 interface{}) (line, before, after string, err error) {
- contentBytes, err := ioutil.ReadFile(file)
+func multipleLines(ctx *Context, file string, arg1, arg2 interface{}) (line, before, after string, err error) {
+ contentBytes, err := ctx.ReadFile(file)
lines := strings.SplitAfter(string(contentBytes), "\n")
if err != nil {
return "", "", "", err
« no previous file with comments | « no previous file | pkg/present/html.go » ('j') | no next file with comments »

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b