Przeglądaj źródła

First pass at WRITE-DOCUMENT, document exported protocol helpers.

Brit Butler 11 lat temu
rodzic
commit
dc2a2cc92e
3 zmienionych plików z 28 dodań i 1 usunięć
  1. 18 0
      docs/hacking.md
  2. 8 0
      src/documents.lisp
  3. 2 1
      src/packages.lisp

+ 18 - 0
docs/hacking.md

@@ -52,6 +52,8 @@ be seamlessly picked up by *coleslaw* and included on the rendered site.
52 52
 All current Content Types and Indexes implement the protocol faithfully.
53 53
 It consists of 2 "class" methods, 2 instance methods, and an invariant.
54 54
 
55
+There are also 4 helper functions provided that should prove useful in
56
+implementing new content types.
55 57
 
56 58
 **Class Methods**:
57 59
 
@@ -84,6 +86,22 @@ implement them by eql-specializing on the class, e.g.
84 86
   the site's git repo with the lowercased class-name as a file extension,
85 87
   i.e. (".post" for POST files).
86 88
 
89
+**Protocol Helpers**:
90
+
91
+- `add-document`: Add the document to *coleslaw*'s in-memory
92
+  database. It will error if the `page-url` of the document is not
93
+  unique. Such a hash collision represents content on the site being
94
+  shadowed/overwritten. This should be used in your `discover` method.
95
+- `write-document`: Write the document out to disk as HTML. It takes
96
+  an optional template name and render-args to pass to the template.
97
+  This should be used in your `publish` method.
98
+- `find-all`: Return a list of all documents of the requested class.
99
+  This is often used in the `publish` method to iterate over documents
100
+  of a given type.
101
+- `purge-all`: Remove all instances of the requested class from the DB.
102
+  This is primarily used at the REPL or for debugging but it is also
103
+  used in a `:before` method on `discover` to keep it idempotent.
104
+
87 105
 ### Current Content Types & Indexes
88 106
 
89 107
 There are 5 INDEX subclasses at present: TAG-INDEX, MONTH-INDEX,

+ 8 - 0
src/documents.lisp

@@ -54,3 +54,11 @@
54 54
 
55 55
 (defgeneric render (document &key &allow-other-keys)
56 56
   (:documentation "Render the given DOCUMENT to HTML."))
57
+
58
+(defun write-document (document &optional theme-fn &rest render-args)
59
+  "Write the given DOCUMENT to disk as HTML. If THEME-FN is present,
60
+use it as the template passing any RENDER-ARGS."
61
+  (let ((html (if render-args
62
+                  (apply #'render-page document theme-fn render-args)
63
+                  (render-page document nil))))
64
+    (write-file (page-path obj) html)))

+ 2 - 1
src/packages.lisp

@@ -22,4 +22,5 @@
22 22
            #:discover
23 23
            #:publish
24 24
            #:page-url
25
-           #:render))
25
+           #:render
26
+           #:write-document))