show individual quotes
This commit is contained in:
parent
cf933531b1
commit
23c80f907c
|
@ -1,10 +1,11 @@
|
||||||
import asyncdispatch, db_sqlite, jester, moustachu, os,
|
import asyncdispatch, db_sqlite, jester, moustachu, os,
|
||||||
shorturl, strutils, tables, times
|
shorturl, strutils, tables, times, typetraits
|
||||||
|
|
||||||
const
|
const
|
||||||
baseTemplate*: string = staticRead "./templates/layout.mustache"
|
baseTemplate*: string = staticRead "./templates/layout.mustache"
|
||||||
indexTemplate*: string = staticRead "./templates/index.mustache"
|
indexTemplate*: string = staticRead "./templates/index.mustache"
|
||||||
errorTemplate*: string = staticRead "./templates/error.mustache"
|
errorTemplate*: string = staticRead "./templates/error.mustache"
|
||||||
|
quoteTemplate*: string = staticRead "./templates/quote.mustache"
|
||||||
|
|
||||||
testTemplate*: string = """<p>hi!</p>"""
|
testTemplate*: string = """<p>hi!</p>"""
|
||||||
|
|
||||||
|
@ -37,7 +38,14 @@ template renderMustache*(title: string, templ: string, ctx: Context): expr =
|
||||||
template fail*(): expr =
|
template fail*(): expr =
|
||||||
var ctx = newContext()
|
var ctx = newContext()
|
||||||
ctx["exception"] = getCurrentExceptionMsg()
|
ctx["exception"] = getCurrentExceptionMsg()
|
||||||
renderMustache("error", errorTemplate, ctx)
|
|
||||||
|
var
|
||||||
|
layoutCtx = moustachu.newContext()
|
||||||
|
|
||||||
|
layoutCtx["title"] = title
|
||||||
|
layoutCtx["body"] = render(templ, ctx)
|
||||||
|
|
||||||
|
halt render(baseTemplate, layoutCtx)
|
||||||
|
|
||||||
settings:
|
settings:
|
||||||
port = 5000.Port
|
port = 5000.Port
|
||||||
|
@ -57,6 +65,7 @@ routes:
|
||||||
for quote in items(quotes):
|
for quote in items(quotes):
|
||||||
var c = newContext()
|
var c = newContext()
|
||||||
|
|
||||||
|
c["listid"] = quote[0]
|
||||||
c["id"] = quote[0].parseInt().encodeURLSimple()
|
c["id"] = quote[0].parseInt().encodeURLSimple()
|
||||||
c["channel"] = quote[1]
|
c["channel"] = quote[1]
|
||||||
c["channelsafe"] = quote[1].replace("#", "hashtag-")
|
c["channelsafe"] = quote[1].replace("#", "hashtag-")
|
||||||
|
@ -72,16 +81,34 @@ routes:
|
||||||
renderMustache("most recent quotes", indexTemplate, ctx)
|
renderMustache("most recent quotes", indexTemplate, ctx)
|
||||||
|
|
||||||
get "/quotes/@id":
|
get "/quotes/@id":
|
||||||
var qid: int = -1
|
var qid: int = 0
|
||||||
|
|
||||||
try:
|
try:
|
||||||
qid = (@"id").decodeURLSimple()
|
qid = (@"id").parseInt
|
||||||
except:
|
except:
|
||||||
fail()
|
qid = (@"id").decodeURLSimple()
|
||||||
|
redirect "/quotes/" & $qid
|
||||||
|
|
||||||
let quote = db.getRow(sql"SELECT * FROM quotes WHERE id = ?", qid)
|
let quote = db.getRow(sql"SELECT * FROM quotes WHERE id = ?", qid)
|
||||||
|
|
||||||
echo quote
|
if quote[1] == "":
|
||||||
|
halt Http404, "no such quote"
|
||||||
|
|
||||||
resp $quote
|
var
|
||||||
|
ctx = newContext()
|
||||||
|
|
||||||
|
ctx["listid"] = qid
|
||||||
|
ctx["id"] = quote[0].parseInt().encodeURLSimple()
|
||||||
|
ctx["channel"] = quote[1]
|
||||||
|
ctx["channelsafe"] = quote[1].replace("#", "hashtag-")
|
||||||
|
ctx["nick"] = quote[2]
|
||||||
|
ctx["adder"] = quote[3]
|
||||||
|
ctx["message"] = quote[4]
|
||||||
|
ctx["time"] = parseInt(split(quote[5], '.')[0])
|
||||||
|
|
||||||
|
ctx["last"] = qid - 1
|
||||||
|
ctx["next"] = qid + 1
|
||||||
|
|
||||||
|
renderMustache("quote #" & $qid & " by " & quote[2], quoteTemplate, ctx)
|
||||||
|
|
||||||
runForever()
|
runForever()
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{{# quotes }}
|
{{# quotes }}
|
||||||
<div class="entries">
|
<div class="entries">
|
||||||
<h3><a href="/channel/{{ channelsafe }}">{{channel}}</a> - {{time}}</h3>
|
<h3><a href="/channel/{{ channelsafe }}">{{channel}}</a> - #{{listid}} - {{time}}</h3>
|
||||||
<p>({{nick}}) {{message}}</p>
|
<p>({{nick}}) {{message}}</p>
|
||||||
<small><i>Added by {{adder}}. <a href="/quotes/{{id}}">Permalink.</a></i></small>
|
<small><i>Added by {{adder}}. <a href="/quotes/{{id}}">Permalink.</a></i></small>
|
||||||
<br />
|
<br />
|
||||||
|
|
|
@ -0,0 +1,12 @@
|
||||||
|
<div class="entries">
|
||||||
|
<h3><a href="/channel/{{ channelsafe }}">{{channel}}</a> - #{{ listid }} - {{time}}</h3>
|
||||||
|
<p>({{nick}}) {{message}}</p>
|
||||||
|
<small><i>Added by {{adder}}. <a href="/quotes/{{id}}">Permalink.</a></i></small>
|
||||||
|
<br />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<br />
|
||||||
|
|
||||||
|
<center>
|
||||||
|
<p><a href="/quotes/{{ last }}">prev</a> this <a href="/quotes/{{ next }}">next</p>
|
||||||
|
</center>
|
Loading…
Reference in New Issue