diff 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
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/said.rhope	Tue Apr 28 23:06:07 2009 +0000
@@ -0,0 +1,53 @@
+/*
+	This program implements Paul Graham's "Arc Challenge"
+	While I think the Arc Challenge is a little silly, it does provide a simple 
+	example of how to use the web framework I whipped up for the Rhope blog
+*/
+
+//The Import keyword causes another Rhope source file to be included
+//Here we import the Rhope web framework
+Import framework.rhope
+
+//Here we define an event handler that will get called when the user clicks the button
+//Event handlers get passed the current page tree and an event object
+Save Text[page,event:out]
+{
+	//First we store the value from the text box in a session variable
+	out <- [[[page]Set["said",[[page]Get Child By Name["foo"]]Value >>]
+	//Then we empty the page object
+	]Clear Children
+	//And we add a hyperlink
+	]Add Child[New@Web Link["Click Here","/said"]]
+}
+
+//This worker defines our page
+Said[page,query:out]
+{
+	//Here we try to retrieve the session variable "said"
+	[page]Index["said"]
+	{
+		//If it's present we display it on the page
+		out <- [page]Add Child[ ["You said: "]Append[~] ]
+	}{
+		//Otherwise we provide them with a form to enter a word
+		out <- [[[page]Add Child[New@Web Field["foo","","text"]]
+			]Add Child[
+				New@Web Button["blah","Click!"]
+			//The Set Handler call here attaches the worker Save Text to the click event for the page
+			//Events propagate can propagate themselves up the page hierarchy and handled wherever appropriate
+			]]Set Handler["click","Save Text"]
+	}
+}
+
+Main[]
+{
+	//Start Web starts the webserver and initializes the web framework
+	Start Web[
+		//It takes a dictionary mapping paths to Workers that define dynamic pages
+		//Rather than just passing the name of the Worker, we're passing a List of info
+		//that allows the framework to take care of some of the drudgework for us
+		//The first element in the list is the worker name, the second the page title 
+		//and the third element indicates whether this page will be using session data or not
+		[New@Dictionary[]]Set["/said",("Said","That's what she said",Yes)]
+	]
+}