Skip to content
Browse files

made a change to "caveman.project:build" (backward incompatible!).

  • Loading branch information...
1 parent 2bc01c8 commit 4183badcc6da9e33e42d6be2e77d98bec5acf272 @fukamachi committed
Showing with 33 additions and 42 deletions.
  1. +2 −1 skeleton/skeleton.asd
  2. +17 −6 skeleton/src/skeleton.lisp
  3. +11 −3 src/core/app.lisp
  4. +3 −32 src/core/project.lisp
View
3 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"
View
23 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
+ (<clack-middleware-static>
+ :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)))
+ <clack-middleware-session>
<% @var name %>.app:*app*))
@export
View
14 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 <app>) req)
+(defmethod call :around ((this <app>) env)
+ (call (wrap
+ (make-instance '<caveman-middleware-context>)
+ (lambda (env)
+ (call-next-method this env)))
+ env))
+
+(defmethod call ((this <app>) 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)))
View
35 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 <project>) &optional app)
- (builder
- (clack.middleware.logger:<clack-middleware-logger>
- :logger (make-instance 'clack.logger.file:<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)))))
- (<clack-middleware-static>
- :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)))
- <clack-middleware-session>
- <caveman-middleware-context>
- 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."

0 comments on commit 4183bad

Please sign in to comment.
Something went wrong with that request. Please try again.