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
|
// process. We do this when we need the functionality
|
||||||
// of another process accessable to a running Go process.
|
// of another process accessable to a running Go process.
|
||||||
// In other cases we may just want to completely replace
|
// In other cases we may just want to completely replace
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
})();
|
})();
|
||||||
</script>
|
</script>
|
||||||
<body>
|
<body>
|
||||||
<div class="chapter" id="{{.Id}}">
|
<div class="example" id="{{.Id}}">
|
||||||
<h2><a href="./">Go by Example</a>: {{.Name}}</h2>
|
<h2><a href="./">Go by Example</a>: {{.Name}}</h2>
|
||||||
{{range .Segs}}
|
{{range .Segs}}
|
||||||
<table cellspacing="0" cellpadding="0">
|
<table cellspacing="0" cellpadding="0">
|
||||||
@ -34,9 +34,9 @@
|
|||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
{{end}}
|
{{end}}
|
||||||
{{if .NextChapter}}
|
{{if .NextExample}}
|
||||||
<p class="next">
|
<p class="next">
|
||||||
Next example: <a href="{{.NextChapter.Id}}">{{.NextChapter.Name}}</a>.
|
Next example: <a href="{{.NextExample.Id}}">{{.NextExample.Name}}</a>.
|
||||||
</p>
|
</p>
|
||||||
{{end}}
|
{{end}}
|
||||||
<p class="footer">
|
<p class="footer">
|
@ -30,3 +30,33 @@
|
|||||||
</div>
|
</div>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</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 {
|
h2 a {
|
||||||
text-decoration: none;
|
text-decoration: none;
|
||||||
}
|
}
|
||||||
div.chapter {
|
div.example {
|
||||||
width: 900px;
|
width: 900px;
|
||||||
min-width: 900px;
|
min-width: 900px;
|
||||||
max-width: 900px;
|
max-width: 900px;
|
||||||
@ -71,7 +71,7 @@ div.chapter {
|
|||||||
margin-right: auto;
|
margin-right: auto;
|
||||||
margin-bottom: 120px;
|
margin-bottom: 120px;
|
||||||
}
|
}
|
||||||
div.chapter table {
|
div.example table {
|
||||||
margin-top: 15px;
|
margin-top: 15px;
|
||||||
margin-bottom: 20px;
|
margin-bottom: 20px;
|
||||||
}
|
}
|
||||||
|
@ -123,10 +123,10 @@ type Seg struct {
|
|||||||
CodeEmpty, CodeLeading bool
|
CodeEmpty, CodeLeading bool
|
||||||
}
|
}
|
||||||
|
|
||||||
type Chapter struct {
|
type Example struct {
|
||||||
Id, Name string
|
Id, Name string
|
||||||
Segs [][]*Seg
|
Segs [][]*Seg
|
||||||
NextChapter *Chapter
|
NextExample *Example
|
||||||
}
|
}
|
||||||
|
|
||||||
func parseSegs(sourcePath string) []*Seg {
|
func parseSegs(sourcePath string) []*Seg {
|
||||||
@ -190,50 +190,50 @@ func parseAndRenderSegs(sourcePath string) []*Seg {
|
|||||||
return segs
|
return segs
|
||||||
}
|
}
|
||||||
|
|
||||||
func parseChapters() []*Chapter {
|
func parseExamples() []*Example {
|
||||||
chapterNames := readLines("meta/chapters.txt")
|
exampleNames := readLines("examples.txt")
|
||||||
chapters := make([]*Chapter, 0)
|
examples := make([]*Example, 0)
|
||||||
for _, chapterName := range chapterNames {
|
for _, exampleName := range exampleNames {
|
||||||
if (chapterName != "") && !strings.HasPrefix(chapterName, "#") {
|
if (exampleName != "") && !strings.HasPrefix(exampleName, "#") {
|
||||||
chapter := Chapter{Name: chapterName}
|
example := Example{Name: exampleName}
|
||||||
chapterId := strings.ToLower(chapterName)
|
exampleId := strings.ToLower(exampleName)
|
||||||
chapterId = strings.Replace(chapterId, " ", "-", -1)
|
exampleId = strings.Replace(exampleId, " ", "-", -1)
|
||||||
chapterId = strings.Replace(chapterId, "/", "-", -1)
|
exampleId = strings.Replace(exampleId, "/", "-", -1)
|
||||||
chapter.Id = chapterId
|
example.Id = exampleId
|
||||||
chapter.Segs = make([][]*Seg, 0)
|
example.Segs = make([][]*Seg, 0)
|
||||||
sourcePaths := mustGlob("src/" + chapterId + "/*")
|
sourcePaths := mustGlob("src/" + exampleId + "/*")
|
||||||
for _, sourcePath := range sourcePaths {
|
for _, sourcePath := range sourcePaths {
|
||||||
sourceSegs := parseAndRenderSegs(sourcePath)
|
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 {
|
for i, example := range examples {
|
||||||
if i < (len(chapters) - 1) {
|
if i < (len(examples) - 1) {
|
||||||
chapter.NextChapter = chapters[i+1]
|
example.NextExample = examples[i+1]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return chapters
|
return examples
|
||||||
}
|
}
|
||||||
|
|
||||||
func renderIndex(chapters []*Chapter) {
|
func renderIndex(examples []*Example) {
|
||||||
indexTmpl := template.New("index")
|
indexTmpl := template.New("index")
|
||||||
_, err := indexTmpl.Parse(mustReadFile("template/index.tmpl"))
|
_, err := indexTmpl.Parse(mustReadFile("template/index.tmpl"))
|
||||||
check(err)
|
check(err)
|
||||||
indexF, err := os.Create(siteDir + "/index.html")
|
indexF, err := os.Create(siteDir + "/index.html")
|
||||||
check(err)
|
check(err)
|
||||||
indexTmpl.Execute(indexF, chapters)
|
indexTmpl.Execute(indexF, examples)
|
||||||
}
|
}
|
||||||
|
|
||||||
func renderChapters(chapters []*Chapter) {
|
func renderExamples(examples []*Example) {
|
||||||
chapterTmpl := template.New("chapter")
|
exampleTmpl := template.New("example")
|
||||||
_, err := chapterTmpl.Parse(mustReadFile("template/chapter.tmpl"))
|
_, err := exampleTmpl.Parse(mustReadFile("template/example.tmpl"))
|
||||||
check(err)
|
check(err)
|
||||||
for _, chapter := range chapters {
|
for _, example := range examples {
|
||||||
chapterF, err := os.Create(siteDir + "/" + chapter.Id)
|
exampleF, err := os.Create(siteDir + "/" + example.Id)
|
||||||
check(err)
|
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/site.css", siteDir+"/site.css")
|
||||||
copyFile("template/favicon.ico", siteDir+"/favicon.ico")
|
copyFile("template/favicon.ico", siteDir+"/favicon.ico")
|
||||||
copyFile("template/404.html", siteDir+"/404.html")
|
copyFile("template/404.html", siteDir+"/404.html")
|
||||||
chapters := parseChapters()
|
examples := parseExamples()
|
||||||
renderIndex(chapters)
|
renderIndex(examples)
|
||||||
renderChapters(chapters)
|
renderExamples(examples)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user