From 7bf14a95b4a4adb7f55308532e7d6ffc8305bdc1 Mon Sep 17 00:00:00 2001 From: KatolaZ Date: Mon, 3 Jul 2017 22:40:22 +0100 Subject: Template system refined --- html/header.html | 25 +++++++++++++++++++++++-- html/index.html | 52 ++++++++++++++++++++++++++++++++++++++++++---------- html/templ.html | 16 +++++++++++----- templ.go | 24 ++++++++++++++++++++++++ 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 @@ binit 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 @@ + + + -

Index.html

+

Binnit

- Title: -
- Paste: -
- -
- Show link -
- +
+ Title: + +
+
+ Paste: +
+ +
+ Show link +
+
+ +
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 @@ - -
+ +
Title: {{TITLE}}
-
+
Date: {{DATE}}
-
+
{{CONTENT}} -
+
+ + +
+
Raw paste:
+ +
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 += "" + + for l_num, l := range lines { + ret += "\n" + ret += "" + ret += "" + ret += "" + } + ret += "
"+ strconv.Itoa(l_num+1) + "
"+ l +"
" + 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 -- cgit v1.2.3