Libraryless. Click here for Pure Java version (7594L/53K/159K).
!752 static int port = 7654; concepts. concept Definition { S name; // what is defined S text; // definition text O source; // where definition comes from (optional) O caveat; // an optional restriction of the definition, like "maybe" or "allegedly" or "rarely" or smth. *() {} *(S *name, S *text) { change(); } } p { useProgramDirOf("#1005059"); concepts(); serveHttp(port); makeBot("Wiki."); print("Go to http://localhost:\*port*/ to browse Wiki.\nType here to edit. Commands: def \"the topic\" \"the text\". undef \"the topic\"."); } synchronized answer { if "def * *" { S name = $1, text = $2; new Definition(name, text); int count = countConcepts(Definition, +name); ret "Definition saved! Now have " + n(count, "definition") + " for " + quote(name) + "."; } if "undef *" { S x = $1; if (isInteger(x)) ret deleteConcept(parseLong(x)) != null ? "Deleted" : "Nothing to delete"; else ret nempty(deleteConcepts(Definition, name := x)) ? "Deleted" : "Nothing to delete"; } } synchronized html { uri = dropPrefix("/", uri); // serve definition if (startsWith(uri, "!")) { S name = substring(uri, 1); L<Definition> l = findConceptsWhere(Definition, +name); if (empty(l)) ret fixHTML("No definition found for " + quote(htmlencode(name))); else ret fixHTML( htitle("Wiki: " + htmlencode(name)) + h1(htmlencode(name)) + ul(map(l, func(Definition d) { spanTitle("#" + d.id, htmlencode(d.text)) }))); } // process action if (eq(uri, "add")) { printStruct(params); S name = params.get("word").trim(); S text = params.get("definition").trim(); new Definition(name, text); ret hrefresh("/"); } // serve home page final MultiSet<S> ms = collectMultiSet(list(Definition.class), "name"); L<S> names = sorted(ms.keySet()); ret fixHTML( htitle_h1("A. I. Wiki!") + p("Yo I got definitions for:") + ul(map(names, func(S name) { int count = ms.get(name); //S xinfo = bracketedCount(count); Definition example = findConceptWhere(Definition, +name); S xinfo = " - " + htmlencode(example.text); if (count > 1) xinfo += " +\*count-1*/"; ret ahref("/!" + urlencode(name), htmlencode(name)) + xinfo; })) + h3("Add definition") + hform( htableRaw(ll( ll("Word", htextinput("word")), ll("Definition", htextinput("definition", style := "width: 500px")), ll("", hsubmit()) )) , action := "/add", method := "POST") ); }
Began life as a copy of #1005059
download show line numbers debug dex old transpilations
Travelled to 16 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, ddnzoavkxhuk, gwrvuhgaqvyk, ishqpsrjomds, iveijnkanddl, lpdgvwnxivlt, mqqgnosmbjvj, onxytkatvevr, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt
No comments. add comment
Snippet ID: | #1005066 |
Snippet name: | Wiki v2 [WORKS] |
Eternal ID of this version: | #1005066/1 |
Text MD5: | 3dc9a15d835c07eb6800fb83bd76b0ea |
Transpilation MD5: | 9265db718c22c7bb7d70c230975ef930 |
Author: | stefan |
Category: | javax / a.i. |
Type: | JavaX source code |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2016-11-10 01:37:30 |
Source code size: | 2711 bytes / 93 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 632 / 737 |
Referenced in: | -