(Arne Babenhauserheide)
2013-11-24: factored out the comment-server into its own wisp example. factored out the comment-server into its own wisp example.
diff --git a/examples/comment-server.w b/examples/comment-server.w
new file mode 100755
--- /dev/null
+++ b/examples/comment-server.w
@@ -0,0 +1,60 @@
+#!./wisp-multiline.sh
+; !#
+
+use-modules
+ web server
+ web request
+ web response
+ web uri
+ rnrs unicode
+ rnrs bytevectors ; for utf8->string
+
+define : header-html
+ ' : content-type . : text/html
+
+define : show-comments request comments-hash-table
+ let*
+ : path : uri-path : request-uri request
+ uri-components : split-and-decode-uri-path path
+ string-join
+ list "<!DOCTYPE html><html><head><title>Comments</title></head><body><form action='" path "' method='post'>
+ <input type='text' name='comment' />
+ <input type='submit' name='submit' value='Save' />
+</form>"
+ hash-ref comments-hash-table uri-components
+ string-join uri-components
+ . "</body></html>\n"
+
+define : change-comment-content current to-add
+ if current
+ string-join : list "<div class='comment'>" to-add "</div><div class='commentsep'></div>" current
+ string-join : list "<div class='comment'>" to-add "</div>"
+
+define : body->comment request-body
+ let : : request-string : utf8->string request-body
+ substring request-string
+ string-length "comment="
+ string-index request-string #\& ; FIXME: This will break for comments with &. Ignore that: This is just a mockup.
+
+define : add-comment request request-body comments-hash-table
+ let : : uri-components : split-and-decode-uri-path : uri-path : request-uri request
+ hash-set! comments-hash-table uri-components
+ change-comment-content
+ hash-ref comments-hash-table uri-components
+ body->comment request-body
+ show-comments request comments-hash-table
+
+
+define global-comment-hash-table : make-hash-table
+
+define : uri-comment-showing-handler request request-body
+ values
+ header-html
+ if request-body
+ add-comment request request-body global-comment-hash-table
+ show-comments request global-comment-hash-table
+
+display "Server starting. Test it at http://127.0.0.1:8081"
+newline
+
+run-server uri-comment-showing-handler 'http ' : #:port 8081
diff --git a/examples/hello-world-server.w b/examples/hello-world-server.w
--- a/examples/hello-world-server.w
+++ b/examples/hello-world-server.w
@@ -3,19 +3,11 @@
use-modules
web server
- web request
- web response
- web uri
- rnrs unicode
- rnrs bytevectors ; for utf8->string
; first the plain text header
define : header
' : content-type . : text/plain
-define : header-html
- ' : content-type . : text/html
-
; now content building functions
define : timestring
string-join
@@ -45,51 +37,7 @@ define : hello-world-handler request req
header
content
-define : show-comments request comments-hash-table
- let*
- : path : uri-path : request-uri request
- uri-components : split-and-decode-uri-path path
- string-join
- list "<!DOCTYPE html><html><head><title>Comments</title></head><body><form action='" path "' method='post'>
- <input type='text' name='comment' />
- <input type='submit' name='submit' value='Save' />
-</form>"
- hash-ref comments-hash-table uri-components
- string-join uri-components
- . "</body></html>\n"
-
-define : change-comment-content current to-add
- if current
- string-join : list "<div class='comment'>" to-add "</div><div class='commentsep'></div>" current
- string-join : list "<div class='comment'>" to-add "</div>"
-
-define : body->comment request-body
- let : : request-string : utf8->string request-body
- substring request-string
- string-length "comment="
- string-index request-string #\& ; FIXME: This will break for comments with &. Ignore that: This is just a mockup.
-
-define : add-comment request request-body comments-hash-table
- let : : uri-components : split-and-decode-uri-path : uri-path : request-uri request
- hash-set! comments-hash-table uri-components
- change-comment-content
- hash-ref comments-hash-table uri-components
- body->comment request-body
- show-comments request comments-hash-table
-
-
-define global-comment-hash-table : make-hash-table
-
-define : uri-comment-showing-handler request request-body
- values
- header-html
- if request-body
- add-comment request request-body global-comment-hash-table
- show-comments request global-comment-hash-table
-
display "Server starting. Test it at http://127.0.0.1:8081"
newline
-; run-server hello-world-handler 'http ' : #:port 8081
-
-run-server uri-comment-showing-handler 'http ' : #:port 8081
+run-server hello-world-handler 'http ' : #:port 8081