Permalink
Browse files

application-handling

  • Loading branch information...
asdr committed Feb 8, 2011
1 parent c82959c commit a1e23c323897fa55c0acfab7a512336d5b6afe32
Showing with 58 additions and 39 deletions.
  1. +19 −0 application-handler.lisp
  2. +2 −0 application-handler.lisp~
  3. +1 −3 template-app/_settings.lisp
  4. +36 −36 url-handler.lisp
View
@@ -0,0 +1,19 @@
+(in-package :easyweb)
+
+(defparameter *application-contexts* nil)
+
+(defstruct (application-context
+ (:conc-name context-))
+ name
+ mappings
+ loaded-p nil)
+
+(defstruct (url-mapping
+ (:conc-name mapping-))
+ uri
+ acceptor-names
+ handler
+ request-method)
+
+(defmacro define-url-patterns (prefix &body body)
+
@@ -0,0 +1,2 @@
+(in-package :easyweb)
+
@@ -9,14 +9,12 @@
;;bound application name as
(let ((easyweb::*application-name* "(% TMPL_VAR APPLICATION_NAME %)"))
- (define-url-patterns "/pap1/"
+ (define-url-patterns "/(% TMPL_VAR APPLICATION_NAME %)/"
((:prefix "") index-page/get)
((:prefix "") index-page/post)
((:absolute "form") form)
((:absolute "argtest") argtest)
((:absolute "template1") template1/get)
((:regex "asdr[0-9]+$") mervecigim))
-
- ;(set-application-loaded easyweb::*application-name*)
)
View
@@ -84,42 +84,41 @@ but not in define-easy-handler macro. So below is that for...
(read-from-string "(&rest argumets &key)"))))
-(defmacro! map-one-url (o!mapping o!prefix o!acceptor-name)
- `(let ((,g!uri (car ,g!mapping)))
- (let ((,g!uri-type (car ,g!uri))
- (,g!uri-content (format nil "~A~A" ,g!prefix (cadr ,g!uri))))
- (let* ((,g!handler (cadr ,g!mapping))
- (,g!handler-name (string ,g!handler))
- (,g!request-method (cond ((eq (search "/get" ,g!handler-name :test #'string-equal)
- (- (length ,g!handler-name) 4))
- :GET)
- ((eq (search "/post" ,g!handler-name :test #'string-equal)
- (- (length ,g!handler-name) 5))
- :POST)
- (t
- :BOTH))))
- (destructuring-bind (none0 arguments &rest rest)
- (get-lambda-list ,g!handler)
- (let ((args (cdr rest))) ;;because the first of rest is &key
- (hunchentoot::define-url-handler (,(gensym) :uri (,g!uri-type . ,g!uri-content)
- :acceptor-names '(,g!acceptor-name)
- :default-request-type ,g!request-method)
- #|,(mapcar #'(lambda (arg)
- (if (listp arg)
- (car arg)
- arg))
- args)|#
- ()
- (funcall ,g!handler #|,@(mapcan #'(lambda (arg)
- (if (listp arg)
- `(,(chunga:as-keyword (string-downcase (car arg))
- :destructivep nil)
- (null-value-check ,(car arg) ,(cadr arg)))
-
- `(,(chunga:as-keyword (string-downcase arg)
- :destructivep nil)
- ,arg)))
- args)|#))))))))
+(defun map-one-url (mapping prefix acceptor-name)
+ (let ((uri (car mapping)))
+ (let ((uri-type (car uri))
+ (uri-content (format nil "~A~A" prefix (cadr uri))))
+ (let* ((handler (cadr mapping))
+ (handler-name (string handler))
+ (request-method (cond ((eq (search "/get" handler-name :test #'string-equal)
+ (- (length handler-name) 4))
+ :GET)
+ ((eq (search "/post" handler-name :test #'string-equal)
+ (- (length handler-name) 5))
+ :POST)
+ (t
+ :BOTH))))
+ (destructuring-bind (none0 arguments &rest rest)
+ (get-lambda-list handler)
+ (let ((args (cdr rest))) ;;because the first of rest is &key
+ `(hunchentoot::define-url-handler (,(gensym) :uri (cons ,uri-type ,uri-content)
+ :acceptor-names (list ,acceptor-name)
+ :default-request-type ,request-method)
+ (mapcar #'(lambda (arg)
+ (if (listp arg)
+ (car arg)
+ arg))
+ args)
+ (funcall ,handler ,@(mapcan #'(lambda (arg)
+ (if (listp arg)
+ `(,(chunga:as-keyword (string-downcase (car arg))
+ :destructivep nil)
+ (null-value-check ,(car arg) ,(cadr arg)))
+
+ `(,(chunga:as-keyword (string-downcase arg)
+ :destructivep nil)
+ ,arg)))
+ args)))))))))
(defmacro! easy-load-application (o!application-name o!acceptor-name)
`(let ((,g!mappings (assoc ,g!application-name *application-mapping-table* :test #'string=)))
@@ -135,3 +134,4 @@ but not in define-easy-handler macro. So below is that for...
`(unless (assoc *application-name* *application-mapping-table* :test #'string=)
(push (cons *application-name* (list ,prefix ',body))
*application-mapping-table*)))
+

0 comments on commit a1e23c3

Please sign in to comment.