Initial templating implementation
This commit is contained in:
parent
673a65c336
commit
d754572c45
|
@ -12,3 +12,4 @@ bin = @["nimblog"]
|
|||
|
||||
requires "nim >= 1.6.0"
|
||||
requires "prologue >= 0.5.6"
|
||||
requires "nimja >= 0.5.6"
|
||||
|
|
|
@ -0,0 +1,14 @@
|
|||
import prologue
|
||||
import templating
|
||||
|
||||
proc getIndex*(ctx: Context) {.async.} =
|
||||
resp renderIndex()
|
||||
|
||||
proc runWebsite() =
|
||||
let website = newApp()
|
||||
|
||||
website.get("/", getIndex)
|
||||
|
||||
website.run()
|
||||
|
||||
export runWebsite
|
|
@ -0,0 +1,6 @@
|
|||
import nimja/parser
|
||||
|
||||
proc renderIndex(): string =
|
||||
compileTemplateFile(getScriptDir() & "/templates/index.nwt")
|
||||
|
||||
export renderIndex
|
|
@ -1,11 +1,8 @@
|
|||
when isMainModule:
|
||||
import prologue
|
||||
import modules/blog
|
||||
|
||||
proc placeholder*(ctx: Context) {.async.} =
|
||||
resp "Have a nice day"
|
||||
|
||||
let blog = newApp()
|
||||
|
||||
blog.get("/", placeholder)
|
||||
|
||||
blog.run()
|
||||
try:
|
||||
echo "Starting website"
|
||||
runWebsite()
|
||||
except:
|
||||
echo "Could not run website"
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
<html>
|
||||
<head>
|
||||
<title>Example</title>
|
||||
</head>
|
||||
<body>
|
||||
{% block content %}{% endblock %}
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,5 @@
|
|||
{% extends templates/components/master.nwt %}
|
||||
|
||||
{% block content %}
|
||||
<h1>Hello world</h1>
|
||||
{% endblock %}
|
Loading…
Reference in New Issue