Split template name from function, and add basic env-based debug toggle
This commit is contained in:
parent
057235669a
commit
0a24eaadfa
|
@ -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)
|
||||||
|
|
||||||
|
|
|
@ -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
|
|
@ -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
|
||||||
|
|
Loading…
Reference in New Issue