Skip to content

Instantly share code, notes, and snippets.

@kingcons
Last active December 25, 2015 01:09
Show Gist options
  • Save kingcons/6892689 to your computer and use it in GitHub Desktop.
Save kingcons/6892689 to your computer and use it in GitHub Desktop.
tweaks
(defpackage :lisp-oo
(:use :cl))
(in-package :lisp-oo)
(defclass content ()
((tags :initform nil :initarg :tags :accessor content-tags)
(slug :initform nil :initarg :slug :accessor content-slug)
(date :initform nil :initarg :date :accessor content-date)
(text :initform nil :initarg :text :accessor content-text)))
(defun construct (content-type args)
"Create an instance of CONTENT-TYPE with the given ARGS."
(apply 'make-instance content-type args))
(defgeneric publish (content-type)
(:documentation "Write pages to disk for all content of the given CONTENT-TYPE."))
(defgeneric render (object &key &allow-other-keys)
(:documentation "Render the given OBJECT to HTML."))
(defgeneric render-content (text format)
(:documentation "Compile TEXT from the given FORMAT to HTML for display.")
(:method (text (format (eql :html)))
text)
(:method (text (format (eql :md)))
(let ((3bmd-code-blocks:*code-blocks* t))
(with-output-to-string (str)
(3bmd:parse-string-and-print-to-stream text str)))))
(defgeneric page-url (object)
(:documentation "The url to the object, without the domain."))
(defmethod page-url :around ((object t))
(let ((result (call-next-method)))
(if (pathname-type result)
result
(make-pathname :type "html" :defaults result))))
;;; You can also do insane things like...
;;; make a DSL for writing Finite State Machines using the Method Dispatch system
;;; If you're crazy: https://gist.github.com/sshirokov/2698150
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment