From eea0da373349349b4d25dd4bc116a9c9eb04fb98 Mon Sep 17 00:00:00 2001 From: colin Date: Mon, 6 Mar 2023 20:06:19 -0800 Subject: Add: basic page stub to view an adventure --- src/endpoints.lisp | 10 ++++++++++ src/names.lisp | 3 ++- src/pages/adventure-page.lisp | 8 ++++++++ src/render.lisp | 16 +++++++++------- 4 files changed, 29 insertions(+), 8 deletions(-) create mode 100644 src/pages/adventure-page.lisp diff --git a/src/endpoints.lisp b/src/endpoints.lisp index 288f39e..f1151cf 100644 --- a/src/endpoints.lisp +++ b/src/endpoints.lisp @@ -149,4 +149,14 @@ functions in url parameters in endpoint definitions." :description description :seers possible-seers))))))) +(defun an-adventure-with-id (id) + (let ((object (object-with-uid (string-upcase id)))) + (unless (typep object 'adventure) + (lzb:http-err 404)) + object)) + +(defendpoint* :get "/adventure/:adventure an-adventure-with-id:/:title:" () () + (with-session (player) + (render (page-render-mode) + adventure))) ;; for now, render raw adventure. diff --git a/src/names.lisp b/src/names.lisp index 3bc0c16..05397a6 100644 --- a/src/names.lisp +++ b/src/names.lisp @@ -21,6 +21,7 @@ incorporate it into the urlpath. Otherwise use the object's uid. Returns /class/identifier." - (format nil "/~a/~a" + (format nil "/~a/~a/~a" (urlify (class-name (class-of object))) + (urlify (uid object)) (urlify (or (unique-name object) (uid object)))))) diff --git a/src/pages/adventure-page.lisp b/src/pages/adventure-page.lisp new file mode 100644 index 0000000..fd9cb09 --- /dev/null +++ b/src/pages/adventure-page.lisp @@ -0,0 +1,8 @@ +;;;; adventure-page.lisp -- shows a particular adventure + +(in-package :dnd) + +(defrender :page ((adventure adventure)) + (with-page (:title (title adventure)) + (:h1 (title adventure)) + (:p "uhh......"))) diff --git a/src/render.lisp b/src/render.lisp index 140e1ec..71f07b4 100644 --- a/src/render.lisp +++ b/src/render.lisp @@ -14,10 +14,12 @@ be a keyword for usin in EQL method specializers.")) (defmacro with-page ((&key title) &body body) "A helper macro fordefining some standard page boilerplate." - `(with-html-string - (:doctype) - (:html - (:head - (:title ,title)) - (:body - ,@body)))) + (let ((title-var (gensym))) + `(let ((,title-var ,title)) + (with-html-string + (:doctype) + (:html + (:head + (:title ,title-var)) + (:body + ,@body)))))) -- cgit v1.2.3