run command, make template rendering a template

This commit is contained in:
Christine Dodrill 2016-02-05 15:16:42 -08:00
parent 5c02b05882
commit 89201245d7
4 changed files with 32 additions and 12 deletions

View File

@ -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"

View File

@ -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()

View File

@ -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 }}

View File

@ -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>