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