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">
|
<div id="tildelog">
|
||||||
{{range .}}
|
{{range .}}
|
||||||
<hr />
|
<hr />
|
||||||
@ -5,3 +6,4 @@
|
|||||||
<p>{{printf "%s" .Body}}</p>
|
<p>{{printf "%s" .Body}}</p>
|
||||||
{{end}}
|
{{end}}
|
||||||
</div>
|
</div>
|
||||||
|
{{end}}
|
||||||
|
@ -9,6 +9,7 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"bufio"
|
"bufio"
|
||||||
"regexp"
|
"regexp"
|
||||||
|
"flag"
|
||||||
)
|
)
|
||||||
|
|
||||||
const entriesPath = "./entries/"
|
const entriesPath = "./entries/"
|
||||||
@ -48,6 +49,10 @@ func main() {
|
|||||||
fmt.Println(" ~log generator v1.0")
|
fmt.Println(" ~log generator v1.0")
|
||||||
fmt.Println()
|
fmt.Println()
|
||||||
|
|
||||||
|
// Get any arguments
|
||||||
|
templateFilePtr := flag.String("template", "log", "Tildelog template file (defined name).")
|
||||||
|
flag.Parse()
|
||||||
|
|
||||||
entryFiles := getEntries()
|
entryFiles := getEntries()
|
||||||
entries := make([]Entry, len(*entryFiles))
|
entries := make([]Entry, len(*entryFiles))
|
||||||
i := 0
|
i := 0
|
||||||
@ -62,7 +67,9 @@ func main() {
|
|||||||
i++
|
i++
|
||||||
}
|
}
|
||||||
|
|
||||||
generateLog(entries)
|
fmt.Printf("Using template %s\n", *templateFilePtr)
|
||||||
|
|
||||||
|
generateLog(entries, *templateFilePtr)
|
||||||
}
|
}
|
||||||
|
|
||||||
var validFileFormat = regexp.MustCompile("^[0-9]{8}$")
|
var validFileFormat = regexp.MustCompile("^[0-9]{8}$")
|
||||||
@ -83,7 +90,7 @@ func getEntries() *[]string {
|
|||||||
return &fileList
|
return &fileList
|
||||||
}
|
}
|
||||||
|
|
||||||
func generateLog(entries []Entry) {
|
func generateLog(entries []Entry, templateFile string) {
|
||||||
file, err := os.Create(outputPath + "log.html")
|
file, err := os.Create(outputPath + "log.html")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
@ -92,11 +99,11 @@ func generateLog(entries []Entry) {
|
|||||||
defer file.Close()
|
defer file.Close()
|
||||||
|
|
||||||
writer := bufio.NewWriter(file)
|
writer := bufio.NewWriter(file)
|
||||||
template, err := template.ParseFiles(templatesPath + "log.html")
|
template, err := template.ParseGlob(templatesPath + "*.html")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
template.Execute(writer, entries)
|
template.ExecuteTemplate(writer, templateFile, entries)
|
||||||
writer.Flush()
|
writer.Flush()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user