Report when a required field is missing in the static-pages plugin
Add ASSERT-FIELD to the API as the entry point for plugins to report to the user when a content field is missing.
This commit is contained in:
parent
7d87d483a0
commit
d397b32328
3 changed files with 28 additions and 2 deletions
|
@ -2,6 +2,7 @@
|
||||||
(:use :cl)
|
(:use :cl)
|
||||||
(:export #:enable)
|
(:export #:enable)
|
||||||
(:import-from :coleslaw #:*config*
|
(:import-from :coleslaw #:*config*
|
||||||
|
#:assert-field
|
||||||
#:content
|
#:content
|
||||||
#:find-all
|
#:find-all
|
||||||
#:render
|
#:render
|
||||||
|
@ -19,7 +20,9 @@
|
||||||
(:default-initargs :format :md))
|
(:default-initargs :format :md))
|
||||||
|
|
||||||
(defmethod initialize-instance :after ((object page) &key)
|
(defmethod initialize-instance :after ((object page) &key)
|
||||||
(with-slots (coleslaw::url coleslaw::text format) object
|
(assert-field 'title object)
|
||||||
|
(assert-field 'coleslaw::url object)
|
||||||
|
(with-slots (coleslaw::url coleslaw::text format title) object
|
||||||
(setf coleslaw::url (make-pathname :defaults coleslaw::url)
|
(setf coleslaw::url (make-pathname :defaults coleslaw::url)
|
||||||
format (alexandria:make-keyword (string-upcase format))
|
format (alexandria:make-keyword (string-upcase format))
|
||||||
coleslaw::text (render-text coleslaw::text format))))
|
coleslaw::text (render-text coleslaw::text format))))
|
||||||
|
|
|
@ -46,4 +46,7 @@
|
||||||
#:add-document
|
#:add-document
|
||||||
#:delete-document
|
#:delete-document
|
||||||
#:write-document
|
#:write-document
|
||||||
#:content-text))
|
#:content-text
|
||||||
|
|
||||||
|
;; Error reporting
|
||||||
|
#:assert-field))
|
||||||
|
|
|
@ -1,5 +1,25 @@
|
||||||
(in-package :coleslaw)
|
(in-package :coleslaw)
|
||||||
|
|
||||||
|
|
||||||
|
(define-condition coleslaw-condition ()
|
||||||
|
())
|
||||||
|
|
||||||
|
(define-condition field-missing (error coleslaw-condition)
|
||||||
|
((field-name :initarg :field-name :reader missing-field-field-name)
|
||||||
|
(file :initarg :file :reader missing-field-file
|
||||||
|
:documentation "The path of the file where the field is missing."))
|
||||||
|
(:report
|
||||||
|
(lambda (c s)
|
||||||
|
(format s "~A: The required field ~A is missing."
|
||||||
|
(missing-field-file c)
|
||||||
|
(missing-field-field-name c)))))
|
||||||
|
|
||||||
|
(defmacro assert-field (field-name content)
|
||||||
|
`(when (not (slot-boundp ,content ,field-name))
|
||||||
|
(error 'field-missing
|
||||||
|
:field-name ,field-name
|
||||||
|
:file (content-file ,content))))
|
||||||
|
|
||||||
(defun construct (class-name args)
|
(defun construct (class-name args)
|
||||||
"Create an instance of CLASS-NAME with the given ARGS."
|
"Create an instance of CLASS-NAME with the given ARGS."
|
||||||
(apply 'make-instance class-name args))
|
(apply 'make-instance class-name args))
|
||||||
|
|
Loading…
Add table
Reference in a new issue