Browse Source

Make add-injection support more complex injections. Thanks @PuercoPop.

In short, an injection is now a FUNCTION that takes a
document and returns either a STRING to insert in the
page (possibly with data from the document) or NIL.
Brit Butler 10 years ago
parent
commit
e44d0bde9e
7 changed files with 28 additions and 27 deletions
  1. 7 2
      NEWS.md
  2. 1 1
      docs/hacking.md
  3. 5 7
      docs/plugin-api.md
  4. 2 1
      plugins/analytics.lisp
  5. 4 2
      plugins/disqus.lisp
  6. 4 3
      plugins/mathjax.lisp
  7. 5 11
      src/themes.lisp

+ 7 - 2
NEWS.md

4
   instead of the previous symlinked, timestamped deploy strategy.
4
   instead of the previous symlinked, timestamped deploy strategy.
5
   To retain the previous behavior, add `(versioned)` to your config's
5
   To retain the previous behavior, add `(versioned)` to your config's
6
   `:plugins` list.
6
   `:plugins` list.
7
-* **SITE-BREAKING CHANGE**: Custom themes will be broken by a change
7
+* **Incompatible Change**: Custom themes will be broken by a change
8
   to URL handling. Previously, we were hand-constructing URLs in the
8
   to URL handling. Previously, we were hand-constructing URLs in the
9
   templates. All site objects now store their URL in an instance slot.
9
   templates. All site objects now store their URL in an instance slot.
10
   In general, hrefs should be of the form `<a href="{$config.domain}/{$obj.url}"> ...</a>`.
10
   In general, hrefs should be of the form `<a href="{$config.domain}/{$obj.url}"> ...</a>`.
11
+* **Incompatible Change**: The interface of the `add-injection` function
12
+  has changed. If you have written a plugin which uses `add-injection`
13
+  you should update it to conform to the [new interface][add-inj-new].
14
+* **Docs**: Improved README and Theming docs. New Config File docs.
11
 * Changes to `:routing` would previously break links in the templates
15
 * Changes to `:routing` would previously break links in the templates
12
   but now work seamlessly due to the updated URL handling.
16
   but now work seamlessly due to the updated URL handling.
13
-* **Docs**: Improved README and Theming docs. New Config File docs.
14
 * Loading content is more robust when empty lines or metadata are passed.
17
 * Loading content is more robust when empty lines or metadata are passed.
15
   Thanks to @PuercoPop for the bug report and preliminary fix.
18
   Thanks to @PuercoPop for the bug report and preliminary fix.
16
 * The config `:repo` option is now deprecated as its value has become
19
 * The config `:repo` option is now deprecated as its value has become
21
 * The templates are now HTML5 valid thanks to @Ferada.
24
 * The templates are now HTML5 valid thanks to @Ferada.
22
 * Fixed a bug where RSS/Atom tag feeds were being published multiple times.
25
 * Fixed a bug where RSS/Atom tag feeds were being published multiple times.
23
 
26
 
27
+[add-inj-new]: https://github.com/redline6561/coleslaw/blob/master/docs/plugin-api.md#extension-points
28
+
24
 ## Changes for 0.9.5 (2014-06-13):
29
 ## Changes for 0.9.5 (2014-06-13):
25
 
30
 
26
 * A plugin for Incremental builds, cutting runtime for generating
31
 * A plugin for Incremental builds, cutting runtime for generating

+ 1 - 1
docs/hacking.md

213
 Currently, there is only 1 content type: POST, for blog entries.
213
 Currently, there is only 1 content type: POST, for blog entries.
214
 PAGE, a content type for static page support, is available as a plugin.
214
 PAGE, a content type for static page support, is available as a plugin.
215
 
215
 
216
-## Areas for Improvement
216
+## Areas for Improvement (i.e. The Roadmap)
217
 
217
 
218
 ### TODO for 0.9.6
218
 ### TODO for 0.9.6
219
 
219
 

+ 5 - 7
docs/plugin-api.md

15
 
15
 
16
 # Extension Points
16
 # Extension Points
17
 
17
 
