Skip to content

Commit

Permalink
Show Tim + Prologue
Browse files Browse the repository at this point in the history
  • Loading branch information
Uzo2005 committed Feb 27, 2024
1 parent f0889c3 commit e5b13a1
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 0 deletions.
56 changes: 56 additions & 0 deletions example/example_prologue.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#This example demonstrates using Tim with Prologue
import std/[strutils, times]
import prologue
include ./initializer

#init Settings for prologue
let
settings = newSettings(port = Port(8082))

var app = newApp(settings = settings)

#define your route handling callbacks
proc indexPageHandler(ctx: Context) {.async, gcsafe.} =
let localObjects = %*{
"meta": {
"title": "Tim Engine is Awesome!"
},
"path": "/"
}

{.cast(gcsafe).}: #timl is a global using GC'ed memory and prologue loves it's callbacks to be gc-safe
let indexPage = timl.render(viewName = "index", layoutName = "base", local = localObjects)

resp indexPage

proc aboutPageHandler(ctx: Context) {.async, gcsafe.} =
let localObjects = %*{
"meta": {
"title": "About Tim Engine"
},
"path": "/about"
}
{.cast(gcsafe).}: #timl is a global using GC'ed memory and prologue loves it's callbacks to be gc-safe
let aboutPage = timl.render(viewName = "about", layoutName = "secondary", local = localObjects)

resp aboutPage

proc e404(ctx: Context) {.async, gcsafe.} =
let localObjects = %*{
"meta": {
"title": "Oh, you're a genius!",
"msg": "Oh yes, yes. It's got action, it's got drama, it's got dance! Oh, it's going to be a hit hit hit!"
},
"path": %*(ctx.request.path)
}
{.cast(gcsafe).}: #timl is a global using GC'ed memory and prologue loves it's callbacks to be gc-safe
let e404Page = timl.render(viewName = "error", layoutName = "base", local = localObjects)

resp e404Page

#tell prologue how to handle routes
app.addRoute("/", indexPageHandler)
app.addRoute("/about", aboutPageHandler)
app.registerErrorHandler(Http404, e404)

app.run()
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

0 comments on commit e5b13a1

Please sign in to comment.