Split template name from function, and add basic env-based debug toggle

This commit is contained in:
Quad 2022-04-11 07:58:28 +02:00
parent 057235669a
commit 0a24eaadfa
3 changed files with 20 additions and 5 deletions

View File

@ -1,11 +1,15 @@
import env
import prologue import prologue
import templating import templating
proc getIndex*(ctx: Context) {.async.} = proc getIndex*(ctx: Context) {.async.} =
resp renderIndex() resp renderTemplate(templateName="index.nwt")
proc runWebsite() = proc runWebsite() =
let website = newApp() let settings = newSettings(
debug = boolEnvOrDefault("DEBUG", false)
)
let website = newApp(settings = settings)
website.get("/", getIndex) website.get("/", getIndex)

11
src/modules/env.nim Normal file
View File

@ -0,0 +1,11 @@
import os
proc boolEnvOrDefault(envName: string, default: bool): bool =
if getEnv(envName) == "false":
return false
elif getEnv(envName) == "true":
return true
else:
return default
export boolEnvOrDefault

View File

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