comparison said.rhope @ 0:76568becd6d6

Rhope Alpha 2a source import
author Mike Pavone <pavone@retrodev.com>
date Tue, 28 Apr 2009 23:06:07 +0000
parents
children f3686f60985d
comparison
equal deleted inserted replaced
-1:000000000000 0:76568becd6d6
1 /*
2 This program implements Paul Graham's "Arc Challenge"
3 While I think the Arc Challenge is a little silly, it does provide a simple
4 example of how to use the web framework I whipped up for the Rhope blog
5 */
6
7 //The Import keyword causes another Rhope source file to be included
8 //Here we import the Rhope web framework
9 Import framework.rhope
10
11 //Here we define an event handler that will get called when the user clicks the button
12 //Event handlers get passed the current page tree and an event object
13 Save Text[page,event:out]
14 {
15 //First we store the value from the text box in a session variable
16 out <- [[[page]Set["said",[[page]Get Child By Name["foo"]]Value >>]
17 //Then we empty the page object
18 ]Clear Children
19 //And we add a hyperlink
20 ]Add Child[New@Web Link["Click Here","/said"]]
21 }
22
23 //This worker defines our page
24 Said[page,query:out]
25 {
26 //Here we try to retrieve the session variable "said"
27 [page]Index["said"]
28 {
29 //If it's present we display it on the page
30 out <- [page]Add Child[ ["You said: "]Append[~] ]
31 }{
32 //Otherwise we provide them with a form to enter a word
33 out <- [[[page]Add Child[New@Web Field["foo","","text"]]
34 ]Add Child[
35 New@Web Button["blah","Click!"]
36 //The Set Handler call here attaches the worker Save Text to the click event for the page
37 //Events propagate can propagate themselves up the page hierarchy and handled wherever appropriate
38 ]]Set Handler["click","Save Text"]
39 }
40 }
41
42 Main[]
43 {
44 //Start Web starts the webserver and initializes the web framework
45 Start Web[
46 //It takes a dictionary mapping paths to Workers that define dynamic pages
47 //Rather than just passing the name of the Worker, we're passing a List of info
48 //that allows the framework to take care of some of the drudgework for us
49 //The first element in the list is the worker name, the second the page title
50 //and the third element indicates whether this page will be using session data or not
51 [New@Dictionary[]]Set["/said",("Said","That's what she said",Yes)]
52 ]
53 }