;;;; -*- lisp -*- (in-package #:ucw-user) (defvar *example-server* (make-instance 'standard-server)) ;;;; The definiton of the example application (defclass example-application (static-roots-application-mixin tal-application-mixin standard-application) ()) (defvar *wwwroot* (merge-pathnames #P"examples/wwwroot/" (asdf:component-pathname (asdf:find-system :ucw)))) (defvar *example-application* (make-instance 'example-application :url-prefix "/" :tal-generator (make-instance 'yaclml:file-system-generator :cachep t :root-directories (list (merge-pathnames #P"tal/" *wwwroot*))) :debug-on-error t :static-roots (list (cons "static/" (merge-pathnames #P"static/" *wwwroot*))))) ;;;; define the window component (defcomponent example-window (standard-window-component) () (:default-initargs :title "UCW Examples" :stylesheet (list "static/ucw.css" "static/examples.css") :body (make-instance 'tabbed-pane :current-component-key 'example-welcome :contents `((example-welcome . ,(make-instance 'example-welcome)) (multiplication-table . ,(make-instance 'multiplication-table)) (counter . ,(make-instance 'counter)) (sum . ,(make-instance 'sum)) (wiki . ,(make-instance 'wiki-viewer :page-name "WelcomePage")) ;(file-upload-example . ,(make-instance 'file-upload-example)) ;(timeout-cache-example . ,(make-instance 'timeout-cache-example :timeout 10)) ;(hits-cache-example . ,(make-instance 'hits-cache-example :timeout 5)) ))) (:documentation "The main window component for the example application. This component contains the list of all the available components and simply wraps the rendering of the current component with the navigation bar.")) (defentry-point "^(index.ucw|)$" (:application *example-application* :class regexp-dispatcher) () (call 'example-window)) (defentry-point "mul.ucw" (:application *example-application* :class simple-dispatcher :with-call/cc nil :action-options (:class 'action)) () (mul-table-example)) (defentry-point "mul-direct.ucw" (:application *example-application* :class minimal-dispatcher :with-call/cc nil :action-options (:class 'action)) () (direct-mul-table-example)) (defcomponent example-welcome (html-block-element-mixin) () (:documentation "The first page seen by the example app. This component does nothing other than render a litte introductory text.") (:render () (<:h1 "UCW Examples") (<:p (<:as-html "Click on a link to try a demo.")))) (defcomponent multiplication-table (html-block-element-mixin) () (:documentation "Just show a few links to mul.ucw / mul-direct.ucw") (:render () (<:h1 "Multiplication Table Examples") (<:ul (<:li (<:p (<:a :href "mul.ucw" "YACLML Multiplication table"))) (<:li (<:p (<:a :href "direct-mul.ucw" "Direct Stream Writing Multiplication table")))))) ;;;; multiplication table (defun mul-table-example () (yaclml:with-yaclml-stream (html-stream (context.response *context*)) (with-request-params (n) (context.request *context*) (let ((n (if n (or (parse-integer n :junk-allowed t) 0) 0))) (<:html (<:head (<:title "Multiplication table")) (<:body (<:a :href "index.ucw" "Go Back to Main Demo") (<:h1 "Multiplication table upto " (<:ah n)) (<:form :action "" :method "GET" (<:p "N: " (<:input :type "text" :name "n") (<:input :type "submit" :value "Calculate"))) (<:table (<:tr (<:th) (loop for i from 1 to n do (<:th (<:ah i)))) (loop for i from 1 to n do (<:tr (<:th (<:ah i)) (loop for j from 1 to n do (<:td (<:ah (* i j))))))))))))) (defun direct-mul-table-example () ;; just like the above example but write directly to the client ;; stream. you can usually tell the difference if N is large. (send-headers (context.response *context*)) (with-request-params (n) (context.request *context*) (let ((n (if n (or (parse-integer n :junk-allowed t) 0) 0))) (flet ((send-string (&rest strings) (let ((network-stream (ucw::network-stream (context.response *context*)))) (dolist (string strings) (write-sequence (string-to-octets (if (stringp string) string (princ-to-string string)) :us-ascii) network-stream)) (write-sequence +CR-LF+ network-stream)))) ;; we can't use YACLML here since the respons'se network stream is an (unsigned-byte 8) stream. (send-string "") (send-string "
") (loop for i from 1 to n do (send-string " | " i " | ")) (send-string "
---|---|
" i " | ") do (loop for j from 1 to n do (send-string "" (* i j) " | ")) do (send-string "