Simple web server
This commit is contained in:
42
src/org/org_types_printer.nim
Normal file
42
src/org/org_types_printer.nim
Normal 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)
|
||||
Reference in New Issue
Block a user