git.fiddlerwoaroof.com
Raw Blame History
(defpackage :fwoar.rss-render
  (:use :cl )
  (:export
   #:summary))
(in-package :fwoar.rss-render)

(defmacro if-arg-not-nil ((op arg))
  (alexandria:once-only (arg)
    `(when ,arg
       (,op ,arg))))

(defmethod alimenta.render:render-feed ((feed alimenta.rss:rss-feed) (renderer fwoar.rss-reader:feed-reference))
  (plump:parse
   (spinneret:with-html-string
     (:div.feed
      (:section
       (:h2.title (if-arg-not-nil
                      (plump:decode-entities
                       (alimenta:title feed))))
       (:p.description (if-arg-not-nil
                           (plump:decode-entities
                            (alimenta:description feed)))))
      (:ul.items)))))

(defmethod alimenta.render:render-feed ((feed alimenta.atom::atom-feed) (renderer fwoar.rss-reader:feed-reference))
  (plump:parse
   (spinneret:with-html-string
     (:div.feed
      (:section
       (:h2.title (if-arg-not-nil
                      (plump:decode-entities
                       (alimenta:title feed)))))
      (:ul.items)))))

(defmethod alimenta.render:render-item (item feed (renderer fwoar.rss-reader:feed-reference))
  (plump:first-element
   (plump:parse
    (spinneret:with-html-string
      (:li
       (:a :href (alimenta:link item)
           (plump:decode-entities
            (alimenta:title item)))
       (:p.description
        (let ((description (fwoar.rss-reader:prepare-feed-item-description renderer item)))
          (when description
            (plump:decode-entities
             description)))))))))

(defmethod alimenta.render:add-rendered-item (feed-r item-r (renderer fwoar.rss-reader:feed-reference))
  (lquery:$
    (inline feed-r)
    ".items"
    (append item-r))
  feed-r)