Skip to content

Instantly share code, notes, and snippets.

@kingcons
Last active December 25, 2015 01:09

Revisions

  1. Brit Butler revised this gist Oct 8, 2013. 1 changed file with 4 additions and 0 deletions.
    4 changes: 4 additions & 0 deletions oo.lisp
    Original file line number Diff line number Diff line change
    @@ -36,3 +36,7 @@
    (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
  2. kingcons created this gist Oct 8, 2013.
    38 changes: 38 additions & 0 deletions oo.lisp
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,38 @@
    (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))))