Simple web server

This commit is contained in:
Florian Schroedl
2022-05-04 17:00:00 +02:00
parent f038e4f272
commit 05ecdb1f9e
13 changed files with 209 additions and 7 deletions

View File

@@ -0,0 +1,42 @@
import std/[
options,
sequtils,
strformat,
strutils,
sugar,]
import ./org_types_interface
const INDENT_SIZE = 2;
func stringifySpecialFields(x: OrgBlock, indent = 0): string =
(
case x.kind:
of orgHeading:
@[
("kind", $x.kind, true),
("level", $x.level, true),
("todo", $x.todo, x.todo.isSome()),
("headlineContent", $x.headlineContent, x.headlineContent.len != 0),
("headlineChildrenText", $x.headlineChildrenText, x.headlineChildrenText.len != 0),
("children", $x.children, true),]
else: @[])
.filter(x => x[2])
.map(x => x[0] & ": " & x[1])
.join(",\n")
proc `$`*(x: OrgBlock, indent = 0): string =
let fieldIndent = indent + INDENT_SIZE
@[
"OrgBlock(",
stringifySpecialFields(x).indent(fieldIndent),
")",]
.join("\n")
when isMainModule:
echo OrgBlock(kind: orgHeading, todo: "foo".some)