Added in the changes proposed by PuercoPop. Moved the condition to utils.lisp, added a base condition and moved error signalling to :initform
This commit is contained in:
parent
33db0356b1
commit
12d4643d04
5 changed files with 26 additions and 20 deletions
|
@ -21,7 +21,6 @@
|
|||
:serial t
|
||||
:components ((:file "packages")
|
||||
(:file "util")
|
||||
(:file "errors")
|
||||
(:file "config")
|
||||
(:file "themes")
|
||||
(:file "documents")
|
||||
|
|
|
@ -13,21 +13,21 @@
|
|||
(in-package :coleslaw-static-pages)
|
||||
|
||||
(defclass page (content)
|
||||
((title :initarg :title :reader coleslaw::title-of)
|
||||
((title :initarg :title :reader coleslaw::title-of
|
||||
:initform
|
||||
(error 'coleslaw::required-field-missing :message (format nil "Required field title is missing from static-page")))
|
||||
(format :initarg :format :reader coleslaw::page-format))
|
||||
;; default format is markdown (for backward compatibility)
|
||||
(:default-initargs :format :md))
|
||||
|
||||
(defmethod initialize-instance :after ((object page) &key url title)
|
||||
(cond
|
||||
((null url)
|
||||
(error 'coleslaw::required-field-missing :message (format nil "URL field is missing from static page ~A" (coleslaw::content-file object))))
|
||||
((null title)
|
||||
(error 'coleslaw::required-field-missing :message (format nil "Title field is missing from static page ~A" (coleslaw::content-file object)))))
|
||||
(defmethod initialize-instance :after ((object page) &key)
|
||||
(with-slots (coleslaw::url coleslaw::text format title) object
|
||||
(if (not (boundp coleslaw::url))
|
||||
(error 'coleslaw::required-field-missing
|
||||
:message (format nil "Required field URL is missing"))
|
||||
(setf coleslaw::url (make-pathname :defaults coleslaw::url)
|
||||
format (alexandria:make-keyword (string-upcase format))
|
||||
coleslaw::text (render-text coleslaw::text format))))
|
||||
coleslaw::text (render-text coleslaw::text format)))))
|
||||
|
||||
(defmethod render ((object page) &key next prev)
|
||||
;; For the time being, we'll re-use the normal post theme.
|
||||
|
|
|
@ -1,8 +0,0 @@
|
|||
(in-package :coleslaw)
|
||||
|
||||
(define-condition required-field-missing (error)
|
||||
((message :accessor required-field-missing-message :initarg :message))
|
||||
(:report
|
||||
(lambda (c s)
|
||||
(format s (required-field-missing-message
|
||||
c)))))
|
|
@ -46,4 +46,9 @@
|
|||
#:add-document
|
||||
#:delete-document
|
||||
#:write-document
|
||||
#:content-text))
|
||||
#:content-text
|
||||
|
||||
;; Conditions
|
||||
coleslaw-condition
|
||||
required-field-missing
|
||||
))
|
||||
|
|
|
@ -1,5 +1,15 @@
|
|||
(in-package :coleslaw)
|
||||
|
||||
|
||||
(define-condition coleslaw-condition () ())
|
||||
(define-condition required-field-missing (error coleslaw-condition)
|
||||
((message :accessor required-field-missing-message :initarg :message))
|
||||
(:report
|
||||
(lambda (c s)
|
||||
(format s (required-field-missing-message
|
||||
c)))))
|
||||
|
||||
|
||||
(defun construct (class-name args)
|
||||
"Create an instance of CLASS-NAME with the given ARGS."
|
||||
(apply 'make-instance class-name args))
|
||||
|
|
Loading…
Add table
Reference in a new issue