From 7f0ad904fd005c5fdd32ff6c6ae708084456b0e7 Mon Sep 17 00:00:00 2001 From: Mark McGranaghan Date: Tue, 9 Oct 2012 08:27:30 -0700 Subject: [PATCH] working generate --- tool/generate.go | 78 +++++++++++++++++++++++++----------------------- 1 file changed, 41 insertions(+), 37 deletions(-) diff --git a/tool/generate.go b/tool/generate.go index 9b76fbb..b102b14 100644 --- a/tool/generate.go +++ b/tool/generate.go @@ -209,44 +209,48 @@ func generateIndex() { fmt.Fprint(indexF, ``) } +func generateChapters() { + chapterIds := readLines("meta/contents.txt") + for _, chapterId := range chapterIds { + chapterLines := readLines("src/" + chapterId + "/" + chapterId + ".go") + chapterName := chapterLines[0][6:] + chapterPath := "src/" + chapterId + sourcePaths := mustGlob(chapterPath + "/*") + chapterF, err := os.Create(siteDir + "/" + chapterId + ".html") + check(err) + fmt.Fprintf(chapterF, + ` + + + + Go by Example: %s + + + +
+ `, + chapterName, chapterId) + for _, sourcePath := range sourcePaths { + segs := parseAndRenderSegs(sourcePath) + for _, seg := range segs { + codeClasses := "code" + if seg.code == "" { + codeClasses = codeClasses + " empty" + } + fmt.Fprintf(chapterF, + ` + + + `, + seg.docsRendered, codeClasses, seg.codeRendered) + } + } + fmt.Fprint(chapterF, `
%s%s
`) + } +} + func main() { ensureDir(siteDir) generateIndex() + generateChapters() } - -// -// // Content chapters -// for _, chapterId := range chapterIds { -// fmt.Fprintf(outF, `
`, chapterId) -// if chapterId == "introduction" { -// fmt.Fprint(outF, markdown(mustReadFile("src/introduction.md"))) -// } else { -// chapterPath := "src/" + chapterId -// fmt.Fprintf(outF, -// ``, -// chapterPath) -// sourcePaths := mustGlob(chapterPath + "/*") -// for _, sourcePath := range sourcePaths { -// if strings.HasSuffix(sourcePath, ".go") || strings.HasSuffix(sourcePath, ".sh") { -// segs := parseAndRenderSegs(sourcePath) -// for _, seg := range segs { -// codeClasses := "code" -// if seg.code == "" { -// codeClasses = codeClasses + " empty" -// } -// fmt.Fprintf(outF, -// ` -// -// -// `, -// seg.docsRendered, codeClasses, seg.codeRendered) -// } -// } -// } -// fmt.Fprint(outF, `
%s%s
`) -// } -// fmt.Fprintf(outF, `
`) -// } -// -// // Footer -// fmt.Fprint(outF, ``)