Libraryless. Click here for Pure Java version (6364L/45K/131K).
1 | !752 |
2 | |
3 | concepts. |
4 | |
5 | concept Definition { |
6 | S name; // what is defined |
7 | S text; // definition text |
8 | O source; // where definition comes from (optional) |
9 | O caveat; // an optional restriction of the definition, like "maybe" or "allegedly" or "rarely" or smth. |
10 | |
11 | *() {} |
12 | *(S *name, S *text) { change(); } |
13 | } |
14 | |
15 | p { |
16 | loadAndAutoSaveConcepts(); |
17 | serveHttp(7654); |
18 | makeBot("Wiki."); |
19 | } |
20 | |
21 | synchronized answer { |
22 | if "def * *" { |
23 | S name = m.unq(0); |
24 | S text = m.unq(1); |
25 | new Definition(name, text); |
26 | int count = countConcepts(Definition.class, "name", name); |
27 | ret "Definition saved! Now have " + n(count, "definition") + " for " + quote(name) + "."; |
28 | } |
29 | } |
30 | |
31 | synchronized html { |
32 | uri = dropPrefix("/", uri); |
33 | if (startsWith(uri, "!")) { |
34 | S name = substring(uri, 1); |
35 | L<Definition> l = findConceptsWhere(Definition.class, "name", name); |
36 | if (empty(l)) |
37 | ret fixHTML("No definition found for " + quote(htmlencode(name))); |
38 | else |
39 | ret fixHTML(h1(htmlencode(name)) |
40 | + ul(map(l, func(Definition d) { htmlencode(d.text) }))); |
41 | } |
42 | |
43 | final MultiSet<S> ms = collectMultiSet(list(Definition.class), "name"); |
44 | L<S> names = sorted(ms.keySet()); |
45 | ret fixHTML( |
46 | h1("A. I. Wiki!") |
47 | + p("Yo I got definitions for:") |
48 | + ul(map(names, func(S name) { |
49 | ahref("/!" + urlencode(name), htmlencode(name)) + bracketedCount(ms.get(name)) |
50 | }))); |
51 | } |
download show line numbers debug dex old transpilations
Travelled to 15 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, ddnzoavkxhuk, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, onxytkatvevr, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt
No comments. add comment
Snippet ID: | #1005059 |
Snippet name: | Wiki [simple version] |
Eternal ID of this version: | #1005059/1 |
Text MD5: | fbeaf402dff4e4881b9223a48cfa3dab |
Transpilation MD5: | 59879f078b2de06f6a5f3f230b5342de |
Author: | stefan |
Category: | javax / a.i. |
Type: | JavaX source code |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2016-10-04 21:12:41 |
Source code size: | 1430 bytes / 51 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 680 / 1094 |
Referenced in: | [show references] |