This repository has been archived by the owner on Mar 18, 2019. It is now read-only.
/
generate_talk.go
84 lines (69 loc) · 1.62 KB
/
generate_talk.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
package main
import (
"flag"
"fmt"
"io"
"os"
"path"
"path/filepath"
"strings"
"template"
)
type TemplateData struct {
Name string
}
func CopyDir(dst, src string) {
filepath.Walk(src, func (path string, info *os.FileInfo, err os.Error) (os.Error) {
file := strings.Replace(path, src, dst, -1)
if info.IsDirectory() {
os.MkdirAll(file, 0755)
} else {
srcFile, errSrc := os.Open(path)
defer srcFile.Close()
if errSrc != nil {
return errSrc
}
dstFile, errDst := os.Create(file)
defer dstFile.Close()
if errDst != nil {
return errDst
}
io.Copy(dstFile, srcFile)
}
return nil
})
}
func GeneratePresentation(name, theme string) {
if dir, err := os.Getwd(); err == nil {
out := path.Join(dir, "out", name)
tDir := path.Join(dir, "themes", theme)
CopyDir(out, path.Join(dir, "resources"))
CopyDir(path.Join(out, "theme"), tDir)
templates := map[string] string{
"cfg.tpl": fmt.Sprintf("%s.cfg", name),
"fabfile.py.tpl": "fabfile.py",
"rst.tpl": fmt.Sprintf("%s.rst", name),
}
data := &TemplateData{name}
templatesDir := path.Join(dir, "templates")
for k, v := range templates {
t, err := template.ParseFile(path.Join(templatesDir, k))
if err != nil {
panic(err)
}
dstFile, _ := os.Create(path.Join(out, v))
defer dstFile.Close()
t.Execute(dstFile, data)
}
}
}
func main() {
name := flag.String("name", "", "The presentation name (required)")
theme := flag.String("theme", "default", "The theme to be used (available in the themes directory)")
flag.Parse()
if *name == "" {
flag.Usage()
} else {
GeneratePresentation(*name, *theme)
}
}