GitHub Sale: sign up for any paid plan this week and pay nothing until January 1, 2009!  [ hide ]

why / yown fork watch download tarball
public
Description: a little web for Io
Clone URL: git://github.com/why/yown.git
why (author)
Wed Feb 27 16:16:06 -0800 2008
yown / yown.io
100644 52 lines (43 sloc) 1.04 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
//
// Yown
// a little web doodad for Io
//
 
doRelativeFile("yown/splitlines.io")
 
Yown := Object clone do(
 
  list("builder", "splitlines", "webrequest", "webserver") foreach(lib,
    doRelativeFile("yown/" .. lib .. ".io"))
 
  //
  // The `get`, `put`, etc.
  // (Incoming action handlers)
  //
  handlers := Map clone
  list("get", "post", "put", "delete") foreach(action,
    handlers atPut(action, List clone)
    setSlot(action,
      method(url, addHandler(call message name, url, call message argAt(1)))
    )
  )
 
  addHandler := method(action, url, block,
    handlers at(action) append(list("^#{url}$" interpolate asRegex, block))
  )
 
  handleRequest := method(req,
    match := handlers at(req command asLowercase) detect(l,
      req queryPath matchesRegex(l at(0))
    )
    if (match,
      doMessage(match at(1)),
      "404 NOT FOUND")
  )
 
  //
  // Starts the builtin server
  //
  run := method(
    WebServer run(self)
  )
 
  //
  // Main HTML method
  //
  html := method(
    Builder doMessage(call message)
  )
)