Mercurial > repos > rhope
diff framework.rhope @ 147:f3686f60985d
Sort of working port of framework. Transaction bug seems to be getting in the way. Going to work around, but want the old version in the repo so I can test later.
author | Mike Pavone <pavone@retrodev.com> |
---|---|
date | Mon, 22 Nov 2010 01:15:02 -0500 |
parents | 6202b866d72c |
children | f582fd6c75ee |
line wrap: on
line diff
--- a/framework.rhope Sun Nov 21 22:47:14 2010 -0500 +++ b/framework.rhope Mon Nov 22 01:15:02 2010 -0500 @@ -1,38 +1,65 @@ Import webserver.rhope +_Key Value Map[list,index,newlist,worker:out] +{ + newval,newkey <- [worker]Call[[list]Index[index], index] + + next <- [newlist]Set[newkey, newval] + + [list]Next[index] + { + out <- _Key Value Map[list, ~, next, worker] + }{ + out <- Val[next] + } +} + +Key Value Map[list,worker:out] +{ + [list]First + { + out <- _Key Value Map[list, ~, New Like[list], worker] + }{ + out <- New Like[list] + } +} + Framework Handler[con,path,request type,queryvars,headers,handler,title,use session] { page <- Page[title, path, use session, queryvars, headers] - out list <- [handler]Do[ [[List[]]Append[page]]Append[path] ] - handler page <- [out list]Index[0] + handler page <- [handler]Call[page,path] If[[request type] = ["POST"]] { - final page <- Process POST[handler page, con, headers] + final page,ncon <- Process POST[handler page, con, headers] }{ final page <- Val[handler page] + ncon <- Val[con] } string,out headers <- [final page]Render - [HTTP OK[con, Get Content Type[".html"], [string]Length, out headers] - ]Put String[string] + after headers <- HTTP OK[ncon, Get Content Type[".html"], [string]Byte Length, out headers] + { Print["Sent status"] + { [[string]Write to File[after headers]]Close + { Print["Wrote data"] }}} } Handler Fixer[handler:out] { - If[[Type Of[handler]] = ["List"]] + [(List(),List Leaf())]Find[=[?,Blueprint Of[handler]]] { - out <- [[["Framework Handler"]Set Input[5, [handler]Index[0]]]Set Input[6, [handler]Index[1]]]Set Input[7, [handler]Index[2]] + out <- Val[Framework Handler[?, ?, ?, ?, ?, [handler]Index[0], [handler]Index[1], [handler]Index[2]]] }{ out <- handler } } -Start Web[handlers] +Start Web[handlers,port] { Print["Starting Rhope Web Server"] - Init Sessions[] - { Listen on Port[80,["Connection Start"]Set Input[1, Map[handlers,"Handler Fixer"]]] } - Wait Forever[] + workaround <- Init Sessions[] + Val[workaround] + { Listen on Port[port,Connection Start[?, ?, Map[handlers,Handler Fixer[?]]]] + { Wait Forever[] }} } Get Class[container:class] @@ -54,7 +81,7 @@ Web Event[name,origin,data:out] { - out <- [[[Build["Web Event"]]Event Name <<[name]]Origin <<[origin]]Data <<[data] + out <- [[[Build[Web Event()]]Event Name <<[name]]Origin <<[origin]]Data <<[data] } Blueprint Web Container @@ -72,7 +99,7 @@ Web Container[class:out] { - out <- [[[[[[[[Build["Web Container"] + out <- [[[[[[[[Build[Web Container()] ]Tag Name <<["div"] ]Class <<[class] ]Propagate Events <<[No] @@ -95,11 +122,11 @@ _Preformatted[child,val:out] { - If[[Type Of[child]] = ["Web Text"]] + If[[Blueprint Of[child]] = [Web Text()]] { out <- [child]Preformatted <<[val] }{ - If[[Type Of[child]] = ["Web Container"]] + If[[Blueprint Of[child]] = [Web Container()]] { out <- [child]Preformatted[val] }{ @@ -110,7 +137,7 @@ Preformatted@Web Container[cont,preformatted?:out] { - out <- [[cont]Children <<[ Map[[cont]Children >>, ["_Preformatted"]Set Input[1, preformatted?]] ] + out <- [[cont]Children <<[ Map[[cont]Children >>, _Preformatted[?, preformatted?]] ] ]Preformatted <<[preformatted?] } @@ -120,7 +147,7 @@ [ [container]Use Session <<[Yes] ]Session <<[session] - ]Children <<[ Map[ [container]Children >>, ["Set Session"]Set Input[1, session] ] ] + ]Children <<[ Map[ [container]Children >>, Set Session[?, session] ] ] } Set Handler@Web Container[container,event name,handler:out] @@ -141,7 +168,7 @@ out <- [[[[[[["<"]Append[ [container]Tag Name >> ] ]Append[Get Class[container]] ]Append[[[">"]Append[newline]]Append[tab]] - ]Append[Fold[["Render Child"]<String@Worker, "", [container]Children >>]] + ]Append[Fold[Render Child[?], "", [container]Children >>]] ]Append[[newline]Append["</"]] ]Append[ [container]Tag Name >> ] ]Append[[">"]Append[newline]] @@ -152,18 +179,19 @@ event <- [events]Index[index] [[container]Handlers >>]Index[ [event]Event Name >>] { - result list <- [~]Do[ - [[List[]]Append[container]]Append[event] - ] - new container <- [result list]Index[0] - [result list]Index[1] + //The original version, you had to populate the container output + //and optionally populate the new event output, but that won't work + //now. None of my existing code really needs to populate both so I've + //made them mutually exclusive. + new container <- [~]Call[container,event] { - out events <- [result events]Append[~] + out events <- Val[result events] }{ - out events <- Val[result events] + out events <- [result events]Append[~] + new container <- Val[container] } }{ - new container <- container + new container <- Val[container] out events <- Val[result events] } @@ -261,7 +289,7 @@ Page[title,url,use session,queryvars,headers:out] { - page <- [[[[[[[Build["Page"] + page <- [[[[[[[Build[Page()] ]Title <<[title] ]URL <<[url] ]CSS <<[[List[]]Append["/default.css"]] @@ -271,7 +299,7 @@ ]Use Session <<[use session] If[use session] { - Load@Session[queryvars, headers] + Load Session[queryvars, headers] { out <- [[page]Session <<[~]]Session ID <<[ [~]Session ID>>] } @@ -302,7 +330,7 @@ ]Append[[[page]CSS >>]Join["\">\n\t\t<link rel=\"stylesheet\" href=\""]] ]Append["\">\n\t</head>\n\t<body>\n\t<form method=\"POST\" action=\""] ]Append[[[page]Get Action]Append["\">\n"]] - ]Append[Fold[["Render Child"]<String@Worker, "", [page]Children >>]] + ]Append[Fold[Render Child[?], "", [page]Children >>]] ]Append["\t</form>\n\t</body>\n</html>"] If[[page]Use Session>>] { @@ -350,7 +378,8 @@ Decode Helper Decode[list,destlist,index:out] { code,rest <- [[list]Index[index]]Slice[2] - newlist <- [destlist]Set[index, [[""]Put Byte[From Hex@Whole Number[code]]]Append[rest]] + decoded <- String[[Array[]]Append[Trunc UInt8[Abs UInt[Hex Int32[code]]]]] + newlist <- [destlist]Set[index, [decoded]Append[rest]] [list]Next[index] { out <- Decode Helper Decode[list, newlist, ~] @@ -392,13 +421,13 @@ okey <- URL Decode[key] } -Process POST[page,con,headers:out] +Process POST[page,con,headers:out,ncon] { - [con]Get FString[[headers]Index["Content-Length"]] {} + ,ncon <- [con]Read[[headers]Index["Content-Length"]] { - post string <- [~]Replace["+"," "] + post string <- [String[~]]Replace["+"," "] } - post data <- Key Value Map[Dict Split[post string, "=", "&"], ["Decode Pair"]<String@Worker] + post data <- Key Value Map[Dict Split[post string, "=", "&"], Decode Pair[?]] out <- [page]Postback[post data] } @@ -422,7 +451,7 @@ Web Text[text,tag:out] { - out <- [[[Build["Web Text"]]Text <<[text]]Enclosing Tag <<[tag]]Preformatted <<[No] + out <- [[[Build[Web Text()]]Text <<[text]]Enclosing Tag <<[tag]]Preformatted <<[No] } Name@Web Text[text:out,none] @@ -499,7 +528,7 @@ Web Field[name,value,type:out] { - out <- [[[[Build["Web Field"]]Name <<[name]]Value <<[value]]Type <<[type]]Class <<[""] + out <- [[[[Build[Web Field()]]Name <<[name]]Value <<[value]]Type <<[type]]Class <<[""] } Set Session@Web Field[in,session:out] @@ -545,7 +574,7 @@ Web Button[name,label:out] { - out <- [[[Build["Web Button"]]Name <<[name]]Label <<[label]]Class <<[""] + out <- [[[Build[Web Button()]]Name <<[name]]Label <<[label]]Class <<[""] } Name@Web Button[button:name,none] @@ -585,23 +614,25 @@ Get Unique ID[:out] uses Session { - out <- [[[::ID]<Whole Number@String]Append["_"]]Append[Random[]] - ::ID <- [::ID]+[1] + Print["Get Unique ID"] + out <- [[String[Session::ID]]Append["_"]]Append[String[Random[]]] + { Session::ID <- [Session::ID]+[1] } } Session[:out] { - out <- [[[[Build["Session"]]Session ID <<[Get Unique ID[]]]Use Cookies <<[No]]Data <<[Dictionary[]]]Dirty <<[No] + out <- [[[[Build[Session()]]Session ID <<[Get Unique ID[]]]Use Cookies <<[No]]Data <<[Dictionary[]]]Dirty <<[No] + { Print["Built session"] } } -Load@Session[queryvars,headers:out] uses Session +Load Session[queryvars,headers:out] uses Session { ,checkquery <- [headers]Index["Cookie"] { parts <- Dict Split[~, "=", "; "] ,checkquery <- [parts]Index["session_id"] { - ,checkquery <- [::Sessions]Index[~] + ,checkquery <- [Session::Sessions]Index[~] { out <- [~]Use Cookies <<[Yes] } @@ -613,7 +644,7 @@ { ,makenew <- [queryvars]Index["session_id"] { - out, makenew <- [::Sessions]Index[~] + out, makenew <- [Session::Sessions]Index[~] } } @@ -655,14 +686,20 @@ Init Sessions[:out] uses Session { - ::ID <- 1 - ::Sessions <- Dictionary[] + Session::Sessions <- Dictionary[] + out <- Yes +} + +Globals Session +{ + ID <- 1 + Sessions <- No out <- 0 } Save@Session[session:out] uses Session { - ::Sessions <- [::Sessions]Set[[session]Session ID >>, session] + Session::Sessions <- [Session::Sessions]Set[[session]Session ID >>, session] } Finalize@Session[session,headers:out headers] @@ -684,7 +721,7 @@ Web Link[text,target:out] { - out <- [[[[Build["Web Link"]]Text <<[text]]Target <<[target]]Class <<[""]]Query Params <<[Dictionary[]] + out <- [[[[Build[Web Link()]]Text <<[text]]Target <<[target]]Class <<[""]]Query Params <<[Dictionary[]] } @@ -742,7 +779,7 @@ Web Table[headers,data:out] { - out <- [[Build["Web Table"]]Headers <<[headers]]Data <<[data] + out <- [[Build[Web Table()]]Headers <<[headers]]Data <<[data] } Name@Web Table[link:name,none] @@ -770,7 +807,7 @@ { If[[[[table]Headers >>]Length] > [0]] { - out <- [Fold[["Make Header Row"]<String@Worker, "\t\t<tr>\n", [table]Headers >>]]Append["\t\t</tr>\n"] + out <- [Fold[Make Header Row[?], "\t\t<tr>\n", [table]Headers >>]]Append["\t\t</tr>\n"] }{ out <- "" } @@ -783,7 +820,7 @@ Make Table Row[string,row:out] { - out <- [Fold[["Make Table Cell"]<String@Worker, [string]Append["\t\t<tr>\n"], row]]Append["\t\t</tr>"] + out <- [Fold[Make Table Cell[?], [string]Append["\t\t<tr>\n"], row]]Append["\t\t</tr>"] } Render@Web Table[table:out,headers] @@ -791,7 +828,7 @@ out <- [ [ ["\t<table>\n"]Append[[table]Get Header Row] - ]Append[ Fold[["Make Table Row"]<String@Worker, "", [table]Data >>] ] + ]Append[ Fold[Make Table Row[?], "", [table]Data >>] ] ]Append["\t</table>\n"] } @@ -801,9 +838,9 @@ Alt } -New@Web Image[source,alt:out] +Web Image[source,alt:out] { - out <- [[Build["Web Image"]]Source <<[source]]Alt <<[alt] + out <- [[Build[Web Image()]]Source <<[source]]Alt <<[alt] } Name@Web Image[image:name,none]