示例#1
0
文件: site.go 项目: hoffoo/stayke.net
func readAll(file string) *bytes.Buffer {

	cwd, err := os.Getwd()
	M.PANIC_ON_ERR(err)

	f, err := os.Open(fmt.Sprintf("%s/%s", path.Join(cwd, "templates"), file))
	M.PANIC_ON_ERR(err)
	defer f.Close()

	content, err := ioutil.ReadAll(f)
	return bytes.NewBuffer(content)
}
示例#2
0
文件: site.go 项目: hoffoo/stayke.net
func getPage(name string) (page *Page) {
	cwd, err := os.Getwd()
	M.PANIC_ON_ERR(err)

	f, err := os.Open(fmt.Sprintf("%s/%s.html", path.Join(cwd, "templates"), name))
	M.PANIC_ON_ERR(err)
	defer f.Close()

	content, err := ioutil.ReadAll(f)
	M.PANIC_ON_ERR(err)

	return &Page{
		Content: string(content),
	}
}
示例#3
0
文件: site.go 项目: hoffoo/stayke.net
func packTemplate(tplPack *template.Template, name string) (tpl *template.Template) {

	cwd, err := os.Getwd()
	M.PANIC_ON_ERR(err)

	f, err := os.Open(fmt.Sprintf("%s/%s.html", path.Join(cwd, "templates"), name))
	M.PANIC_ON_ERR(err)
	defer f.Close()

	html, err := ioutil.ReadAll(f)
	M.PANIC_ON_ERR(err)

	tpl, err = tplPack.Parse(string(html))
	M.PANIC_ON_ERR(err)

	return
}