git.fiddlerwoaroof.com
Raw Blame History
(in-package :fwoar.rss-reader)

(defgeneric app (obj)
  (:documentation "the ningle app that is to be run"))

(defgeneric handler (obj)
  (:documentation "the clack handler representing the currently running application"))

(defclass+ rss-reader ()
  ((%feeds :initarg :feeds :accessor feeds)
   (%app :initform (make-instance 'ningle:<app>)
         :reader app)
   (%handler :accessor handler))
  (:documentation
   "A simple wrapper that ties a ningle app to a clack handler"))


(defmethod araneus:routes progn ((app rss-reader))
  (araneus:defroutes (app app)
    (("/") (serapeum:partial 'araneus:run-route (make-instance 'homepage)))
    (("/f/:feed") (lambda (params)
                    (optima:match params
                      ((optima.extra:alist (:feed . feed))
                       (araneus:run-route (feed-page
                                           (feeds app)
                                           (serapeum:assocdr feed (feeds app)
                                                             :test 'string-equal))
                                          params)))))
    (("/other") (serapeum:partial 'araneus:run-route 'other))))

(defun start (app)
  (setf (handler app)
        (clack:clackup (app app)))
  app)

(defvar *app*)

(defun unboundp (symbol)
  (not (boundp symbol)))

(defun main ()
  (setf *app*
        (if (not (boundp '*app*))
            (start
             (araneus:routes
              (rss-reader `((:techcrunch . "https://techcrunch.com/feed/")
                            (:just-thomism . "https://thomism.wordpress.com/feed/")))))
            *app*)))