2021-09-12 06:16:18 +00:00
|
|
|
import os, osproc, strutils
|
2020-12-01 17:49:41 +00:00
|
|
|
|
|
|
|
proc cutBetween(str, a, b: string): string =
|
|
|
|
let
|
|
|
|
cutA = str.find(a)
|
|
|
|
cutB = str.find(b)
|
|
|
|
if cutA == -1 or cutB == -1:
|
|
|
|
return ""
|
|
|
|
return str[cutA + a.len..<cutB]
|
|
|
|
|
|
|
|
var md: seq[string]
|
|
|
|
|
2021-02-14 04:45:27 +00:00
|
|
|
var exampleFiles = [
|
2021-05-11 21:35:44 +00:00
|
|
|
"examples/text.nim",
|
|
|
|
"examples/text_spans.nim",
|
2021-02-14 04:45:27 +00:00
|
|
|
"examples/square.nim",
|
2021-02-18 18:14:55 +00:00
|
|
|
"examples/line.nim",
|
2021-02-14 04:45:27 +00:00
|
|
|
"examples/rounded_rectangle.nim",
|
|
|
|
"examples/heart.nim",
|
2021-02-25 16:51:09 +00:00
|
|
|
"examples/masking.nim",
|
2021-02-25 16:57:49 +00:00
|
|
|
"examples/gradient.nim",
|
|
|
|
"examples/image_tiled.nim",
|
2021-02-14 04:45:27 +00:00
|
|
|
"examples/shadow.nim",
|
|
|
|
"examples/blur.nim",
|
|
|
|
"examples/tiger.nim"
|
|
|
|
]
|
|
|
|
|
|
|
|
for path in exampleFiles:
|
2021-09-08 02:13:36 +00:00
|
|
|
discard execCmd("nim c -r " & path)
|
2021-02-14 04:45:27 +00:00
|
|
|
let code = readFile(path)
|
|
|
|
let innerCode = code.cutBetween("image.fill(rgba(255, 255, 255, 255))", "image.writeFile")
|
|
|
|
if innerCode != "":
|
|
|
|
let path = path.replace("\\", "/")
|
|
|
|
md.add "### " & path.splitFile().name.replace("_", " ").capitalizeAscii()
|
2021-09-12 06:16:18 +00:00
|
|
|
md.add "nim c -r [" & path & "](" & path & ")"
|
2021-02-14 04:45:27 +00:00
|
|
|
md.add "```nim"
|
|
|
|
md.add innerCode.strip()
|
|
|
|
md.add "```"
|
2021-02-14 18:27:32 +00:00
|
|
|
md.add "![example output](" & path.replace(".nim", ".png").replace("\\",
|
|
|
|
"/") & ")"
|
2021-02-14 04:45:27 +00:00
|
|
|
md.add ""
|
2020-12-01 17:49:41 +00:00
|
|
|
|
|
|
|
var readme = readFile("README.md")
|
|
|
|
|
|
|
|
let at = readme.find("## Examples")
|
|
|
|
if at != -1:
|
|
|
|
readme = readme[0 .. at]
|
|
|
|
readme.add("# Examples\n\n")
|
2021-09-12 06:16:18 +00:00
|
|
|
readme.add("`git clone https://github.com/treeform/pixie` to run examples.\n\n")
|
2020-12-01 17:49:41 +00:00
|
|
|
readme.add(md.join("\n"))
|
|
|
|
|
|
|
|
writeFile("README.md", readme)
|