Permalink
Browse files

rearrange packages...

  • Loading branch information...
1 parent 6339616 commit e2fce1019cea207858c6a670d080505332ff4b5b asdr the admin committed Jan 29, 2011
Showing with 125 additions and 108 deletions.
  1. +3 −3 defpackage.lisp
  2. +4 −3 easyweb.asd
  3. +19 −64 easyweb.lisp
  4. +3 −0 initialize.lisp
  5. +2 −2 project-util.lisp
  6. +11 −4 server.lisp
  7. +3 −16 settings.lisp
  8. +74 −2 url-handler.lisp
  9. +6 −14 util.lisp
View
@@ -1,11 +1,11 @@
(in-package :common-lisp-user)
(defpackage :easyweb
- (:use #:cl
- #:easyweb.util
- #:hunchentoot)
+ (:use #:cl)
(:export #:make-project
#:defview
#:define-url-patterns
#:server-start
#:server-stop))
+
+(in-package :easyweb)
View
@@ -9,12 +9,13 @@
:name "easyweb"
:serial t
:depends-on (#:dsgner
+ #:swank
#:hunchentoot
#:html-template)
- :components ((:file "util")
- (:file "url-handler") ;;url-handling and dispatching for hunchentoot
- (:file "defpackage")
+ :components ((:file "defpackage")
+ (:file "util")
(:file "settings")
+ (:file "url-handler")
(:file "server")
(:file "easyweb")
(:file "project-util")
View
@@ -1,70 +1,25 @@
(in-package :easyweb)
-(defun get-lambda-list (fn)
- ;;may be platform dependent code
- ;;but i still need it
- ;;returns the parameter list of given function
- (let ((ns (dsgner::empty-string))
- (lambda-list nil))
- (with-output-to-string (stream ns)
- (let ((*standard-output* stream))
- (describe fn)))
- (with-input-from-string (str ns)
- (do ((line (read-line str nil 'eof) (read-line str nil 'eof)))
- ((eq line 'eof) lambda-list)
- (let ((start (search "Lambda-list: " line :test #'string=)))
- (when start
- (setf lambda-list (subseq line (+ start
- (length "Lambda-list: "))))))))
- (if (search "(&REST ARGUMENTS &KEY " lambda-list :test #'string=)
- (read-from-string lambda-list)
- (read-from-string "(&rest argumets &key)"))))
-
+(defun quickload-available-applications ()
+ (dolist (application easyweb.settings:*available-applications*)
+ (when (and application
+ (null (cdr application)))
+
+ ;; causes recursive infinite loop
+ ;; i should find another solution
+ ;;quicklisp-loading
+ ;;(ql:quickload (car application)))))
+ ))
+ t)
-(defun handle-mapping (mapping prefix)
- (let* ((uri (car mapping))
- (uri-type (car uri))
- (uri-content (format nil "~A~A" prefix (cadr uri)))
- (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
- `(define-url-handler (,(gensym) :uri ,(cons uri-type uri-content) :default-request-type ,request-method)
- ,(mapcar #'(lambda(arg)
- (if (listp arg)
- (car arg)
- arg))
- args)
- (,handler ,@(mapcan #'(lambda (arg)
- (if (listp arg)
- `(,(chunga:as-keyword (string-downcase (car arg)) :destructivep nil) (escape-for-html (null-value-check ,(car arg) ,(cadr arg))))
- `(,(chunga:as-keyword (string-downcase arg) :destructivep nil) (escape-for-html ,arg))))
- args)))))))
-
-
-(defmacro map-url-patterns (prefix &body body)
- `(progn ,@(mapcar #'(lambda(mapping)
- (funcall #'handle-mapping mapping prefix))
- body)))
-
-(defmacro define-url-patterns (prefix &body body)
- (let ((application/g! (gensym)))
- `(let ((,application/g! (find *application-name*
- easyweb.settings:*available-applications*
- :test #'string=
- :key #'car)))
- (when ,application/g! ;;application is in available applications alist
- (unless (cdr ,application/g!) ;; application is not loaded yet
- (map-url-patterns ,prefix ,@body))))))
+(defun set-application-loaded (application-name)
+ (let ((application (find application-name
+ easyweb.settings:*available-applications*
+ :test #'string=
+ :key #'car)))
+ (when application
+ (setf (cdr application)
+ (cons t nil)))))
(defmacro defview (name inner-args (&rest arguments) &body body)
`(progn
View
@@ -6,3 +6,6 @@
;;set our new dispatcher to hunchentoot
(setf hunchentoot:*dispatch-table* (list #'hunchentoot:dispatch-url-handlers))
+
+;;load available applications
+(quickload-available-applications )
View
@@ -6,7 +6,7 @@
("_view" . "lisp")
("template-app" . "asd")))
-(defvar *easyweb-template-application-dir* "/home/asdr/projects/easyweb/template-app")
+(defvar *easyweb-template-application-dir* "/home/admin-o/pjs/easyweb/template-app")
(defun write-from-template (in out variables)
(let ((template-printer (html-template:create-template-printer in)))
@@ -64,4 +64,4 @@
:directory path
:name name
:type type))))
- (clone-file if-path of-path :application_name project-name))))))))
+ (clone-file if-path of-path :application_name project-name))))))))
View
@@ -4,12 +4,19 @@
(defparameter *listen-port* 8000)
+(defparameter *httpd* nil)
+
+(defparameter *swank-port* 4991)
+
+(defparameter *swank* nil)
+
(defun server-start (&key (port *listen-port*) (address *listen-address*))
- (defparameter *httpd* (hunchentoot:start (make-instance 'hunchentoot:acceptor
- :port port
- :name "easyweb-default-acceptor"
- #|:address address|#))))
+ (setf *httpd* (hunchentoot:start (make-instance 'hunchentoot:acceptor
+ :port port
+ :name "easyweb-default-acceptor"
+ #|:address address|#))))
(defun server-stop ()
(hunchentoot:stop *httpd*)
(setf *httpd* nil))
+
View
@@ -5,19 +5,6 @@
(:export #:*available-applications*
#:*template-directory*))
-(in-package :easyweb)
-
-(defun set-application-loaded (application-name)
- (let ((application (find application-name
- easyweb.settings:*available-applications*
- :test #'string=
- :key #'car)))
- (when application
- (setf (cdr application)
- (cons t nil)))))
-
-(cl:export 'set-application-loaded)
-
(in-package :easyweb.settings)
(defparameter *template-directory* "template")
@@ -32,9 +19,9 @@
(defparameter *use-available-check* nil)
(defparameter *available-applications*
- (vector '("test3" . nil)
- '("easyweb-default" . nil)
- '("prototype-app1" . nil)))
+ '(("test10" . nil)))
+ ;'("easyweb-default" . nil)
+ ;'("prototype-app1" . nil)))
View
@@ -54,5 +54,77 @@ but not in define-easy-handler macro. So below is that for...
default-request-type)))
,@body))))
-(export 'dispatch-url-handlers)
-(export 'define-url-handler)
+(cl:export 'dispatch-url-handlers)
+(cl:export 'define-url-handler)
+#| ---------------------------------------------------------------------------------- |#
+
+
+(in-package :easyweb)
+
+(defun get-lambda-list (fn)
+ ;;may be platform dependent code
+ ;;but i still need it
+ ;;returns the parameter list of given function
+ (let ((ns (dsgner::empty-string))
+ (lambda-list nil))
+ (with-output-to-string (stream ns)
+ (let ((*standard-output* stream))
+ (describe fn)))
+ (with-input-from-string (str ns)
+ (do ((line (read-line str nil 'eof) (read-line str nil 'eof)))
+ ((eq line 'eof) lambda-list)
+ (let ((start (search "Lambda-list: " line :test #'string=)))
+ (when start
+ (setf lambda-list (subseq line (+ start
+ (length "Lambda-list: "))))))))
+ (if (search "(&REST ARGUMENTS &KEY " lambda-list :test #'string=)
+ (read-from-string lambda-list)
+ (read-from-string "(&rest argumets &key)"))))
+
+
+(defun handle-mapping (mapping prefix)
+ (let* ((uri (car mapping))
+ (uri-type (car uri))
+ (uri-content (format nil "~A~A" prefix (cadr uri)))
+ (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) :default-request-type ,request-method)
+ ,(mapcar #'(lambda(arg)
+ (if (listp arg)
+ (car arg)
+ arg))
+ args)
+ (,handler ,@(mapcan #'(lambda (arg)
+ (if (listp arg)
+ `(,(chunga:as-keyword (string-downcase (car arg)) :destructivep nil) (escape-for-html (null-value-check ,(car arg) ,(cadr arg))))
+ `(,(chunga:as-keyword (string-downcase arg) :destructivep nil) (escape-for-html ,arg))))
+ args)))))))
+
+
+(defmacro map-url-patterns (prefix &body body)
+ `(progn ,@(mapcar #'(lambda(mapping)
+ (funcall #'handle-mapping mapping prefix))
+ body)))
+
+(defmacro/g! define-url-patterns (prefix &body body)
+ `(let ((,application/g! (find *application-name*
+ easyweb.settings:*available-applications*
+ :test #'string=
+ :key #'car)))
+
+ ;;dont let mapping more than one
+ (when (or (null ,application/g!)
+ (and ,application/g!
+ (null (cdr ,application/g!))))
+ (map-url-patterns ,prefix ,@body))))
View
@@ -1,11 +1,4 @@
-(in-package :common-lisp-user)
-
-(defpackage :easyweb.util
- (:use #:cl)
- (:export #:enclose-string
- #:null-value-check))
-
-(in-package :easyweb.util)
+(in-package :easyweb)
;;in order to get around the issue with "describe" function,
;;strings must be enclosed with double-quotes.
@@ -32,7 +25,7 @@
(setf (cdr tail) al)
(setf tail (nthcdr (1- (length al)) al))))))
-#| - LET OVER LAMBDA UTILITIES -
+#| - LET OVER LAMBDA UTILITIES - |#
(defun mkstr (&rest args)
(with-output-to-string (s)
(dolist (a args) (princ a s))))
@@ -102,8 +95,7 @@
,(progn ,@body)))))
;;EXAMPLE#1
-(defmacro! square (o!x)
- `(progn
- (format t "[~A gave ~A]~%" ',o!x ,g!x)
- (* ,g!x ,g!x)))
-|#
+;(defmacro! square (o!x)
+; `(progn
+; (format t "[~A gave ~A]~%" ',o!x ,g!x)
+; (* ,g!x ,g!x)))

0 comments on commit e2fce10

Please sign in to comment.