Template system refined

master
KatolaZ 8 years ago
parent 8be60b1580
commit 7bf14a95b4
  1. 25
      html/header.html
  2. 42
      html/index.html
  3. 14
      html/templ.html
  4. 24
      templ.go

@ -2,8 +2,29 @@
<head> <head>
<title>binit</title> <title>binit</title>
<style type="text/css"> <style type="text/css">
pre {margin-left: 50px; border-left: solid 3px #0000ff; padding: div.title {border-bottom: 2px solid #444444; border-left: 4px
5px;} solid #444444; margin: 3px; padding-left: 5px;}
div.raw_title {border-top: 2px solid #444444; border-left: 4px
solid #444444; margin: 3px; padding-left: 5px;}
div.date {border-bottom: 2px solid #444444; border-left: 4px
solid #444444; margin: 3px; padding-left: 5px; }
div.content {margin-left: 30px; border: solid 3px #444444; padding:
5px; width: 90%;}
textarea.raw_content {margin-left: 30px; border: solid 3px
#999999; width: 91%; height: 200px; padding: 5px;}
table, tr, td {border: 0px; margin: 0px; padding: 0px; border-collapse:
collapse; }
td.lineno {background-color: #cccccc; text-align: right;
vertical-align: middle; padding-right: 3px;}
td.line {margin-left: 5px; padding-left: 5px; border-left: solid
3px #666666;}
</style> </style>
</head> </head>

@ -1,17 +1,49 @@
<html> <html>
<head>
<style type="text/css">
body {
margin-left: 5%;
line-height:1.6;
font-size:20px;
}
h1 {
background-color: #cccccc;
padding-left: 10px;
border-bottom: solid 5px #444444;
border-left: solid 5px #222222;
}
div.title {
border-top: 2px solid #444444;
border-left: 4px solid #444444;
margin: 3px;
padding-left: 5px;
}
input.button {
padding: 5px;
line-height: 1.6;
font-size: 20px;
}
</style>
</head>
<body> <body>
<h1>Index.html</h1> <h1>Binnit</h1>
<form method="POST"> <form method="POST">
Title: <input type="text" name="title" size="24"/> <div class="title">
<br /> Title:
<input type="text" name="title" size="24"/>
</div>
<div class="title">
Paste: Paste:
<br /> <br />
<textarea name="paste" cols="80" rows="10"></textarea> <textarea name="paste" cols="100" rows="15"></textarea>
<br /> <br />
<input type="checkbox" name="show" value="1" checked />Show link <input type="checkbox" name="show" value="1" checked />Show link
<br /> <br />
<input type="submit" value="Binit!"> </div>
<input type="submit" class="button" value="Binnit!">
</form> </form>
</body> </body>

@ -1,14 +1,20 @@
<body> <body>
<div> <div class="title">
Title: {{TITLE}} Title: {{TITLE}}
</div> </div>
<div> <div class="date">
Date: {{DATE}} Date: {{DATE}}
</div> </div>
<pre> <div class="content">
{{CONTENT}} {{CONTENT}}
</pre> </div>
<div class="raw_content">
<div class="raw_title">Raw paste: </div>
<textarea class="raw_content"><pre>{{RAW_CONTENT}}</pre></textarea>
</div>
</body> </body>

@ -34,8 +34,29 @@ import (
"io/ioutil" "io/ioutil"
"os" "os"
"regexp" "regexp"
"strings"
"strconv"
) )
func format_rows(content string) (string) {
var ret string
lines := strings.Split(content, "\n")
ret += "<table class='content'>"
for l_num, l := range lines {
ret += "<tr>\n"
ret += "<td class='lineno'><pre>"+ strconv.Itoa(l_num+1) + "</pre></td>"
ret += "<td class='line'><pre>"+ l +"</pre></td>"
ret += "</tr>"
}
ret += "</table>"
return ret
}
func prepare_paste_page(title, date, content, templ_dir string) (string, error) { func prepare_paste_page(title, date, content, templ_dir string) (string, error) {
s := "" s := ""
@ -72,6 +93,9 @@ func prepare_paste_page(title, date, content, templ_dir string) (string, error)
tmpl = string(re.ReplaceAll([]byte(tmpl), []byte(date))) tmpl = string(re.ReplaceAll([]byte(tmpl), []byte(date)))
re, _ = regexp.Compile("{{CONTENT}}") re, _ = regexp.Compile("{{CONTENT}}")
tmpl = string(re.ReplaceAll([]byte(tmpl), []byte(format_rows(content))))
re, _ = regexp.Compile("{{RAW_CONTENT}}")
tmpl = string(re.ReplaceAll([]byte(tmpl), []byte(content))) tmpl = string(re.ReplaceAll([]byte(tmpl), []byte(content)))
s += tmpl s += tmpl

Loading…
Cancel
Save