Permalink
Browse files

Some changes

  • Loading branch information...
1 parent 9f9be2b commit 5ec48f63b23332876344f00a65dc66a12b1d2f8a @archimag committed Jan 12, 2010
Showing with 36 additions and 9 deletions.
  1. +0 −3 example/example-1.lisp
  2. +0 −2 example/example-2.lisp
  3. +18 −0 example/hello-world.lisp
  4. +1 −0 src/packages.lisp
  5. +4 −1 src/preserve-context.lisp
  6. +13 −3 src/site.lisp
View
@@ -13,9 +13,6 @@
(in-package :restas.example-1)
-(restas:define-site-plugin default (:restas.example-1))
-
-
(define-route main ("" :method :get)
(who:with-html-output-to-string (out)
(:html
View
@@ -14,8 +14,6 @@
(in-package :restas.example-2)
-(restas:define-site-plugin default (:restas.example-2))
-
(define-route root ("")
(who:with-html-output-to-string (out)
(:html
View
@@ -0,0 +1,18 @@
+;;;; hello-world.lisp
+;;;;
+;;;; This file is part of the RESTAS library, released under Lisp-LGPL.
+;;;; See file COPYING for details.
+;;;;
+;;;; Author: Moskvitin Andrey <archimag@gmail.com>
+
+(asdf:operate 'asdf:load-op '#:restas)
+
+(restas:defsite #:restas.hello-world
+ (:use :cl))
+
+(in-package #:restas.hello-world)
+
+(define-route main ("")
+ "<h1>Hello world!</h1>")
+
+(restas:start-site '#:restas.hello-world :port 8080)
View
@@ -28,6 +28,7 @@
#:plugin-instance
#:adopt-route-result
#:calculate-user-login
+ #:with-plugin-context
#:parse-host
#:start-site
@@ -20,7 +20,10 @@
(remhash symbol context))
(defun context-symbol-value (context symbol)
- (gethash symbol context))
+ (multiple-value-bind (value present-p) (gethash symbol context)
+ (if present-p
+ value
+ (symbol-value symbol))))
(defun (setf context-symbol-value) (newval context symbol)
(setf (gethash symbol context)
View
@@ -33,6 +33,10 @@
(defmethod adopt-route-result ((instance plugin-instance) obj)
obj)
+(defmacro with-plugin-context (plugin-instance &body body)
+ `(with-context (slot-value ,plugin-instance 'context)
+ ,@body))
+
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;; site
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
@@ -43,7 +47,7 @@
`(eval-when (:compile-toplevel :load-toplevel :execute)
(let ((package (define-plugin ,name ,@args)))
(eval `(defvar ,(intern "*SITE-PLUGINS*" package) (make-hash-table)))
- (eval `(defvar ,(intern "*MAPPER*" package) (make-instance 'routes:mapper)))
+ (eval `(defvar ,(intern "*MAPPER*" package) (make-instance 'routes:mapper)))
package)))
(defun connect-plugin-instance (instance &optional (mapper *mapper*))
@@ -67,6 +71,10 @@
(iter (for site in *sites*)
(let ((mapper (symbol-value (find-symbol "*MAPPER*" site))))
(routes:reset-mapper mapper)
+ (connect-plugin-instance (make-instance 'plugin-instance
+ :plugin site
+ :context (make-preserve-context))
+ mapper)
(iter (for (name instance) in-hashtable (symbol-value (find-symbol "*SITE-PLUGINS*" site)))
(connect-plugin-instance instance
mapper)))))
@@ -96,6 +104,8 @@
(reconnect-all-sites)))))
(defun site-url (plugin-instance route-symbol &rest args)
- (with-context (slot-value plugin-instance 'context)
- (apply 'genurl route-symbol args)))
+ (if plugin-instance
+ (with-context (slot-value plugin-instance 'context)
+ (apply 'genurl route-symbol args))
+ (apply 'genurl route-symbol args)))

0 comments on commit 5ec48f6

Please sign in to comment.