"
for l_num, l := range lines {
ret += "\n"
ret += "" + strconv.Itoa(l_num+1) + " | "
ret += "" + l + " | "
ret += "
"
}
ret += "
"
return ret
}
func prepare_paste_page(title, date, content, templ_dir string) (string, error) {
s := ""
// insert header
head_file := templ_dir + "/header.html"
f_head, err := os.Open(head_file)
defer f_head.Close()
if err == nil {
cont, err := ioutil.ReadFile(head_file)
if err == nil {
s += string(cont)
}
}
// insert content
// ...Let's read the template
templ_file := templ_dir + "/templ.html"
f_templ, err := os.Open(templ_file)
defer f_templ.Close()
if cont, err := ioutil.ReadFile(templ_file); err == nil {
tmpl := string(cont)
re, _ := regexp.Compile("{{TITLE}}")
tmpl = string(re.ReplaceAllLiteralString(tmpl, title))
re, _ = regexp.Compile("{{DATE}}")
tmpl = string(re.ReplaceAllLiteralString(tmpl, date))
re, _ = regexp.Compile("{{CONTENT}}")
tmpl = string(re.ReplaceAllLiteralString(tmpl, format_rows(content)))
re, _ = regexp.Compile("{{RAW_CONTENT}}")
tmpl = string(re.ReplaceAllLiteralString(tmpl, content))
s += tmpl
} else {
return "", errors.New("Error opening template file")
}
// insert footer
foot_file := templ_dir + "/footer.html"
f_foot, err := os.Open(foot_file)
defer f_foot.Close()
if err == nil {
cont, err := ioutil.ReadFile(foot_file)
if err == nil {
s += string(cont)
}
}
return s, nil
}