This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# layout.nim | |
import templates | |
proc render*(title, content: string): string = | |
tmpli html""" | |
<!doctype html> | |
<html lang="en"> | |
<head> | |
<meta charset="utf-8"> | |
<title>$title</title> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type Pub*[T] = object | |
subs: seq[proc(e: T)] | |
proc init*[T](pub: var Pub[T]) = | |
if pub.subs == nil: | |
pub.subs = @[] | |
proc `()`*[T](pub: Pub, e: T) = | |
if pub.subs != nil: | |
for sub in pub.subs: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import macros | |
proc makeRef(obj: PNimrodNode): PNimrodNode {.compiletime.} = | |
var typeName: string | |
var assignments = newSeq[PNimrodNode]() | |
for i in obj.children: | |
if i.kind == nnkIdent: | |
typeName = $i | |
elif i.kind == nnkExprColonExpr: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import jester, templates | |
proc view(obj: Todo): string = tmpli html""" | |
<ul> | |
$for item in obj { | |
<li>$item</li> | |
} | |
</ul> | |
""" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Dont remove any ()'s! | |
import sequtils, future | |
iterator items(num = 10): int = | |
for i in 1.. num: | |
yield i | |
let values = toSeq(numbers()) | |
.filter(x => (x mod 2 == 1)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## Old | |
# Import "test" class from C++: | |
class(test, ns: pp, header: "../test.hpp"): | |
proc multiply[T](value, by: T): int | |
proc output: void {.isstatic.} | |
proc max[T](a, b: T): T | |
var fieldName, notherName: int | |
## New |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
when someModule: | |
proc a = | |
const someHtml = """ | |
<div>breaks indentation</div> | |
""" | |
proc b = | |
const someHtml = """ | |
<div>extra indentation</div> | |
""" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Imports | |
import math | |
# Constants | |
const RAND_MAX = 0x7fff | |
# Types | |
type | |
TVec2 = object | |
x, y: float |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Imports | |
import zlib | |
import sockets, jester | |
# Types | |
type TCompressStream* = ref object of TObject | |
client: TSocket | |
when defined(usegzip): | |
stream: TZStream |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import templates, macros | |
template master(content: stmt): stmt {.immediate.} = | |
template body = content | |
tmpli html""" | |
<html> | |
<body> | |
${ body() } | |
</body> |