import dom import json import nimja/parser import sequtils import strutils import strformat import math import tables import sugar # lambda syntax #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 nil 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 # Nimja Stuff proc is_numeric*(s: string): bool = try: discard s.parseFloat() result = true except: discard proc renderIndex(): string = compileTemplateFile(getScriptDir() / "main.nimja") document.write renderIndex()