[ginseng-cvs] CVS ginseng/examples
wchunye
wchunye at common-lisp.net
Mon Aug 9 12:27:25 UTC 2010
Update of /project/ginseng/cvsroot/ginseng/examples
In directory cl-net:/tmp/cvs-serv29557/examples
Added Files:
.cvsignore app-inc-counter.lisp hello-world.lisp index.lisp
package.lisp sum-of.lisp
Log Message:
initial version.
--- /project/ginseng/cvsroot/ginseng/examples/.cvsignore 2010/08/09 12:27:25 NONE
+++ /project/ginseng/cvsroot/ginseng/examples/.cvsignore 2010/08/09 12:27:25 1.1
*.wx32fsl
*.fasl--- /project/ginseng/cvsroot/ginseng/examples/app-inc-counter.lisp 2010/08/09 12:27:25 NONE
+++ /project/ginseng/cvsroot/ginseng/examples/app-inc-counter.lisp 2010/08/09 12:27:25 1.1
(in-package :ginseng-examples)
(defun http-inc-counter(&optional (next-action nil))
(invoke-next-action next-action #'(lambda () (inc-counter-main 0))))
(defun inc-counter-main (counter)
(yaclml:with-yaclml-output-to-string
(<:html
(<:head
(<:title "Hello World"))
(<:body
(<:h1 "Hello" )
(<:form :action (dynamic-url (inc-counter-main (1+ counter)))
(<:p (<:as-html counter))
(<:input :type "submit" :value "OK"))
;; (iter (for (k v) in-hashtable *k*)
;; (<:p (<:as-html k)))
))))
(defun http-counter(&optional (next-action nil))
(invoke-next-action next-action #'(lambda () (counter-main 0))))
(defun counter-main (counter)
(yaclml:with-yaclml-output-to-string
(<:html
(<:head
(<:title "Hello World"))
(<:body
(<:h1 "Hello" )
(<:p (<:as-html counter))
(<:br)
(<:a :href (dynamic-url (counter-main (1+ counter))) "++")
(<:as-html " ")
(<:a :href (dynamic-url (counter-main (1- counter))) "--")
))))
(defun http-add-two-numbers (&optional (next-action nil))
(invoke-next-action next-action #'(lambda () (add-two-numbers-main))))
(defun add-two-numbers-main ()
(yaclml:with-yaclml-output-to-string
(<:html
(<:head
(<:title "Add two number"))
(<:body
(<:h1 "Please input the first number:")
(let ((cf (make-callback-factory))
(first-number 0))
(<:form :action (dynamic-url
(apply-callbacks cf)
(input-next-number first-number))
(<:input :type :text
:name (create-callback cf
#'(lambda (v) (setq first-number v))
:type 'integer))
))))))
(defun input-next-number(first-number)
(yaclml:with-yaclml-output-to-string
(<:html
(<:head
(<:title "Add two number"))
(<:body
(<:h1 (<:as-html "Add to " first-number "."
" Please input the second number:"))
(let ((cf (make-callback-factory))
(second-number 0))
(<:form :action (dynamic-url
(apply-callbacks cf)
(add-the-two-numbers first-number second-number))
(<:input :type :text
:name (create-callback cf
#'(lambda (v) (setq second-number v))
:type 'integer))
))))))
(defun add-the-two-numbers ( a b )
(yaclml:with-yaclml-output-to-string
(<:html
(<:head
(<:title "Add two number"))
(<:body
(<:as-html
a "+" b "=" (+ a b) )
(<:br)
(<:a :href (relative-url-to-app) "try again")
))))--- /project/ginseng/cvsroot/ginseng/examples/hello-world.lisp 2010/08/09 12:27:25 NONE
+++ /project/ginseng/cvsroot/ginseng/examples/hello-world.lisp 2010/08/09 12:27:25 1.1
(in-package :ginseng-examples)
;; this is the first example of using Ginseng. To create a simple
;; dynamic web page, it is nothing more than a function.
;;
;; for example, if you access
;; http://localhost:4242/cgi-bin/ginseng-examples/hello-world/arg1/arg2
;;
;; the function "http-hello-world" in package "ginseng-examples" is
;; invoked with arguments, "arg1" and "arg2", etc. The function must
;; return a string as an HTML page.
;;
;; "/cgi-bin" is the ginseng prefix, you can change
;; ginseng::*ginseng-prefix* to change the prefix.
(defun http-hello-world(&rest args)
(with-yaclml-output-to-string
(<:html
(<:head
(<:title "Hello World"))
(<:body
(<:h1 "Hello World")
(<:p
"input arguments are:"
(<:ol
(dolist (arg args)
(<:li (<:as-html arg)))
))))))
--- /project/ginseng/cvsroot/ginseng/examples/index.lisp 2010/08/09 12:27:25 NONE
+++ /project/ginseng/cvsroot/ginseng/examples/index.lisp 2010/08/09 12:27:25 1.1
(in-package :ginseng-examples)
(defun http-index (&rest args)
(declare (ignore args))
(let* ((packages (list-all-packages))
list-of-functions)
(iter (for package in packages)
(iter (for s in-package package)
(if (and
(fboundp s)
(eq (symbol-package s) package)
(equal 0 (search "HTTP-" (symbol-name s))))
(push (cons package s) list-of-functions))))
(with-yaclml-output-to-string
(<:html
(<:head
(<:title "list of apps"))
(<:body
(<:h1 "list of apps")
(<:ol
(iter
(for (package . func) in list-of-functions)
(let ((s (subseq (symbol-name func) (length "HTTP-"))))
(<:li
(<:a :href (concatenate 'string
ginseng::*ginseng-prefix* "/"
(package-name package) "/"
s)
(<:as-html (concatenate 'string (package-name package) "/" s))))))))))))
--- /project/ginseng/cvsroot/ginseng/examples/package.lisp 2010/08/09 12:27:25 NONE
+++ /project/ginseng/cvsroot/ginseng/examples/package.lisp 2010/08/09 12:27:25 1.1
(in-package :cl-user)
(defpackage :ginseng-examples
(:use :cl :hunchentoot :iterate :yaclml :ginseng))
--- /project/ginseng/cvsroot/ginseng/examples/sum-of.lisp 2010/08/09 12:27:25 NONE
+++ /project/ginseng/cvsroot/ginseng/examples/sum-of.lisp 2010/08/09 12:27:25 1.1
(in-package :ginseng-examples)
(defun http-sum-of(&rest args)
(with-yaclml-output-to-string
(<:html
(<:head
(<:title "Sum of numbers"))
(<:body
(<:h1 "Sum of numbers")
(<:p
(<:as-html (format nil "~{~A~^+~}" args) "="
(apply #'+
(mapcar #'(lambda (x)
(or
(parse-integer x
:junk-allowed t)
0))
args))))))))
More information about the ginseng-cvs
mailing list