Initial templating implementation

This commit is contained in:
Quad 2022-04-07 20:23:56 +02:00
parent 673a65c336
commit d754572c45
6 changed files with 40 additions and 9 deletions

View File

@ -12,3 +12,4 @@ bin = @["nimblog"]
requires "nim >= 1.6.0"
requires "prologue >= 0.5.6"
requires "nimja >= 0.5.6"

14
src/modules/blog.nim Normal file
View File

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

View File

@ -0,0 +1,6 @@
import nimja/parser
proc renderIndex(): string =
compileTemplateFile(getScriptDir() & "/templates/index.nwt")
export renderIndex

View File

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

View File

@ -0,0 +1,8 @@
<html>
<head>
<title>Example</title>
</head>
<body>
{% block content %}{% endblock %}
</body>
</html>

5
src/templates/index.nwt Normal file
View File

@ -0,0 +1,5 @@
{% extends templates/components/master.nwt %}
{% block content %}
<h1>Hello world</h1>
{% endblock %}