Skip to content

Commit 597b5a7

Browse files
committed
update examples
Signed-off-by: George Lemon <georgelemon@protonmail.com>
1 parent eecb72c commit 597b5a7

12 files changed

Lines changed: 500 additions & 367 deletions

File tree

example/example_mummy.nim

Lines changed: 0 additions & 57 deletions
This file was deleted.

example/example_prologue.nim

Lines changed: 40 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,61 @@
1-
#This example demonstrates using Tim with Prologue
2-
import std/[strutils, times]
3-
import prologue
4-
include ./initializer
1+
# This is an example of using Tim Engine with Prologue
2+
3+
import std/[strutils, times, os]
4+
import ../src/tim
5+
6+
#
7+
# Setup Tim Engine
8+
#
9+
var
10+
timEngine = newTim(
11+
src = "templates", # where to find the .timl files
12+
output = "storage", # where to cache precompiled templates
13+
basepath = getCurrentDir() # base path for resolving absolute paths in templates
14+
)
515

6-
#init Settings for prologue
7-
let
8-
settings = newSettings(port = Port(8082))
16+
timEngine.precompile()
17+
18+
#
19+
# Setup Prologue
20+
#
21+
import prologue
922

23+
let settings = newSettings(port = Port(8082))
1024
var app = newApp(settings = settings)
1125

1226
#define your route handling callbacks
1327
proc indexPageHandler(ctx: Context) {.async, gcsafe.} =
28+
{.gcsafe.}:
1429
let localObjects = %*{
15-
"meta": {
16-
"title": "Tim Engine is Awesome!"
17-
},
18-
"path": "/"
30+
"meta": {
31+
"title": "Tim Engine is Awesome!"
32+
},
33+
"path": "/"
1934
}
20-
21-
{.cast(gcsafe).}: #timl is a global using GC'ed memory and prologue loves it's callbacks to be gc-safe
22-
let indexPage = timl.render(viewName = "index", layoutName = "base", local = localObjects)
23-
35+
let indexPage = timEngine.render(view = "index", data = localObjects)
2436
resp indexPage
2537

2638
proc aboutPageHandler(ctx: Context) {.async, gcsafe.} =
39+
{.gcsafe.}:
2740
let localObjects = %*{
28-
"meta": {
29-
"title": "About Tim Engine"
30-
},
31-
"path": "/about"
41+
"meta": {
42+
"title": "About Tim Engine"
43+
},
44+
"path": "/about"
3245
}
33-
{.cast(gcsafe).}: #timl is a global using GC'ed memory and prologue loves it's callbacks to be gc-safe
34-
let aboutPage = timl.render(viewName = "about", layoutName = "secondary", local = localObjects)
35-
46+
let aboutPage = timEngine.render(view = "about", layout = "secondary", data = localObjects)
3647
resp aboutPage
3748

3849
proc e404(ctx: Context) {.async, gcsafe.} =
50+
{.gcsafe.}:
3951
let localObjects = %*{
40-
"meta": {
41-
"title": "Oh, you're a genius!",
42-
"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!"
43-
},
44-
"path": %*(ctx.request.path)
52+
"meta": {
53+
"title": "Oh, you're a genius!",
54+
"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!"
55+
},
56+
"path": %*(ctx.request.path)
4557
}
46-
{.cast(gcsafe).}: #timl is a global using GC'ed memory and prologue loves it's callbacks to be gc-safe
47-
let e404Page = timl.render(viewName = "error", layoutName = "base", local = localObjects)
48-
58+
let e404Page = timEngine.render(view = "error", data = localObjects)
4959
resp e404Page
5060

5161
#tell prologue how to handle routes

example/initializer.nim

Lines changed: 0 additions & 83 deletions
This file was deleted.

0 commit comments

Comments
 (0)