Better naming for property keys
This commit is contained in:
parent
3f9821b308
commit
9d10fb9748
1 changed files with 21 additions and 9 deletions
30
src/as2.lisp
30
src/as2.lisp
|
@ -56,6 +56,23 @@
|
||||||
(setf capitalize nil))
|
(setf capitalize nil))
|
||||||
(t (write-char (char-downcase char) out))))))
|
(t (write-char (char-downcase char) out))))))
|
||||||
|
|
||||||
|
(defun remove-postfix (postfix string)
|
||||||
|
"Remove the given postfix from the string if it exists."
|
||||||
|
(let* ((postfix-length (length postfix))
|
||||||
|
(string-length (length string))
|
||||||
|
(index (- string-length postfix-length)))
|
||||||
|
(if (and (>= string-length postfix-length)
|
||||||
|
(string= postfix (subseq string index)))
|
||||||
|
(subseq string 0 index)
|
||||||
|
string)))
|
||||||
|
|
||||||
|
(defun remove-as2-postfix (string)
|
||||||
|
"Remove the '-as2' prefix from the given string."
|
||||||
|
(remove-postfix "-as2" string))
|
||||||
|
|
||||||
|
(defun prepare-property-key (name)
|
||||||
|
(kebab-camel (remove-as2-postfix (string-downcase (symbol-name name)))))
|
||||||
|
|
||||||
(defclass property-container ()
|
(defclass property-container ()
|
||||||
((properties :initform (make-hash-table :test #'equal)
|
((properties :initform (make-hash-table :test #'equal)
|
||||||
:accessor properties)))
|
:accessor properties)))
|
||||||
|
@ -64,17 +81,9 @@
|
||||||
(setf (gethash "type" (properties obj))
|
(setf (gethash "type" (properties obj))
|
||||||
(kebab-camel (string-capitalize (class-name (class-of obj))))))
|
(kebab-camel (string-capitalize (class-name (class-of obj))))))
|
||||||
|
|
||||||
(defgeneric as2-type (property-container &optional value))
|
|
||||||
|
|
||||||
(defmethod as2-type ((obj property-container) &optional value)
|
|
||||||
(if value
|
|
||||||
(prog1 obj
|
|
||||||
(setf (gethash "type" (properties obj)) value))
|
|
||||||
(gethash "type" (properties obj))))
|
|
||||||
|
|
||||||
(defmacro define-property-method (class-name name)
|
(defmacro define-property-method (class-name name)
|
||||||
`(defmethod ,name ((obj ,class-name) &optional value)
|
`(defmethod ,name ((obj ,class-name) &optional value)
|
||||||
(let ((key ,(kebab-camel (string-downcase (symbol-name name)))))
|
(let ((key ,(prepare-property-key name)))
|
||||||
(if value
|
(if value
|
||||||
(prog1 obj
|
(prog1 obj
|
||||||
(setf (gethash key (properties obj)) value))
|
(setf (gethash key (properties obj)) value))
|
||||||
|
@ -96,6 +105,7 @@
|
||||||
end-time
|
end-time
|
||||||
generator
|
generator
|
||||||
icon
|
icon
|
||||||
|
id
|
||||||
image
|
image
|
||||||
in-reply-to
|
in-reply-to
|
||||||
location
|
location
|
||||||
|
@ -105,6 +115,7 @@
|
||||||
start-time
|
start-time
|
||||||
summary
|
summary
|
||||||
tag
|
tag
|
||||||
|
type-as2
|
||||||
updated
|
updated
|
||||||
url
|
url
|
||||||
to
|
to
|
||||||
|
@ -116,6 +127,7 @@
|
||||||
|
|
||||||
(defclass link (property-container) ())
|
(defclass link (property-container) ())
|
||||||
(define-property-methods link
|
(define-property-methods link
|
||||||
|
id
|
||||||
href
|
href
|
||||||
rel
|
rel
|
||||||
media-type
|
media-type
|
||||||
|
|
Loading…
Add table
Reference in a new issue