From f37b6e61cbebab71424ae9561cd5932776c952d9 Mon Sep 17 00:00:00 2001 From: Colin Okay Date: Tue, 8 Feb 2022 08:24:27 -0600 Subject: added support for basic documentation of apps --- lazybones.lisp | 33 ++++++++++++++++++++++++++------- 1 file changed, 26 insertions(+), 7 deletions(-) (limited to 'lazybones.lisp') diff --git a/lazybones.lisp b/lazybones.lisp index 45da60b..8e1228b 100644 --- a/lazybones.lisp +++ b/lazybones.lisp @@ -30,6 +30,18 @@ :initarg :name :initform (error "Appname is required") :type symbol) + (title + :accessor app-title + :initarg :title + :initform "" + :type string + :documentation "A string title") + (description + :accessor app-description + :initarg :description + :initform "" + :type string + :documentation "A string describing the app") (version :reader app-version :initarg :vsn :initarg :version @@ -65,8 +77,13 @@ (defmethod initialize-instance :after ((app app) &key) (setf (symbol-lazybones (app-name app)) app)) -(defun app (name) - (symbol-lazybones name nil)) +(defun app (&optional name) + "Get the APP instance named by the symbol NAME. If NAME is not +supplied, get the default app. Every package has at most one default +app, named with the package name." + (symbol-lazybones (or name + (intern (package-name *package*) *package*)) + nil)) (defclass endpoint () ((method @@ -237,8 +254,9 @@ applying HANDLER-FUNCTION slot of ENDPOINT to the ARGS list." (let ((*request* request) (*response* response) (*app* app)) - (when (request-authorized-p endpoint) - (apply (endpoint-request-handler endpoint) args)))) + (if (request-authorized-p endpoint) + (apply (endpoint-request-handler endpoint) args) + (http-err 404)))) (defun request-authorized-p (endpoint) "Attempts to authorize an endpoint. @@ -254,9 +272,10 @@ authorizer is used. Hence, if the endpoint authorizer is T and the app doesn't have an authorizer, then, the endpoint wants to be authorized but there isn't any way to do it, hence NIL is returned." - (a:if-let (specific-authorizer (request-authorizer endpoint)) - (if (functionp specific-authorizer) - (funcall specific-authorizer) + (a:if-let (auth (request-authorizer endpoint)) + (if (or (functionp auth) + (and (symbolp auth) (fboundp auth))) + (funcall auth) (when (request-authorizer *app*) ; perhaps this should be an if, and (funcall (request-authorizer *app*)))) t)) -- cgit v1.2.3