summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKatolaZ <katolaz@freaknet.org>2017-07-03 22:40:22 +0100
committerKatolaZ <katolaz@freaknet.org>2017-07-03 22:40:22 +0100
commit7bf14a95b4a4adb7f55308532e7d6ffc8305bdc1 (patch)
treed4b0af6ce08e18d23e3bcdbaf9446657b6854bb7
parent8be60b1580de638d2c9151646cb42b78b5f229ae (diff)
Template system refined
-rw-r--r--html/header.html25
-rw-r--r--html/index.html52
-rw-r--r--html/templ.html16
-rw-r--r--templ.go24
4 files changed, 100 insertions, 17 deletions
diff --git a/html/header.html b/html/header.html
index 0cdb721..16a2f8f 100644
--- a/html/header.html
+++ b/html/header.html
@@ -2,8 +2,29 @@
<head>
<title>binit</title>
<style type="text/css">
- pre {margin-left: 50px; border-left: solid 3px #0000ff; padding:
- 5px;}
+ div.title {border-bottom: 2px solid #444444; border-left: 4px
+ 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>
</head>
diff --git a/html/index.html b/html/index.html
index 12c8236..a428d22 100644
--- a/html/index.html
+++ b/html/index.html
@@ -1,17 +1,49 @@
<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>
- <h1>Index.html</h1>
+ <h1>Binnit</h1>
<form method="POST">
- Title: <input type="text" name="title" size="24"/>
- <br />
- Paste:
- <br />
- <textarea name="paste" cols="80" rows="10"></textarea>
- <br />
- <input type="checkbox" name="show" value="1" checked />Show link
- <br />
- <input type="submit" value="Binit!">
+ <div class="title">
+ Title:
+ <input type="text" name="title" size="24"/>
+ </div>
+ <div class="title">
+ Paste:
+ <br />
+ <textarea name="paste" cols="100" rows="15"></textarea>
+ <br />
+ <input type="checkbox" name="show" value="1" checked />Show link
+ <br />
+ </div>
+ <input type="submit" class="button" value="Binnit!">
+
</form>
</body>
diff --git a/html/templ.html b/html/templ.html
index 8b951d8..7729b23 100644
--- a/html/templ.html
+++ b/html/templ.html
@@ -1,14 +1,20 @@
<body>
-
- <div>
+
+ <div class="title">
Title: {{TITLE}}
</div>
- <div>
+ <div class="date">
Date: {{DATE}}
</div>
-<pre>
+<div class="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>
diff --git a/templ.go b/templ.go
index f12fbd6..8c290fa 100644
--- a/templ.go
+++ b/templ.go
@@ -34,8 +34,29 @@ import (
"io/ioutil"
"os"
"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) {
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)))
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)))
s += tmpl