Move http.server.responders.* to webapps.*
parent
86a7156a35
commit
37ee63e72d
|
@ -4,7 +4,7 @@ USING: kernel vectors io assocs quotations splitting strings
|
|||
words sequences namespaces arrays hashtables debugger
|
||||
continuations tuples classes io.files
|
||||
http http.server.templating http.basic-authentication
|
||||
http.server.responders.callback html html.elements
|
||||
webapps.callback html html.elements
|
||||
http.server.responders furnace.validator ;
|
||||
IN: furnace
|
||||
|
||||
|
|
|
@ -210,3 +210,43 @@ M: html-stream stream-nl ( stream -- )
|
|||
<title> write </title>
|
||||
default-css
|
||||
] html-document ;
|
||||
|
||||
: vertical-layout ( list -- )
|
||||
#! Given a list of HTML components, arrange them vertically.
|
||||
<table>
|
||||
[ <tr> <td> call </td> </tr> ] each
|
||||
</table> ;
|
||||
|
||||
: horizontal-layout ( list -- )
|
||||
#! Given a list of HTML components, arrange them horizontally.
|
||||
<table>
|
||||
<tr "top" =valign tr> [ <td> call </td> ] each </tr>
|
||||
</table> ;
|
||||
|
||||
: button ( label -- )
|
||||
#! Output an HTML submit button with the given label.
|
||||
<input "submit" =type =value input/> ;
|
||||
|
||||
: paragraph ( str -- )
|
||||
#! Output the string as an html paragraph
|
||||
<p> write </p> ;
|
||||
|
||||
: simple-page ( title quot -- )
|
||||
#! Call the quotation, with all output going to the
|
||||
#! body of an html page with the given title.
|
||||
<html>
|
||||
<head> <title> swap write </title> </head>
|
||||
<body> call </body>
|
||||
</html> ;
|
||||
|
||||
: styled-page ( title stylesheet-quot quot -- )
|
||||
#! Call the quotation, with all output going to the
|
||||
#! body of an html page with the given title. stylesheet-quot
|
||||
#! is called to generate the required stylesheet.
|
||||
<html>
|
||||
<head>
|
||||
<title> rot write </title>
|
||||
swap call
|
||||
</head>
|
||||
<body> call </body>
|
||||
</html> ;
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
USING: http.server.responders.file http.server.responders http
|
||||
USING: webapps.file http.server.responders http
|
||||
http.server namespaces io tools.test strings io.server ;
|
||||
IN: temporary
|
||||
|
||||
|
|
|
@ -2,9 +2,7 @@
|
|||
! See http://factorcode.org/license.txt for BSD license.
|
||||
USING: assocs kernel namespaces io strings splitting
|
||||
threads http http.server.responders sequences prettyprint
|
||||
io.server http.server.responders.file
|
||||
http.server.responders.callback
|
||||
http.server.responders.continuation ;
|
||||
io.server ;
|
||||
|
||||
IN: http.server
|
||||
|
||||
|
@ -63,3 +61,9 @@ IN: http.server
|
|||
: httpd-main ( -- ) 8888 httpd ;
|
||||
|
||||
MAIN: httpd-main
|
||||
|
||||
! Load default webapps
|
||||
USE: webapps.file
|
||||
USE: webapps.callback
|
||||
USE: webapps.continuation
|
||||
USE: webapps.cgi
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
IN: rss.reader
|
||||
USING: kernel html namespaces sequences io quotations
|
||||
assocs sqlite.tuple-db sqlite io.files html.elements
|
||||
rss http.server.responders.continuation ;
|
||||
rss webapps.continuation ;
|
||||
|
||||
TUPLE: reader-feed url title link ;
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
USING: kernel furnace sqlite.tuple-db webapps.article-manager.database
|
||||
sequences namespaces math arrays assocs quotations io.files
|
||||
http.server http.basic-authentication http.server.responders
|
||||
http.server.responders.file ;
|
||||
webapps.file ;
|
||||
IN: webapps.article-manager
|
||||
|
||||
: current-site ( -- site )
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
! Copyright (C) 2004 Chris Double.
|
||||
! Copyright (C) 2006 Slava Pestov.
|
||||
! See http://factorcode.org/license.txt for BSD license.
|
||||
USING: html http http.server.responders io kernel math namespaces
|
||||
prettyprint continuations random system sequences assocs ;
|
||||
IN: http.server.responders.callback
|
||||
USING: html http http.server.responders io kernel math
|
||||
namespaces prettyprint continuations random system sequences
|
||||
assocs ;
|
||||
IN: webapps.callback
|
||||
|
||||
#! Name of the variable holding the continuation used to exit
|
||||
#! back to the httpd responder.
|
|
@ -2,7 +2,7 @@
|
|||
! See http://factorcode.org/license.txt for BSD license.
|
||||
USING: namespaces kernel assocs io.files combinators
|
||||
arrays io.launcher io http.server http.server.responders
|
||||
http.server.responders.file sequences strings ;
|
||||
webapps.file sequences strings ;
|
||||
IN: webapps.cgi
|
||||
|
||||
SYMBOL: cgi-root
|
||||
|
@ -67,4 +67,6 @@ SYMBOL: cgi-root
|
|||
{ [ t ] [ (do-cgi) ] }
|
||||
} cond ;
|
||||
|
||||
"cgi" [ "argument" get do-cgi ] add-simple-responder
|
||||
global [
|
||||
"cgi" [ "argument" get do-cgi ] add-simple-responder
|
||||
] bind
|
||||
|
|
|
@ -2,9 +2,9 @@
|
|||
! See http://factorcode.org/license.txt for BSD license.
|
||||
|
||||
USING: http math namespaces io strings kernel html html.elements
|
||||
hashtables continuations quotations parser generic
|
||||
sequences http.server.responders.callback http.server.responders ;
|
||||
IN: http.server.responders.continuation
|
||||
hashtables continuations quotations parser generic sequences
|
||||
webapps.callback http.server.responders ;
|
||||
IN: webapps.continuation
|
||||
|
||||
#! Used inside the session state of responders to indicate whether the
|
||||
#! next request should use the post-refresh-get pattern. It is set to
|
||||
|
@ -39,31 +39,31 @@ SYMBOL: current-show
|
|||
#! recalls itself when the continuation is called to ensure that
|
||||
#! it resets its value back to the most recent show call.
|
||||
[ ( 0 -- )
|
||||
[ ( 0 1 -- )
|
||||
current-show set ( 0 -- )
|
||||
continue
|
||||
] callcc1 ! 0 [ ] ==
|
||||
nip
|
||||
restore-request
|
||||
call
|
||||
store-current-show
|
||||
[ ( 0 1 -- )
|
||||
current-show set ( 0 -- )
|
||||
continue
|
||||
] callcc1
|
||||
nip
|
||||
restore-request
|
||||
call
|
||||
store-current-show
|
||||
] callcc0 restore-request ;
|
||||
|
||||
: redirect-to-here ( -- )
|
||||
#! Force a redirect to the client browser so that the browser
|
||||
#! goes to the current point in the code. This forces an URL
|
||||
#! change on the browser so that refreshing that URL will
|
||||
#! immediately run from this code point. This prevents the
|
||||
#! "this request will issue a POST" warning from the browser
|
||||
#! and prevents re-running the previous POST logic. This is
|
||||
#! known as the 'post-refresh-get' pattern.
|
||||
post-refresh-get? get [
|
||||
[
|
||||
>callable t register-callback forward-to-url
|
||||
] callcc0 restore-request
|
||||
] [
|
||||
t post-refresh-get? set
|
||||
] if ;
|
||||
#! Force a redirect to the client browser so that the browser
|
||||
#! goes to the current point in the code. This forces an URL
|
||||
#! change on the browser so that refreshing that URL will
|
||||
#! immediately run from this code point. This prevents the
|
||||
#! "this request will issue a POST" warning from the browser
|
||||
#! and prevents re-running the previous POST logic. This is
|
||||
#! known as the 'post-refresh-get' pattern.
|
||||
post-refresh-get? get [
|
||||
[
|
||||
>callable t register-callback forward-to-url
|
||||
] callcc0 restore-request
|
||||
] [
|
||||
t post-refresh-get? set
|
||||
] if ;
|
||||
|
||||
: (show) ( quot -- hashtable )
|
||||
#! See comments for show. The difference is the
|
||||
|
@ -102,7 +102,7 @@ SYMBOL: current-show
|
|||
#! use is an optimisation to save having to generate and save a continuation
|
||||
#! in that special case.
|
||||
#! 'quot' has stack effect ( -- ).
|
||||
[ serving-html ] swap append (show-final) ;
|
||||
[ serving-html ] swap compose (show-final) ;
|
||||
|
||||
#! Name of variable for holding initial continuation id that starts
|
||||
#! the responder.
|
||||
|
@ -141,30 +141,6 @@ SYMBOL: root-callback
|
|||
root-callback set
|
||||
] make-responder ;
|
||||
|
||||
: simple-page ( title quot -- )
|
||||
#! Call the quotation, with all output going to the
|
||||
#! body of an html page with the given title.
|
||||
<html>
|
||||
<head> <title> swap write </title> </head>
|
||||
<body> call </body>
|
||||
</html> ;
|
||||
|
||||
: styled-page ( title stylesheet-quot quot -- )
|
||||
#! Call the quotation, with all output going to the
|
||||
#! body of an html page with the given title. stylesheet-quot
|
||||
#! is called to generate the required stylesheet.
|
||||
<html>
|
||||
<head>
|
||||
<title> rot write </title>
|
||||
swap call
|
||||
</head>
|
||||
<body> call </body>
|
||||
</html> ;
|
||||
|
||||
: paragraph ( str -- )
|
||||
#! Output the string as an html paragraph
|
||||
<p> write </p> ;
|
||||
|
||||
: show-message-page ( message -- )
|
||||
#! Display the message in an HTML page with an OK button.
|
||||
[
|
||||
|
@ -173,19 +149,3 @@ SYMBOL: root-callback
|
|||
<a =href a> "OK" write </a>
|
||||
] simple-page
|
||||
] show 2drop ;
|
||||
|
||||
: vertical-layout ( list -- )
|
||||
#! Given a list of HTML components, arrange them vertically.
|
||||
<table>
|
||||
[ <tr> <td> call </td> </tr> ] each
|
||||
</table> ;
|
||||
|
||||
: horizontal-layout ( list -- )
|
||||
#! Given a list of HTML components, arrange them horizontally.
|
||||
<table>
|
||||
<tr "top" =valign tr> [ <td> call </td> ] each </tr>
|
||||
</table> ;
|
||||
|
||||
: button ( label -- )
|
||||
#! Output an HTML submit button with the given label.
|
||||
<input "submit" =type =value input/> ;
|
|
@ -22,10 +22,11 @@
|
|||
! ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
!
|
||||
! Simple test applications
|
||||
USING: hashtables html kernel io html html.elements strings math assocs quotations
|
||||
http.server.responders.continuation namespaces prettyprint sequences ;
|
||||
USING: hashtables html kernel io html html.elements strings math
|
||||
assocs quotations webapps.continuation namespaces prettyprint
|
||||
sequences ;
|
||||
|
||||
IN: http.server.responders.continuation.examples
|
||||
IN: webapps.continuation.examples
|
||||
|
||||
: display-page ( title -- )
|
||||
#! Display a page with some text to test the cont-responder.
|
|
@ -5,7 +5,7 @@ http.server.responders http.server.templating namespaces parser
|
|||
sequences strings assocs hashtables debugger http.mime sorting
|
||||
html.elements ;
|
||||
|
||||
IN: http.server.responders.file
|
||||
IN: webapps.file
|
||||
|
||||
: serving-path ( filename -- filename )
|
||||
"" or "doc-root" get swap path+ ;
|
|
@ -4,7 +4,7 @@
|
|||
USING: kernel furnace fjsc parser-combinators namespaces
|
||||
lazy-lists io io.files furnace.validator sequences
|
||||
http.client http.server http.server.responders
|
||||
http.server.responders.file ;
|
||||
webapps.file ;
|
||||
IN: webapps.fjsc
|
||||
|
||||
: compile ( code -- )
|
||||
|
|
|
@ -31,10 +31,10 @@
|
|||
! to use HTML. The remaining code was untouched.
|
||||
!
|
||||
! The result is not that pretty but it shows the basic idea.
|
||||
USING: kernel math parser html html.elements io namespaces math.parser
|
||||
random http.server.responders.continuation ;
|
||||
USING: kernel math parser html html.elements io namespaces
|
||||
math.parser random webapps.continuation ;
|
||||
|
||||
IN: http.server.responders.continuation.examples.numbers
|
||||
IN: webapps.numbers
|
||||
|
||||
: web-print ( str -- )
|
||||
#! Display the string in a web page.
|
Loading…
Reference in New Issue