18
-* **New functionality via JS**, for example the Disqus and Mathjax
19
-  plugins. In this case, the plugin's `enable` function should call
18
+* **New functionality via JS**, for example the Disqus and Mathjax plugins.
19
+  In this case, the plugin's `enable` function should call
20
   [`add-injection`](http://redlinernotes.com/docs/coleslaw.html#add-injection_func)
20
   [`add-injection`](http://redlinernotes.com/docs/coleslaw.html#add-injection_func)
21
-  with an injection and a keyword. The injection itself is a list of
22
-  the string to insert and a lambda or function that can be called on
23
-  a content instance to determine whether the injection should be
24
-  included on the page. The keyword specifies whether the injected
25
-  text goes in the HEAD or BODY element. The
21
+  with an injection and a keyword. The injection is a function that takes a
22
+  *Document* and returns a string to insert in the page or nil.
23
+  The keyword specifies whether the injected text goes in the HEAD or BODY element. The
26
   [Disqus plugin](http://github.com/redline6561/coleslaw/blob/master/plugins/disqus.lisp)
24
   [Disqus plugin](http://github.com/redline6561/coleslaw/blob/master/plugins/disqus.lisp)
27
   is a good example of this.
25
   is a good example of this.
28
 
26
 

+ 2 - 1
plugins/analytics.lisp

21
 </script>")
21
 </script>")
22
 
22
 
23
 (defun enable (&key tracking-code)
23
 (defun enable (&key tracking-code)
24
-  (add-injection (format nil *analytics-js* tracking-code) :head))
24
+  (let ((snippet (format nil *analytics-js* tracking-code)))
25
+    (add-injection (constantly snippet) :head)))

+ 4 - 2
plugins/disqus.lisp

24
      <a href=\"http://disqus.com\" class=\"dsq-brlink\">comments powered by <span class=\"logo-disqus\">Disqus</span></a>")
24
      <a href=\"http://disqus.com\" class=\"dsq-brlink\">comments powered by <span class=\"logo-disqus\">Disqus</span></a>")
25
 
25
 
26
 (defun enable (&key shortname)
26
 (defun enable (&key shortname)
27
-  (add-injection (list (format nil *disqus-header* shortname)
28
-                       (lambda (x) (typep x 'post))) :body))
27
+  (flet ((inject-p (x)
28
+           (when (typep x 'post)
29
+             (format nil *disqus-header* shortname))))
30
+    (add-injection #'inject-p :body)))

+ 4 - 3
plugins/mathjax.lisp

24
 
24
 
25
 (defun enable (&key force config (preset "TeX-AMS-MML_HTMLorMML")
25
 (defun enable (&key force config (preset "TeX-AMS-MML_HTMLorMML")
26
                  (location "http://cdn.mathjax.org/mathjax/latest/MathJax.js"))
26
                  (location "http://cdn.mathjax.org/mathjax/latest/MathJax.js"))
27
-  (flet ((plugin-p (x) (or force (mathjax-p x))))
28
-    (let ((mathjax-header (format nil *mathjax-header* config location preset)))
29
-      (add-injection (list mathjax-header #'plugin-p) :head))))
27
+  (flet ((inject-p (x)
28
+           (when (or force (mathjax-p x))
29
+             (format nil *mathjax-header* config location preset))))
30
+    (add-injection #'inject-p :head)))

+ 5 - 11
src/themes.lisp

4
   "A list that stores pairs of (string . predicate) to inject in the page.")
4
   "A list that stores pairs of (string . predicate) to inject in the page.")
5
 
5
 
6
 (defun add-injection (injection location)
6
 (defun add-injection (injection location)
7
-  "Adds an INJECTION to a given LOCATION for rendering. The INJECTION should be
8
-a string which will always be added or a (string . lambda). In the latter case,
9
-the lambda takes a single argument, a content object, i.e. a POST or INDEX, and
10
-any return value other than nil indicates the injection should be added."
11
-  (let ((result (etypecase injection
12
-                  (string (list injection #'identity))
13
-                  (list injection))))
14
-    (push result (getf *injections* location))))
7
+  "Adds an INJECTION to a given LOCATION for rendering. The INJECTION should be a
8
+function that takes a DOCUMENT and returns NIL or a STRING for template insertion."
9
+  (push result (getf *injections* location)))
15
 
10
 
16
 (defun find-injections (content)
11
 (defun find-injections (content)
17
   "Iterate over *INJECTIONS* collecting any that should be added to CONTENT."
12
   "Iterate over *INJECTIONS* collecting any that should be added to CONTENT."
18
   (flet ((injections-for (location)
13
   (flet ((injections-for (location)
19
-           (loop for (injection predicate) in (getf *injections* location)
20
-              when (funcall predicate content)
21
-              collect injection)))
14
+           (loop for injection in (getf *injections* location)
15
+              collecting (funcall injection content))))
22
     (list :head (injections-for :head)
16
     (list :head (injections-for :head)
23
           :body (injections-for :body))))
17
           :body (injections-for :body))))
24
 
18