Browse Source

More comments and docs tweaks.

Brit Butler 11 years ago
parent
commit
f2bd0ff0ef
3 changed files with 35 additions and 22 deletions
  1. 8 1
      docs/hacking.md
  2. 26 20
      src/content.lisp
  3. 1 1
      src/documents.lisp

+ 8 - 1
docs/hacking.md

39
 limitations. Chiefly, the association between Content Types, their
39
 limitations. Chiefly, the association between Content Types, their
40
 template, and their inclusion in an INDEX is presently ad-hoc.
40
 template, and their inclusion in an INDEX is presently ad-hoc.
41
 
41
 
42
-// TODO: Write something about class-names as file-extension/eql-specializers!
42
+// TODO: Write something about the new Document Protocol!
43
 ### Current Content Types & Indexes
43
 ### Current Content Types & Indexes
44
 
44
 
45
 There are 5 INDEX subclasses at present: TAG-INDEX, MONTH-INDEX,
45
 There are 5 INDEX subclasses at present: TAG-INDEX, MONTH-INDEX,
106
 
106
 
107
 ## Areas for Improvement
107
 ## Areas for Improvement
108
 
108
 
109
+### render-foo* functions could be abstracted out
110
+// TODO
111
+
112
+### user-defined routing
113
+// TODO
114
+
109
 ### Better Content Types
115
 ### Better Content Types
116
+// TODO: Update to discuss Document Protocol.
110
 
117
 
111
 Creating a new content type should be both straightforward and doable
118
 Creating a new content type should be both straightforward and doable
112
 as a plugin. All that is really required is a subclass of CONTENT with
119
 as a plugin. All that is really required is a subclass of CONTENT with

+ 26 - 20
src/content.lisp

1
 (in-package :coleslaw)
1
 (in-package :coleslaw)
2
 
2
 
3
+;; Tagging
4
+
3
 (defclass tag ()
5
 (defclass tag ()
4
   ((name :initform nil :initarg :name :accessor tag-name)
6
   ((name :initform nil :initarg :name :accessor tag-name)
5
    (slug :initform nil :Initarg :slug :accessor tag-slug)))
7
    (slug :initform nil :Initarg :slug :accessor tag-slug)))
13
   "Test if the slugs for tag A and B are equal."
15
   "Test if the slugs for tag A and B are equal."
14
   (string= (tag-slug a) (tag-slug b)))
16
   (string= (tag-slug a) (tag-slug b)))
15
 
17
 
18
+;; Slugs
19
+
20
+(defun slug-char-p (char)
21
+  "Determine if CHAR is a valid slug (i.e. URL) character."
22
+  (or (char<= #\0 char #\9)
23
+      (char<= #\a char #\z)
24
+      (char<= #\A char #\Z)
25
+      (member char '(#\_ #\-))))
26
+
27
+(defun slugify (string)
28
+  "Return a version of STRING suitable for use as a URL."
29
+  (remove-if-not #'slug-char-p (substitute #\- #\Space string)))
30
+
31
+;; Content Types
32
+
16
 (defclass content ()
33
 (defclass content ()
17
   ((tags :initform nil :initarg :tags :accessor content-tags)
34
   ((tags :initform nil :initarg :tags :accessor content-tags)
18
    (slug :initform nil :initarg :slug :accessor content-slug)
35
    (slug :initform nil :initarg :slug :accessor content-slug)
19
    (date :initform nil :initarg :date :accessor content-date)
36
    (date :initform nil :initarg :date :accessor content-date)
20
    (text :initform nil :initarg :text :accessor content-text)))
37
    (text :initform nil :initarg :text :accessor content-text)))
21
 
38
 
22
-(defun tag-p (tag obj)
23
-  "Test if OBJ is tagged with TAG."
24
-  (let ((tag (if (typep tag 'tag) tag (make-tag tag))))
25
-    (member tag (content-tags obj) :test #'tag-slug=)))
26
-
27
-(defun month-p (month obj)
28
-  "Test if OBJ was written in MONTH."
29
-  (search month (content-date obj)))
30
-
31
 (defun read-content (file)
39
 (defun read-content (file)
32
   "Returns a plist of metadata from FILE with :text holding the content as a string."
40
   "Returns a plist of metadata from FILE with :text holding the content as a string."
33
   (flet ((slurp-remainder (stream)
41
   (flet ((slurp-remainder (stream)
52
         (setf (getf meta :tags) (read-tags (getf meta :tags)))
60
         (setf (getf meta :tags) (read-tags (getf meta :tags)))
53
         (append meta (list :text content))))))
61
         (append meta (list :text content))))))
54
 
62
 
63
+(defun tag-p (tag obj)
64
+  "Test if OBJ is tagged with TAG."
65
+  (let ((tag (if (typep tag 'tag) tag (make-tag tag))))
66
+    (member tag (content-tags obj) :test #'tag-slug=)))
67
+
68
+(defun month-p (month obj)
69
+  "Test if OBJ was written in MONTH."
70
+  (search month (content-date obj)))
71
+
55
 (defun by-date (content)
72
 (defun by-date (content)
56
   "Sort CONTENT in reverse chronological order."
73
   "Sort CONTENT in reverse chronological order."
57
   (sort content #'string> :key #'content-date))
74
   (sort content #'string> :key #'content-date))
58
-
59
-(defun slug-char-p (char)
60
-  "Determine if CHAR is a valid slug (i.e. URL) character."
61
-  (or (char<= #\0 char #\9)
62
-      (char<= #\a char #\z)
63
-      (char<= #\A char #\Z)
64
-      (member char '(#\_ #\-))))
65
-
66
-(defun slugify (string)
67
-  "Return a version of STRING suitable for use as a URL."
68
-  (remove-if-not #'slug-char-p (substitute #\- #\Space string)))

+ 1 - 1
src/documents.lisp

8
   "An in-memory database to hold all site documents, keyed on page-url.")
8
   "An in-memory database to hold all site documents, keyed on page-url.")
9
 
9
 
10
 (defun add-document (doc)
10
 (defun add-document (doc)
11
-  "Add DOC to the in-memory database. If a matching entry is present, error."
11
+  "Add DOC to the in-memory database. Error if a matching entry is present."
12
   (let ((url (page-url doc)))
12
   (let ((url (page-url doc)))
13
     (if (gethash url *site*)
13
     (if (gethash url *site*)
14
         (error "There is already an existing document with the url ~a" url)
14
         (error "There is already an existing document with the url ~a" url)