From 4183badcc6da9e33e42d6be2e77d98bec5acf272 Mon Sep 17 00:00:00 2001 From: fukamachi Date: Sun, 25 Mar 2012 23:21:12 +0900 Subject: [PATCH] made a change to "caveman.project:build" (backward incompatible!). --- skeleton/skeleton.asd | 3 ++- skeleton/src/skeleton.lisp | 23 +++++++++++++++++------ src/core/app.lisp | 14 +++++++++++--- src/core/project.lisp | 35 +++-------------------------------- 4 files changed, 33 insertions(+), 42 deletions(-) diff --git a/skeleton/skeleton.asd b/skeleton/skeleton.asd index ab19f6b..d2b5609 100644 --- a/skeleton/skeleton.asd +++ b/skeleton/skeleton.asd @@ -24,7 +24,8 @@ :depends-on (:clack :caveman :cl-syntax - :cl-syntax-annot) + :cl-syntax-annot + :cl-ppcre) :components ((:module "lib" :components ((:module "view" diff --git a/skeleton/src/skeleton.lisp b/skeleton/src/skeleton.lisp index 805e1be..4516f58 100644 --- a/skeleton/src/skeleton.lisp +++ b/skeleton/src/skeleton.lisp @@ -5,7 +5,10 @@ (clack.util:namespace <% @var name %> (:use :cl - :clack) + :clack + :clack.builder + :clack.middleware.static + :clack.middleware.session) (:shadow :stop) (:import-from :caveman :config) @@ -17,7 +20,10 @@ (:import-from :clack.builder :*builder-lazy-p*) (:import-from :<% @var name %>.app - :*app*)) + :*app*) + (:import-from :cl-ppcre + :scan + :regex-replace)) (cl-syntax:use-syntax :annot) @@ -27,10 +33,15 @@ @export (defvar *project* nil) -(defmethod build ((this <<% @var name %>>) &optional app) - @ignore app - (call-next-method - this +(defmethod build ((this <<% @var name %>>)) + (builder + ( + :path (lambda (path) + (when (ppcre:scan "^(?:/static/|/images/|/css/|/js/|/robot\\.txt$|/favicon.ico$)" path) + (ppcre:regex-replace "^/static" path ""))) + :root (merge-pathnames (config :static-path) + (config :application-root))) + <% @var name %>.app:*app*)) @export diff --git a/src/core/app.lisp b/src/core/app.lisp index 9b4fd37..e54e911 100644 --- a/src/core/app.lisp +++ b/src/core/app.lisp @@ -8,7 +8,8 @@ (clack.util:namespace caveman.app (:use :cl - :clack) + :clack + :caveman.middleware.context) (:import-from :clack.util.route :match) (:import-from :caveman.context @@ -27,9 +28,16 @@ :accessor routing-rules)) (:documentation "Base class for Caveman Application. All Caveman Application must inherit this class.")) -(defmethod call ((this ) req) +(defmethod call :around ((this ) env) + (call (wrap + (make-instance ') + (lambda (env) + (call-next-method this env))) + env)) + +(defmethod call ((this ) env) "Overriding method. This method will be called for each request." - @ignore req + @ignore env (let* ((req *request*) (path-info (path-info req)) (method (request-method req))) diff --git a/src/core/project.lisp b/src/core/project.lisp index 720d548..60abe12 100644 --- a/src/core/project.lisp +++ b/src/core/project.lisp @@ -10,17 +10,8 @@ (:use :cl :anaphora :clack - :clack.builder - :clack.middleware.static - :clack.middleware.session - :caveman.middleware.context) + :clack.builder) (:shadow :stop) - (:import-from :local-time - :format-timestring - :now) - (:import-from :cl-ppcre - :scan - :scan-to-strings) (:import-from :cl-fad :file-exists-p) (:import-from :caveman.context @@ -45,28 +36,8 @@ :accessor project-mode))) @export -(defmethod build ((this ) &optional app) - (builder - (clack.middleware.logger: - :logger (make-instance 'clack.logger.file: - :output-file - (merge-pathnames - (local-time:format-timestring nil - (local-time:now) - :format - '("log-" (:year 4) (:month 2) (:day 2))) - (merge-pathnames - (getf (config this) :log-path) - (getf (config this) :application-root))))) - ( - :path (lambda (path) - (when (ppcre:scan "^(?:/static/|/images/|/css/|/js/|/robot\\.txt$|/favicon.ico$)" path) - (ppcre:regex-replace "^/static" path ""))) - :root (merge-pathnames (getf (config this) :static-path) - (getf (config this) :application-root))) - - - app)) +(defgeneric build (project) + (:documentation "Build up an application for this project and return it. This method must be implemented in subclasses.")) (defun slurp-file (path) "Read a specified file and return the content as a sequence."