git.fiddlerwoaroof.com
yason-encoders.lisp
d28d3987
 (in-package :alimenta.feed-archive.encoders)
 
79f9884d
 (defmethod yason:encode-slots progn ((feed alimenta:feed))
877a9d53
   (prog1 feed
     (patmatch:let-pat* (((alimenta:feed :title title
                                         :feed-link feed-link
                                         :link link
                                         :description description)
                          feed))
       (yason:encode-object-element "title" title)
       (yason:encode-object-element "fetch-url" (puri:render-uri feed-link nil))
       (yason:encode-object-element "link" link)
       ;;(yason:encode-object-element "source-type" source-type)
       (yason:encode-object-element "description" description))))
79f9884d
 
 
f92f94ff
 (defmethod yason:encode-slots progn ((item alimenta:item))
877a9d53
   (patmatch:let-pat* (((alimenta:item :author author
                                       :content content
                                       :date date
                                       :id id
                                       :link link
                                       :title title)
                        item))
f7e44666
     (let* ((date (local-time:format-timestring nil date)))
877a9d53
       (yason:encode-object-element "title" title)
       (yason:encode-object-element "date" date)
       (yason:encode-object-element "author" author)
       (yason:encode-object-element "id" (princ-to-string id))
       (yason:encode-object-element "link" link)
       (yason:encode-object-element "content" content))))
f92f94ff
 
877a9d53
 (defmethod yason:encode ((object pathname) &optional stream)
   (prog1 object
     (yason:encode (princ-to-string (uiop:native-namestring object))
                   stream)))
f7e44666
 
877a9d53
 (defmethod yason:encode ((object puri:uri) &optional stream)
   (prog1 object
     (yason:encode (puri:render-uri object nil)
                   stream)))
 
 (defmethod yason:encode ((feed-entity alimenta:feed-entity) &optional stream)
   (prog1 feed-entity
     (yason:with-output (stream :indent t)
       (yason:encode-object feed-entity))))
d28d3987
 
 (defun encode-collection-object (other-pairs collection-key collection-value element-encoder)
   (yason:with-object ()
     (loop for (key value) on other-pairs by #'cddr
        do
          (yason:encode-object-element key value))
     (yason:with-object-element (collection-key)
       (yason:with-array ()
         (dolist (item collection-value)
           (funcall element-encoder item))))))
 
 (defmacro with-collection ((item-sym key collection &rest other-pairs) &body encoder)
   (once-only (key collection)
     `(encode-collection-object (list ,@other-pairs)
                                ,key ,collection
                                (lambda (,item-sym)
                                  ,@encoder))))