70 lines
1.5 KiB
Nim
70 lines
1.5 KiB
Nim
import dom
|
|
import json
|
|
import nimja/parser
|
|
import sequtils
|
|
import strutils
|
|
import strformat
|
|
import tables
|
|
import sugar
|
|
#import jscore
|
|
|
|
# XPATH JSON stuff
|
|
|
|
type Entry = object
|
|
node : string
|
|
xpath : string
|
|
content : string
|
|
attributes : Table[string, string]
|
|
|
|
let entries = parseJson($document.getElementById("json_data").innerText).to(seq[Entry])
|
|
#.map do (entry: Entry ) -> Entry: entry. TODO: strip content
|
|
.filter do (entry: Entry) -> bool:
|
|
not entry.xpath.contains("text()") or entry.content.strip() != ""
|
|
|
|
proc get(key: string): Entry =
|
|
for entry in entries:
|
|
if entry.xpath == fmt"/ability_card/{key}":
|
|
return entry
|
|
assert false
|
|
|
|
#proc get_first(path: str): Entry =
|
|
# for entry in entries:
|
|
# if entry
|
|
|
|
type Component = object
|
|
key : string # db_entry
|
|
x : int
|
|
y : int
|
|
attrs : Table[string, string]
|
|
|
|
var components: seq[Component] = @[]
|
|
for entry in entries:
|
|
if entry.node == "component" and entry.xpath.startswith("/ability_card/component["):
|
|
var attrs = entry.attributes
|
|
attrs.del("x")
|
|
attrs.del("y")
|
|
attrs.del("db_entry")
|
|
components.add Component(
|
|
x : entry.attributes["x"].parseInt(),
|
|
y : entry.attributes["y"].parseInt(),
|
|
key : entry.attributes["db_entry"],
|
|
attrs : attrs,
|
|
)
|
|
|
|
# YAML stuff
|
|
|
|
|
|
|
|
proc renderIndex(
|
|
title : string,
|
|
entries : seq[Entry],
|
|
get : (string) -> Entry,
|
|
): string =
|
|
compileTemplateFile(getScriptDir() / "main.nimja", )
|
|
|
|
document.write renderIndex(
|
|
"index",
|
|
entries,
|
|
get,
|
|
)
|