run command, make template rendering a template
This commit is contained in:
parent
5c02b05882
commit
89201245d7
|
@ -9,5 +9,8 @@ bin = @["quotesite"]
|
|||
|
||||
# Dependencies
|
||||
|
||||
requires "nim >= 0.13.0", "jester", "moustachu"
|
||||
requires "nim >= 0.13.0", "jester", "moustachu", "shorturl"
|
||||
|
||||
task run, "run the site":
|
||||
exec "nimble build"
|
||||
exec "./quotesite"
|
||||
|
|
|
@ -1,7 +1,19 @@
|
|||
import asyncdispatch, jester, moustachu, os, strutils
|
||||
|
||||
const
|
||||
baseTemplate = staticRead "./templates/layout.mustache"
|
||||
baseTemplate*: string = staticRead "./templates/layout.mustache"
|
||||
indexTemplate*: string = staticRead "./templates/index.mustache"
|
||||
|
||||
testTemplate*: string = """<p>hi!</p>"""
|
||||
|
||||
template renderMustache*(title: string, templ: string, ctx: Context): expr =
|
||||
var
|
||||
layoutCtx = moustachu.newContext()
|
||||
|
||||
layoutCtx["title"] = title
|
||||
layoutCtx["body"] = render(templ, ctx)
|
||||
|
||||
resp render(baseTemplate, layoutCtx)
|
||||
|
||||
settings:
|
||||
port = 5000.Port
|
||||
|
@ -9,11 +21,6 @@ settings:
|
|||
|
||||
routes:
|
||||
get "/":
|
||||
var ctx = newContext()
|
||||
|
||||
ctx["title"] = "Test"
|
||||
ctx["body"] = "<p>Test!</p>"
|
||||
|
||||
resp render(baseTemplate, ctx)
|
||||
renderMustache("test", testTemplate, newContext())
|
||||
|
||||
runForever()
|
||||
|
|
|
@ -0,0 +1,9 @@
|
|||
<h1>Latest Quotes</h1>
|
||||
|
||||
{{# quotes }}
|
||||
<div class="entries">
|
||||
<h3>{{channel}} - {{time}}</h3>
|
||||
<p>({{nick}}) {{message}}</p>
|
||||
<small><i>Added by {{adder}}. <a href="/quotes/{{id}}">Permalink.</i></small>
|
||||
</div>
|
||||
{{/ quotes }}
|
|
@ -1,11 +1,12 @@
|
|||
<!doctype html>
|
||||
<title>Quotes{{# title }} - {{ title }}{{/title}}</title>
|
||||
<title>quotes{{# title }} - {{ title }}{{/ title }}</title>
|
||||
<link rel=stylesheet type=text/css href="/css/style.css">
|
||||
<div class=page>
|
||||
<h1>Quotes</h1>
|
||||
<h1>{{# title }}{{ title }}{{/ title }}</h1>
|
||||
<div class=metanav>
|
||||
<a href="/network">Network</a>
|
||||
<a href="/channel">Channel</a>
|
||||
<a href="/">home</a>
|
||||
<a href="/channel">channel</a>
|
||||
<a href="/submit">submit</a>
|
||||
</div>
|
||||
{{{ body }}}
|
||||
</div>
|
||||
|
|
Loading…
Reference in New Issue