X-Git-Url: https://git.hcoop.net/clinton/lisp-on-lines.git/blobdiff_plain/6fe664d14f96294676a35f455ea5d4839bb0fb9d..b1c8f43be32503f3911e60696dba8c9194f28ca5:/src/ucw/standard-components.lisp diff --git a/src/ucw/standard-components.lisp b/src/ucw/standard-components.lisp index 361e61e..0fb99f5 100644 --- a/src/ucw/standard-components.lisp +++ b/src/ucw/standard-components.lisp @@ -1,15 +1,46 @@ (in-package :lisp-on-lines-ucw) +(defparameter *source-component* nil) + +(defclass standard-basic-action (basic-action) + ((source-component :accessor action-source-component)) + (:metaclass mopp:funcallable-standard-class)) + +(defmethod shared-initialize :before ((action standard-basic-action) slots &rest args) + (declare (ignore slots args)) + (setf (action-source-component action) *source-component*)) + +(defmethod handle-action :around ((action standard-basic-action) a s f) + (let ((*source-component* (action-source-component action))) + (call-next-method))) + +(defmethod render :around (component) + (let ((*source-component* component)) + (call-next-method))) + + +(defun/cc call (name &rest args) + (call-component *source-component* + (apply #'make-instance name args))) + +(defun/cc answer (&optional val) + (answer-component *source-component* + val)) + (defclass described-component-class (standard-component-class described-class) ()) (defmacro defaction (&rest args-and-body) `(arnesi:defmethod/cc ,@args-and-body)) -(defun make-action (lambda &rest args) - (let ((ucw::*default-action-class* 'basic-action)) - (apply #'ucw::make-action lambda args))) +(defparameter *default-action-class* 'standard-basic-action) +(defun make-action (lambda &rest initargs &key (class *default-action-class*) &allow-other-keys) + "Makes a new unregistered action." + (remf-keywords initargs :class) + (apply #'make-instance class :lambda lambda initargs)) + + (defclass standard-application (ucw:basic-application) ()) @@ -24,7 +55,6 @@ (defmethod ucw::find-action-id :around ((context standard-request-context)) (or (loop - :for (k . v) in (ucw::parameters (context.request context)) :do(destructuring-bind (param-name &optional action-id) @@ -44,5 +74,33 @@ :component t :initarg :body))) +(defmethod render-html-head ((window standard-window-component)) + (let* ((app (context.application *context*)) + (url-prefix (application.url-prefix app))) + (<:meta :http-equiv "Content-Type" :content (window-component.content-type window)) + (awhen (window-component.title window) + (<:title (if (functionp it) + (funcall it window) + (<:as-html it)))) + (awhen (window-component.icon window) + (<:link :rel "icon" + :type "image/x-icon" + :href (concatenate 'string url-prefix it))) + (dolist (stylesheet (effective-window-stylesheets window)) + (<:link :rel "stylesheet" + :href stylesheet + :type "text/css")))) + (defmethod render-html-body ((window standard-window-component)) (ucw:render (window-body window))) + +(defcomponent info-message () + ((message :accessor message :initarg :message))) + +(defmethod render ((m info-message)) + (<:div + :class "info-mssage" + (<:as-html (message m))) + (