mirror of
https://github.com/thebaer/tildes.git
synced 2018-07-20 07:15:21 +00:00
Ability to specify template
For example, for an entire page which include the log inside it.
This commit is contained in:
parent
7916ac832f
commit
b4c8dee526
@ -1,3 +1,4 @@
|
||||
{{define "log"}}
|
||||
<div id="tildelog">
|
||||
{{range .}}
|
||||
<hr />
|
||||
@ -5,3 +6,4 @@
|
||||
<p>{{printf "%s" .Body}}</p>
|
||||
{{end}}
|
||||
</div>
|
||||
{{end}}
|
||||
|
@ -9,6 +9,7 @@ import (
|
||||
"os"
|
||||
"bufio"
|
||||
"regexp"
|
||||
"flag"
|
||||
)
|
||||
|
||||
const entriesPath = "./entries/"
|
||||
@ -48,6 +49,10 @@ func main() {
|
||||
fmt.Println(" ~log generator v1.0")
|
||||
fmt.Println()
|
||||
|
||||
// Get any arguments
|
||||
templateFilePtr := flag.String("template", "log", "Tildelog template file (defined name).")
|
||||
flag.Parse()
|
||||
|
||||
entryFiles := getEntries()
|
||||
entries := make([]Entry, len(*entryFiles))
|
||||
i := 0
|
||||
@ -62,7 +67,9 @@ func main() {
|
||||
i++
|
||||
}
|
||||
|
||||
generateLog(entries)
|
||||
fmt.Printf("Using template %s\n", *templateFilePtr)
|
||||
|
||||
generateLog(entries, *templateFilePtr)
|
||||
}
|
||||
|
||||
var validFileFormat = regexp.MustCompile("^[0-9]{8}$")
|
||||
@ -83,7 +90,7 @@ func getEntries() *[]string {
|
||||
return &fileList
|
||||
}
|
||||
|
||||
func generateLog(entries []Entry) {
|
||||
func generateLog(entries []Entry, templateFile string) {
|
||||
file, err := os.Create(outputPath + "log.html")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
@ -92,11 +99,11 @@ func generateLog(entries []Entry) {
|
||||
defer file.Close()
|
||||
|
||||
writer := bufio.NewWriter(file)
|
||||
template, err := template.ParseFiles(templatesPath + "log.html")
|
||||
template, err := template.ParseGlob(templatesPath + "*.html")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
template.Execute(writer, entries)
|
||||
template.ExecuteTemplate(writer, templateFile, entries)
|
||||
writer.Flush()
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user