From thomas.karolski at googlemail.com Mon Jun 1 00:49:31 2009 From: thomas.karolski at googlemail.com (Thomas) Date: Mon, 01 Jun 2009 02:49:31 +0200 Subject: [bknr-devel] xhtmlgen Message-ID: <4A23259B.8080100@googlemail.com> Hi, how can I get xhtmlgen to accept (:label :for "name")? From hans.huebner at gmail.com Mon Jun 1 05:39:53 2009 From: hans.huebner at gmail.com (=?ISO-8859-1?Q?Hans_H=FCbner?=) Date: Mon, 1 Jun 2009 07:39:53 +0200 Subject: [bknr-devel] xhtmlgen In-Reply-To: <4A23259B.8080100@googlemail.com> References: <4A23259B.8080100@googlemail.com> Message-ID: This works for me: CL-USER> (html ((:form :action "post") ((:label :for "abc") "abc:") ((:input :name "abc"))))
-Hans On Mon, Jun 1, 2009 at 02:49, Thomas wrote: > Hi, > > how can I get xhtmlgen to accept (:label :for "name")? > > _______________________________________________ > bknr-devel mailing list > bknr-devel at common-lisp.net > http://common-lisp.net/cgi-bin/mailman/listinfo/bknr-devel > From thomas.karolski at googlemail.com Mon Jun 1 20:02:48 2009 From: thomas.karolski at googlemail.com (Thomas) Date: Mon, 01 Jun 2009 22:02:48 +0200 Subject: [bknr-devel] xhtmlgen In-Reply-To: References: <4A23259B.8080100@googlemail.com> Message-ID: <4A2433E8.9050802@googlemail.com> Hans H?bner schrieb: > This works for me: > > CL-USER> (html ((:form :action "post") > ((:label :for "abc") "abc:") > ((:input :name "abc")))) >
Ah ok, thanks. I guess this is different syntax wise from what I expected. I would love to try this out, but I got stuck with with-bknr-page. How come this does not work: (defmethod handle-form ((handler register-handler) action) (lambda () (with-bknr-page (:title "Test") ((:form :id "test")))) I merely get a page with the basic xhtml header but no content. Is with-bknr-page not supposed to be used here? From hans.huebner at gmail.com Mon Jun 1 20:29:40 2009 From: hans.huebner at gmail.com (=?ISO-8859-1?Q?Hans_H=FCbner?=) Date: Mon, 1 Jun 2009 22:29:40 +0200 Subject: [bknr-devel] xhtmlgen In-Reply-To: <4A2433E8.9050802@googlemail.com> References: <4A23259B.8080100@googlemail.com> <4A2433E8.9050802@googlemail.com> Message-ID: On Mon, Jun 1, 2009 at 22:02, Thomas wrote: > How come this does not work: > (defmethod handle-form ((handler register-handler) action) > ?(lambda () > ? ?(with-bknr-page (:title "Test") > ? ? ?((:form :id "test")))) > > I merely get a page with the basic xhtml header but no content. Is > with-bknr-page not supposed to be used here? BKNR handlers do not return a closure. Please have a look into the existing project source code in order to find some examples of how BKNR handlers work. It is unfortunate that there is no documentation, and I regret not having any time to add some. I'd recommend that you use another web framework if you are unable to work yourself through the source. -Hans From thomas.karolski at googlemail.com Mon Jun 1 21:42:36 2009 From: thomas.karolski at googlemail.com (Thomas) Date: Mon, 01 Jun 2009 23:42:36 +0200 Subject: [bknr-devel] xhtmlgen In-Reply-To: References: <4A23259B.8080100@googlemail.com> <4A2433E8.9050802@googlemail.com> Message-ID: <4A244B4C.8040103@googlemail.com> Hans H?bner wrote: > BKNR handlers do not return a closure. Please have a look into the > existing project source code in order to find some examples of how > BKNR handlers work. It is unfortunate that there is no documentation, > and I regret not having any time to add some. I'd recommend that you > use another web framework if you are unable to work yourself through > the source. Yes I noticed its different in the examples and bknr source code. However unless I return a function object, I get error pages like this: The value " " is not of type (OR FUNCTION SYMBOL). So I figured I ought to try returning a function. Anyway, I appreciate the heads up - though as I don't really know of any other web framework, I might just as well stick with BKNR. I'll try to figure out how it works by doing some code digging. Kind regards, Thomas From hans.huebner at gmail.com Tue Jun 2 03:31:12 2009 From: hans.huebner at gmail.com (=?ISO-8859-1?Q?Hans_H=FCbner?=) Date: Tue, 2 Jun 2009 05:31:12 +0200 Subject: [bknr-devel] xhtmlgen In-Reply-To: <4A244B4C.8040103@googlemail.com> References: <4A23259B.8080100@googlemail.com> <4A2433E8.9050802@googlemail.com> <4A244B4C.8040103@googlemail.com> Message-ID: On Mon, Jun 1, 2009 at 23:42, Thomas wrote: > Yes I noticed its different in the examples and bknr source code. > However unless I return a function object, I get error pages like this: > > The value " > > " > is not of type > ?(OR FUNCTION SYMBOL). That propably is because you're not using BKNR's request dispatcher. Have a look at projects/lisp-ecoop/src/webserver.lisp. In the function START-WEBSERVER, Hunchentoot is initialized with a :REQUEST-DISPATCHER argument of 'BKNR.WEB:BKNR-DISPATCH. -Hans From thomas.karolski at googlemail.com Tue Jun 2 19:16:25 2009 From: thomas.karolski at googlemail.com (Thomas) Date: Tue, 02 Jun 2009 21:16:25 +0200 Subject: [bknr-devel] xhtmlgen In-Reply-To: References: <4A23259B.8080100@googlemail.com> <4A2433E8.9050802@googlemail.com> <4A244B4C.8040103@googlemail.com> Message-ID: <4A257A89.1020206@googlemail.com> Hans H?bner schrieb: > That propably is because you're not using BKNR's request dispatcher. > Have a look at projects/lisp-ecoop/src/webserver.lisp. In the > function START-WEBSERVER, Hunchentoot is initialized with a > :REQUEST-DISPATCHER argument of 'BKNR.WEB:BKNR-DISPATCH. Ah - I saw that publish-site pushed that exact dispatcher into the *dispatch-table* so I didn't think of invoking hunchentoot's acceptor with it. Now that works - it even fixed a problem I had with the template handler. Great! I'm actually going through some of the BKNR functions I encounter on a daily basis and document them here and there. If you are like, interested at all in having some basic documentation on some of your functions, then I could post a diff. Kind Regards, Thomas K. From thomas.karolski at googlemail.com Tue Jun 2 20:57:06 2009 From: thomas.karolski at googlemail.com (Thomas) Date: Tue, 02 Jun 2009 22:57:06 +0200 Subject: [bknr-devel] Automatic HTML Indentation Message-ID: <4A259222.4050303@googlemail.com> I noticed that with-xhtml warns about the INDENTATION parameter being deprecated. According to the cxml documentation (on their website anyway) cxml:make-character-stream-sink still takes that parameter - and actually passing it does seem to work. Is there some other method of enforcing (x)html indentation (including newlines) or do I have to go with hacking a global variable *html-indentation* into xhtmlgen.lisp in order to get it to work? On a side note: How come the HTML function is not exported from within BKNR.web? Isn't it an integral part of using the BKNR.web utility functions? Kind regards, Thomas From thomas.karolski at googlemail.com Tue Jun 2 20:47:41 2009 From: thomas.karolski at googlemail.com (Thomas) Date: Tue, 02 Jun 2009 22:47:41 +0200 Subject: [bknr-devel] handler.lisp doc svn diff Message-ID: <4A258FED.20707@googlemail.com> Index: bknr/web/src/web/handlers.lisp =================================================================== --- bknr/web/src/web/handlers.lisp (Revision 4409) +++ bknr/web/src/web/handlers.lisp (Arbeitskopie) @@ -717,7 +717,12 @@ (ensure-directories-exist spool-dir) spool-dir)) -(defmethod website-show-page ((website website) fn title) +(defmethod website-show-page ((website website) fn title) + "Method for generating the code for a normal website page. +This gets called by with-bknr-page, whereas FN is a function with zero parameters +containing the body of a with-bknr-page call. TITLE is the title as specified by a +with-bknr-page call. +Redefine to add your own behavior." (html (:html (:head @@ -733,6 +738,12 @@ (session-info))))) (defmethod website-show-error-page ((website website) error) + "Method for generating the code for an error page. +This gets called by an error handler in case something goes wrong on the server side. +ERROR is a string describing the error which happened. + +Redefine to add your own behavior." (if (and (website-template-handler website) (error-template-pathname (website-template-handler website))) (send-error-response (website-template-handler website) (princ-to-string error)) @@ -747,12 +758,22 @@ (:princ-safe error))))))) (defun show-page-with-error-handlers (fn &key (response +http-ok+) title) + "Sets up the http-response RESPONSE, content-type \"text/html; charset=UTF8\" and the xhtml stream which is used to send +html to the clients. Then calls website-show-page for the current website with the given FN and TITLE." (setf (return-code*) response) (with-http-response (:content-type "text/html; charset=UTF-8" :response response) (with-http-body () (website-show-page *website* fn title)))) (defmacro with-bknr-page ((&rest args) &body body) + "Macro which sets up everything so you can directly write your html code. +ARGS is a property list and can be any of the KEYWORD arguments which can also be given to +show-page-with-error-handlers. Noteworthy in particular are :title and :response. +The BODY will be given to website-show-page as a lambda function. + +Example: + * (with-bknr-page (:title \"Random Page\") + (:p (:princ-safe \"Randomness\"))) " `(show-page-with-error-handlers (lambda () (html , at body)) , at args)) #+(or) @@ -765,5 +786,6 @@ , at body)))))) (defun unpublish () + "Unpublish a website by removing the BKNR dispatcher from the global *dispatch-table*" (setf *dispatch-table* (remove 'bknr-dispatch *dispatch-table*) *handlers* nil)) From hans.huebner at gmail.com Sun Jun 7 05:37:17 2009 From: hans.huebner at gmail.com (=?ISO-8859-1?Q?Hans_H=FCbner?=) Date: Sun, 7 Jun 2009 07:37:17 +0200 Subject: [bknr-devel] handler.lisp doc svn diff In-Reply-To: <4A258FED.20707@googlemail.com> References: <4A258FED.20707@googlemail.com> Message-ID: Thomas, can you please re-send your patch as attachment? When pasted to an email body, it gets garbled enough in the transmission process to not be useable. Thanks, Hans On Tue, Jun 2, 2009 at 22:47, Thomas wrote: > Index: bknr/web/src/web/handlers.lisp > =================================================================== > --- bknr/web/src/web/handlers.lisp ? ?(Revision 4409) > +++ bknr/web/src/web/handlers.lisp ? ?(Arbeitskopie) > @@ -717,7 +717,12 @@ > ? ? (ensure-directories-exist spool-dir) > ? ? spool-dir)) > > -(defmethod website-show-page ((website website) fn title) > +(defmethod website-show-page ((website website) fn title) > + ?"Method for generating the code for a normal website page. > +This gets called by with-bknr-page, whereas FN is a function with zero > parameters > +containing the body of a with-bknr-page call. TITLE is the title as > specified by a > +with-bknr-page call. > +Redefine to add your own behavior." > ? (html > ? ?(:html > ? ? (:head > @@ -733,6 +738,12 @@ > ? ? ?(session-info))))) > > ?(defmethod website-show-error-page ((website website) error) > + ?"Method for generating the code for an error page. > +This gets called by an error handler in case something goes wrong on > the server side. > +ERROR is a string describing the error which happened. > + > +Redefine to add your own behavior." > ? (if (and (website-template-handler website) > ? ? ? ? ? ?(error-template-pathname (website-template-handler website))) > ? ? ? (send-error-response (website-template-handler website) > (princ-to-string error)) > @@ -747,12 +758,22 @@ > ? ? ? (:princ-safe error))))))) > > ?(defun show-page-with-error-handlers (fn &key (response +http-ok+) title) > + ?"Sets up the http-response RESPONSE, content-type \"text/html; > charset=UTF8\" and the xhtml stream which is used to send > +html to the clients. Then calls website-show-page for the current > website with the given FN and TITLE." > ? (setf (return-code*) response) > ? (with-http-response (:content-type "text/html; charset=UTF-8" > :response response) > ? ? (with-http-body () > ? ? ? (website-show-page *website* fn title)))) > > ?(defmacro with-bknr-page ((&rest args) &body body) > + ?"Macro which sets up everything so you can directly write your html code. > +ARGS is a property list and can be any of the KEYWORD arguments which > can also be given to > +show-page-with-error-handlers. Noteworthy in particular are :title and > :response. > +The BODY will be given to website-show-page as a lambda function. > + > +Example: > + * (with-bknr-page (:title \"Random Page\") > + ? ?(:p (:princ-safe \"Randomness\"))) " > ? `(show-page-with-error-handlers (lambda () (html , at body)) , at args)) > > ?#+(or) > @@ -765,5 +786,6 @@ > ? ? ? ? ? ?, at body)))))) > > ?(defun unpublish () > + ?"Unpublish a website by removing the BKNR dispatcher from the global > *dispatch-table*" > ? (setf *dispatch-table* (remove 'bknr-dispatch *dispatch-table*) > ? ? *handlers* nil)) > > _______________________________________________ > bknr-devel mailing list > bknr-devel at common-lisp.net > http://common-lisp.net/cgi-bin/mailman/listinfo/bknr-devel > From thomas.karolski at googlemail.com Tue Jun 9 20:26:07 2009 From: thomas.karolski at googlemail.com (Thomas Karolski) Date: Tue, 09 Jun 2009 22:26:07 +0200 Subject: [bknr-devel] Directory Handler problem Message-ID: <87fxe9p31c.fsf@googlemail.com> Hey there, the directory handler is deleting the first char of every file which is dispatched through it (e.g. "http://localhost/example-3.lisp" accesses "/xample-3.lisp"). I have the following simple example for a directory handler: ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; example-3.lisp --- (defpackage :example-3 (:use :cl :bknr.web :bknr.datastore)) (in-package :example-3) (make-instance 'website :name "My first website" :handler-definitions `(("/" directory-handler :destination #p"/home/thomas/workspace/bknr-examples/"))) (defvar *server* nil) (if *server* (progn ;; Open a store (close-store) (make-instance 'mp-store :directory "store/" :subsystems (list (make-instance 'store-object-subsystem))) ;; Create an anonymous user if none exists yet (unless (bknr.user:find-user "anonymous") (bknr.user:make-user "anonymous")) (hunchentoot:stop *server*) (setf hunchentoot:*show-lisp-errors-p* t) (setf *server* nil)) (setf *server* (hunchentoot:start (make-instance 'hunchentoot:acceptor :port 8080 :request-dispatcher 'bknr.web:bknr-dispatch)))) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; example-3.lisp ends here However, whenever I try to access http://localhost:8080/example-3.lisp (which also resides in the bknr-examples directory as specified in the :directory argument), I get the following error: --------------------------------------------------------------------- Internal Server Error FILES-NOT-FOUND while processing pathnames argument xample-3.lisp, files ("xample-3.lisp") could not be found Hunchentoot 1.0.0 (SBCL 1.0.28) at localhost:8080 --------------------------------------------------------------------- For some reason "example-3.lisp" is truncated down to "xample-3.lisp". I tracked it down to 'request-relative-pathnames' in bknr/web/src/web/handlers.lisp. For some reason pathnames-argument is being let* with: (subseq (script-name*) (1+ (length (page-handler-prefix handler)))) whereas '(script-name*)' returns "/example-3.lisp", and '(page-handler-prefix handler)' returns "/". With (length (page-handler-prefix handler)) being 1 and another 1 being added through 1+ we would get: (subseq "/example-3.lisp" 2) which results in "xsample-3.lisp" instead of "example-3.lisp". In case the 1+ is supposed to be there - what am I doing wrong when initializing the directory handler? Kind regards, Thomas From hans.huebner at gmail.com Tue Jun 9 20:43:40 2009 From: hans.huebner at gmail.com (=?ISO-8859-1?Q?Hans_H=FCbner?=) Date: Tue, 9 Jun 2009 16:43:40 -0400 Subject: [bknr-devel] Directory Handler problem In-Reply-To: <87fxe9p31c.fsf@googlemail.com> References: <87fxe9p31c.fsf@googlemail.com> Message-ID: I think that DIRECTORY-HANDLER does not currently support being mounted under the root directory, basically because it assumes that it can safely strip the first character of the file path or some such. It should not be too hard to fix this by special casing mounts under the root directory, but I currently have no time to do that myself. I'd look at a patch, though. -Hans On Tue, Jun 9, 2009 at 16:26, Thomas Karolski wrote: > Hey there, > the directory handler is deleting the first char of every file which > is dispatched through it (e.g. "http://localhost/example-3.lisp" accesses "/xample-3.lisp"). > I have the following simple example for a directory handler: > > ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; > ;;; example-3.lisp --- > (defpackage :example-3 > ?(:use :cl :bknr.web :bknr.datastore)) > > (in-package :example-3) > > (make-instance 'website > ? ? ? ? ? ? ? ? :name "My first website" > ? ? ? ? ? ? ? ? :handler-definitions `(("/" directory-handler > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? :destination #p"/home/thomas/workspace/bknr-examples/"))) > > (defvar *server* nil) > (if *server* > ? ?(progn > ? ? ?;; Open a store > ? ? ?(close-store) > ? ? ?(make-instance 'mp-store :directory "store/" > ? ? ? ? ? ? ? ? ? ? :subsystems (list (make-instance 'store-object-subsystem))) > ? ? ?;; Create an anonymous user if none exists yet > ? ? ?(unless (bknr.user:find-user "anonymous") > ? ? ? ?(bknr.user:make-user "anonymous")) > ? ? ?(hunchentoot:stop *server*) > ? ? ?(setf hunchentoot:*show-lisp-errors-p* t) > ? ? ?(setf *server* nil)) > ? ?(setf *server* > ? ? ? ? ?(hunchentoot:start (make-instance 'hunchentoot:acceptor :port 8080 :request-dispatcher 'bknr.web:bknr-dispatch)))) > ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; > ;;; example-3.lisp ends here > > However, whenever I try to access http://localhost:8080/example-3.lisp > (which also resides in the bknr-examples directory as specified in the > :directory argument), > I get the following error: > > --------------------------------------------------------------------- > Internal Server Error > > FILES-NOT-FOUND while processing pathnames argument xample-3.lisp, files ("xample-3.lisp") could not be found > > Hunchentoot 1.0.0 (SBCL 1.0.28) at localhost:8080 > --------------------------------------------------------------------- > > For some reason "example-3.lisp" is truncated down to "xample-3.lisp". I > tracked it down to 'request-relative-pathnames' in > bknr/web/src/web/handlers.lisp. > For some reason pathnames-argument is being let* with: > (subseq (script-name*) (1+ (length (page-handler-prefix handler)))) > whereas '(script-name*)' returns "/example-3.lisp", > and '(page-handler-prefix handler)' returns "/". > With (length (page-handler-prefix handler)) being 1 and another 1 being > added through 1+ we would get: > (subseq "/example-3.lisp" 2) > which results in "xsample-3.lisp" instead of "example-3.lisp". > > In case the 1+ is supposed to be there - what am I doing wrong when > initializing the directory handler? > > Kind regards, > Thomas > > _______________________________________________ > bknr-devel mailing list > bknr-devel at common-lisp.net > http://common-lisp.net/cgi-bin/mailman/listinfo/bknr-devel >