books with chapters lol
This commit is contained in:
parent
e498512b07
commit
e71161efb2
@ -1,28 +0,0 @@
|
||||
## Introduction
|
||||
|
||||
Go is an open-source programming language designed for
|
||||
building simple, fast, and reliable software.
|
||||
It's powerful to use and fun to learn.
|
||||
|
||||
This book is a hands-on introduction to Go. It gives you
|
||||
the tools you need to understand the why of Go and how to
|
||||
write real Go programs.
|
||||
|
||||
### Intended Audience
|
||||
|
||||
This book is intended for experienced programmers who may
|
||||
be new to Go. If you have previous experience with
|
||||
languages like Ruby, Python, Javascript, C#, or Java, you
|
||||
should find this book immediately approachable even if
|
||||
this is your first introduction to Go. Even if you've
|
||||
worked with Go before, you may find that the material
|
||||
covers ideas and techniques that you haven't seen
|
||||
elsewhere.
|
||||
|
||||
### An Example-Based Approach
|
||||
|
||||
Programmers learn to program by writing programs.
|
||||
_Go by Example_ therefore teaches Go exclusively via
|
||||
working example programs, with each chapter trying to
|
||||
provide the programmer a new tool for writing her own
|
||||
programs.
|
@ -1,4 +1,4 @@
|
||||
// In the previous chapter we looked at spawning external
|
||||
// In the previous example we looked at spawning external
|
||||
// process. We do this when we need the functionality
|
||||
// of another process accessable to a running Go process.
|
||||
// In other cases we may just want to completely replace
|
||||
|
@ -16,7 +16,7 @@
|
||||
})();
|
||||
</script>
|
||||
<body>
|
||||
<div class="chapter" id="{{.Id}}">
|
||||
<div class="example" id="{{.Id}}">
|
||||
<h2><a href="./">Go by Example</a>: {{.Name}}</h2>
|
||||
{{range .Segs}}
|
||||
<table cellspacing="0" cellpadding="0">
|
||||
@ -34,9 +34,9 @@
|
||||
</tbody>
|
||||
</table>
|
||||
{{end}}
|
||||
{{if .NextChapter}}
|
||||
{{if .NextExample}}
|
||||
<p class="next">
|
||||
Next example: <a href="{{.NextChapter.Id}}">{{.NextChapter.Name}}</a>.
|
||||
Next example: <a href="{{.NextExample.Id}}">{{.NextExample.Name}}</a>.
|
||||
</p>
|
||||
{{end}}
|
||||
<p class="footer">
|
@ -30,3 +30,33 @@
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
## Introduction
|
||||
|
||||
Go is an open-source programming language designed for
|
||||
building simple, fast, and reliable software.
|
||||
It's powerful to use and fun to learn.
|
||||
|
||||
This book is a hands-on introduction to Go. It gives you
|
||||
the tools you need to understand the why of Go and how to
|
||||
write real Go programs.
|
||||
|
||||
### Intended Audience
|
||||
|
||||
This book is intended for experienced programmers who may
|
||||
be new to Go. If you have previous experience with
|
||||
languages like Ruby, Python, Javascript, C#, or Java, you
|
||||
should find this book immediately approachable even if
|
||||
this is your first introduction to Go. Even if you've
|
||||
worked with Go before, you may find that the material
|
||||
covers ideas and techniques that you haven't seen
|
||||
elsewhere.
|
||||
|
||||
### An Example-Based Approach
|
||||
|
||||
Programmers learn to program by writing programs.
|
||||
_Go by Example_ therefore teaches Go exclusively via
|
||||
working example programs, with each example trying to
|
||||
provide the programmer a new tool for writing her own
|
||||
programs.
|
||||
|
||||
|
@ -63,7 +63,7 @@ h2 {
|
||||
h2 a {
|
||||
text-decoration: none;
|
||||
}
|
||||
div.chapter {
|
||||
div.example {
|
||||
width: 900px;
|
||||
min-width: 900px;
|
||||
max-width: 900px;
|
||||
@ -71,7 +71,7 @@ div.chapter {
|
||||
margin-right: auto;
|
||||
margin-bottom: 120px;
|
||||
}
|
||||
div.chapter table {
|
||||
div.example table {
|
||||
margin-top: 15px;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
@ -123,10 +123,10 @@ type Seg struct {
|
||||
CodeEmpty, CodeLeading bool
|
||||
}
|
||||
|
||||
type Chapter struct {
|
||||
type Example struct {
|
||||
Id, Name string
|
||||
Segs [][]*Seg
|
||||
NextChapter *Chapter
|
||||
NextExample *Example
|
||||
}
|
||||
|
||||
func parseSegs(sourcePath string) []*Seg {
|
||||
@ -190,50 +190,50 @@ func parseAndRenderSegs(sourcePath string) []*Seg {
|
||||
return segs
|
||||
}
|
||||
|
||||
func parseChapters() []*Chapter {
|
||||
chapterNames := readLines("meta/chapters.txt")
|
||||
chapters := make([]*Chapter, 0)
|
||||
for _, chapterName := range chapterNames {
|
||||
if (chapterName != "") && !strings.HasPrefix(chapterName, "#") {
|
||||
chapter := Chapter{Name: chapterName}
|
||||
chapterId := strings.ToLower(chapterName)
|
||||
chapterId = strings.Replace(chapterId, " ", "-", -1)
|
||||
chapterId = strings.Replace(chapterId, "/", "-", -1)
|
||||
chapter.Id = chapterId
|
||||
chapter.Segs = make([][]*Seg, 0)
|
||||
sourcePaths := mustGlob("src/" + chapterId + "/*")
|
||||
func parseExamples() []*Example {
|
||||
exampleNames := readLines("examples.txt")
|
||||
examples := make([]*Example, 0)
|
||||
for _, exampleName := range exampleNames {
|
||||
if (exampleName != "") && !strings.HasPrefix(exampleName, "#") {
|
||||
example := Example{Name: exampleName}
|
||||
exampleId := strings.ToLower(exampleName)
|
||||
exampleId = strings.Replace(exampleId, " ", "-", -1)
|
||||
exampleId = strings.Replace(exampleId, "/", "-", -1)
|
||||
example.Id = exampleId
|
||||
example.Segs = make([][]*Seg, 0)
|
||||
sourcePaths := mustGlob("src/" + exampleId + "/*")
|
||||
for _, sourcePath := range sourcePaths {
|
||||
sourceSegs := parseAndRenderSegs(sourcePath)
|
||||
chapter.Segs = append(chapter.Segs, sourceSegs)
|
||||
example.Segs = append(example.Segs, sourceSegs)
|
||||
}
|
||||
chapters = append(chapters, &chapter)
|
||||
examples = append(examples, &example)
|
||||
}
|
||||
}
|
||||
for i, chapter := range chapters {
|
||||
if i < (len(chapters) - 1) {
|
||||
chapter.NextChapter = chapters[i+1]
|
||||
for i, example := range examples {
|
||||
if i < (len(examples) - 1) {
|
||||
example.NextExample = examples[i+1]
|
||||
}
|
||||
}
|
||||
return chapters
|
||||
return examples
|
||||
}
|
||||
|
||||
func renderIndex(chapters []*Chapter) {
|
||||
func renderIndex(examples []*Example) {
|
||||
indexTmpl := template.New("index")
|
||||
_, err := indexTmpl.Parse(mustReadFile("template/index.tmpl"))
|
||||
check(err)
|
||||
indexF, err := os.Create(siteDir + "/index.html")
|
||||
check(err)
|
||||
indexTmpl.Execute(indexF, chapters)
|
||||
indexTmpl.Execute(indexF, examples)
|
||||
}
|
||||
|
||||
func renderChapters(chapters []*Chapter) {
|
||||
chapterTmpl := template.New("chapter")
|
||||
_, err := chapterTmpl.Parse(mustReadFile("template/chapter.tmpl"))
|
||||
func renderExamples(examples []*Example) {
|
||||
exampleTmpl := template.New("example")
|
||||
_, err := exampleTmpl.Parse(mustReadFile("template/example.tmpl"))
|
||||
check(err)
|
||||
for _, chapter := range chapters {
|
||||
chapterF, err := os.Create(siteDir + "/" + chapter.Id)
|
||||
for _, example := range examples {
|
||||
exampleF, err := os.Create(siteDir + "/" + example.Id)
|
||||
check(err)
|
||||
chapterTmpl.Execute(chapterF, chapter)
|
||||
exampleTmpl.Execute(exampleF, example)
|
||||
}
|
||||
}
|
||||
|
||||
@ -243,7 +243,7 @@ func main() {
|
||||
copyFile("template/site.css", siteDir+"/site.css")
|
||||
copyFile("template/favicon.ico", siteDir+"/favicon.ico")
|
||||
copyFile("template/404.html", siteDir+"/404.html")
|
||||
chapters := parseChapters()
|
||||
renderIndex(chapters)
|
||||
renderChapters(chapters)
|
||||
examples := parseExamples()
|
||||
renderIndex(examples)
|
||||
renderExamples(examples)
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user