Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

93
LINES

< > BotCompany Repo | #1005066 // Wiki v2 [WORKS]

JavaX source code [tags: use-pretranspiled] - run with: x30.jar

Libraryless. Click here for Pure Java version (7594L/53K/159K).

1  
!752
2  
3  
static int port = 7654;
4  
5  
concepts.
6  
7  
concept Definition {
8  
  S name;   // what is defined
9  
  S text;   // definition text
10  
  O source; // where definition comes from (optional)
11  
  O caveat; // an optional restriction of the definition, like "maybe" or "allegedly" or "rarely" or smth.
12  
  
13  
  *() {}
14  
  *(S *name, S *text) { change(); }
15  
}
16  
17  
p {
18  
  useProgramDirOf("#1005059");
19  
  concepts();
20  
  serveHttp(port);
21  
  makeBot("Wiki.");
22  
  print("Go to http://localhost:\*port*/ to browse Wiki.\nType here to edit. Commands: def \"the topic\" \"the text\". undef \"the topic\".");
23  
}
24  
25  
synchronized answer {
26  
  if "def * *" {
27  
    S name = $1, text = $2;
28  
    new Definition(name, text);
29  
    int count = countConcepts(Definition, +name);
30  
    ret "Definition saved! Now have " + n(count, "definition") + " for " + quote(name) + ".";
31  
  }
32  
  
33  
  if "undef *" {
34  
    S x = $1;
35  
    if (isInteger(x))
36  
      ret deleteConcept(parseLong(x)) != null ? "Deleted" : "Nothing to delete";
37  
    else
38  
      ret nempty(deleteConcepts(Definition, name := x)) ? "Deleted" : "Nothing to delete";
39  
  }
40  
}
41  
42  
synchronized html {
43  
  uri = dropPrefix("/", uri);
44  
  
45  
  // serve definition
46  
  
47  
  if (startsWith(uri, "!")) {
48  
    S name = substring(uri, 1);
49  
    L<Definition> l = findConceptsWhere(Definition, +name);
50  
    if (empty(l))
51  
      ret fixHTML("No definition found for " + quote(htmlencode(name)));
52  
    else
53  
      ret fixHTML(
54  
          htitle("Wiki: " + htmlencode(name))
55  
        + h1(htmlencode(name))
56  
        + ul(map(l, func(Definition d) { spanTitle("#" + d.id, htmlencode(d.text)) })));
57  
  }
58  
  
59  
  // process action
60  
  
61  
  if (eq(uri, "add")) {
62  
    printStruct(params);
63  
    S name = params.get("word").trim();
64  
    S text = params.get("definition").trim();
65  
    new Definition(name, text);
66  
    ret hrefresh("/");
67  
  }
68  
  
69  
  // serve home page
70  
71  
  final MultiSet<S> ms = collectMultiSet(list(Definition.class), "name");
72  
  L<S> names = sorted(ms.keySet());
73  
  ret fixHTML(
74  
      htitle_h1("A. I. Wiki!")
75  
    + p("Yo I got definitions for:")
76  
    + ul(map(names, func(S name) {
77  
        int count = ms.get(name);
78  
        //S xinfo = bracketedCount(count);
79  
        Definition example = findConceptWhere(Definition, +name);
80  
        S xinfo = " - " + htmlencode(example.text);
81  
        if (count > 1) xinfo += " +\*count-1*/";
82  
        ret ahref("/!" + urlencode(name), htmlencode(name)) + xinfo;
83  
      }))
84  
    + h3("Add definition")
85  
    + hform(
86  
        htableRaw(ll(
87  
          ll("Word", htextinput("word")),
88  
          ll("Definition", htextinput("definition", style := "width: 500px")),
89  
          ll("", hsubmit())
90  
        ))
91  
      , action := "/add", method := "POST")
92  
  );
93  
}

Author comment

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: 531 / 630
Referenced in: [show references]