From 6963098fa7926e13ce221b8c0a3886f9f9984ac1 Mon Sep 17 00:00:00 2001 From: drewc Date: Fri, 24 Jul 2009 10:08:25 -0700 Subject: [PATCH] add contextl component using new dynamic environment stuff darcs-hash:20090724170825-39164-5167dc5a28fa6e0fc101e5b6766017eb65d82d37.gz --- src/ucw/contextl-components.lisp | 92 ++++++++++++++++++++++++++++++++ src/ucw/packages.lisp | 6 +-- src/ucw/standard-components.lisp | 68 ++++++++++++++--------- 3 files changed, 138 insertions(+), 28 deletions(-) diff --git a/src/ucw/contextl-components.lisp b/src/ucw/contextl-components.lisp index 80431c3..0f4465e 100644 --- a/src/ucw/contextl-components.lisp +++ b/src/ucw/contextl-components.lisp @@ -1,5 +1,97 @@ (in-package :lisp-on-lines-ucw) +(defclass contextl-application (standard-application) + () + (:default-initargs + + :action-class 'contextl-action)) + +(defclass contextl-action (ucw-standard:standard-action) + ((dynamic-environment :accessor action-dynamic-environment + :initform nil + :initarg :dynamic-environment)) + (:metaclass closer-mop:funcallable-standard-class)) + +(defmethod shared-initialize :after ((action contextl-action) slots &rest args) + (declare (ignore slots args)) + (setf (action-dynamic-environment action) (capture-dynamic-environment))) + +(defmethod ucw-core:handle-action :wrap-around ((action contextl-action) application session frame) + (call-next-method)) + +(defmethod ucw-core:call-action :around ((action contextl-action) application session frame) + (with-dynamic-environment ((action-dynamic-environment action)) + (call-next-method))) + +(defmethod ucw-core:call-callbacks ((action contextl-action) frame request) + (with-dynamic-environment ((action-dynamic-environment action)) + (call-next-method))) + +(defclass contextl-component (standard-component) + ((component-dynamic-environment :accessor component-dynamic-environment + :initform nil)) + (:metaclass standard-component-class)) + +(defmethod render :wrap-around ((component contextl-component)) + (if (component-dynamic-environment component) + (with-dynamic-environment ((component-dynamic-environment component)) + (call-next-method)) + (progn (setf (component-dynamic-environment component) (capture-dynamic-environment)) + (call-next-method)))) + +(defmethod/cc call-component :before ((from t) (to contextl-component)) + (setf (component-dynamic-environment to) (capture-dynamic-environment))) + + + + +#+LOL-TEST(progn + (defclass contextl-test-application (contextl-application) + () + (:default-initargs :url-prefix "/contextl/")) + + (defparameter *context-test-application* (make-instance 'contextl-test-application)) + + (register-application ucw-user:*example-server* *context-test-application*) + + (defentry-point "test.ucw" (:application *context-test-application*) () + (call 'contextl-test-component)) + + (defdynamic foo 1) + +(defclass contextl-test-component (contextl-component) () + (:metaclass standard-component-class)) + +(defmethod render ((component contextl-test-component)) + (<:As-html (dynamic foo)) + (dlet ((foo (1+ (dynamic foo)))) + (<:as-html (dynamic foo)) + (<:br) + (with-described-object (T nil) + (let ((a (find-attribute *description* 'identity))) + (