run command, make template rendering a template
This commit is contained in:
parent
5c02b05882
commit
89201245d7
|
@ -9,5 +9,8 @@ bin = @["quotesite"]
|
||||||
|
|
||||||
# Dependencies
|
# 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
|
import asyncdispatch, jester, moustachu, os, strutils
|
||||||
|
|
||||||
const
|
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:
|
settings:
|
||||||
port = 5000.Port
|
port = 5000.Port
|
||||||
|
@ -9,11 +21,6 @@ settings:
|
||||||
|
|
||||||
routes:
|
routes:
|
||||||
get "/":
|
get "/":
|
||||||
var ctx = newContext()
|
renderMustache("test", testTemplate, newContext())
|
||||||
|
|
||||||
ctx["title"] = "Test"
|
|
||||||
ctx["body"] = "<p>Test!</p>"
|
|
||||||
|
|
||||||
resp render(baseTemplate, ctx)
|
|
||||||
|
|
||||||
runForever()
|
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>
|
<!doctype html>
|
||||||
<title>Quotes{{# title }} - {{ title }}{{/title}}</title>
|
<title>quotes{{# title }} - {{ title }}{{/ title }}</title>
|
||||||
<link rel=stylesheet type=text/css href="/css/style.css">
|
<link rel=stylesheet type=text/css href="/css/style.css">
|
||||||
<div class=page>
|
<div class=page>
|
||||||
<h1>Quotes</h1>
|
<h1>{{# title }}{{ title }}{{/ title }}</h1>
|
||||||
<div class=metanav>
|
<div class=metanav>
|
||||||
<a href="/network">Network</a>
|
<a href="/">home</a>
|
||||||
<a href="/channel">Channel</a>
|
<a href="/channel">channel</a>
|
||||||
|
<a href="/submit">submit</a>
|
||||||
</div>
|
</div>
|
||||||
{{{ body }}}
|
{{{ body }}}
|
||||||
</div>
|
</div>
|
||||||
|
|
Loading…
Reference in New Issue