Pārlūkot izejas kodu

Update storage of injections to support predicates.

Brit Butler 12 gadi atpakaļ
vecāks
revīzija
04ada1eaea
3 mainītis faili ar 23 papildinājumiem un 11 dzēšanām
  1. 1 2
      src/coleslaw.lisp
  2. 12 7
      src/themes.lisp
  3. 10 2
      themes/hyde/base.tmpl

+ 1 - 2
src/coleslaw.lisp

@@ -15,8 +15,7 @@ Additional args to render CONTENT can be passed via RENDER-ARGS."
15 15
                               :content content
16 16
                               :raw (apply 'render content render-args)
17 17
                               :pubdate (make-pubdate)
18
-                              :body-inject (gethash :body *injections*)
19
-                              :head-inject (gethash :head *injections*)))))
18
+                              :injections (find-injections content)))))
20 19
     (ensure-directories-exist filepath)
21 20
     (with-open-file (out filepath
22 21
                      :direction :output

+ 12 - 7
src/themes.lisp

@@ -1,12 +1,18 @@
1 1
 (in-package :coleslaw)
2 2
 
3
-(defparameter *injections* (make-hash-table :test #'equal)
4
-  "A hash table for storing JS to inject in the theme templates.")
3
+(defparameter *injections* ()
4
+  "A list that stores pairs of (string . predicate) to inject in the page.")
5 5
 
6
-(defgeneric add-injection (str location)
7
-  (:documentation "Add STR to the list of elements injected in LOCATION.")
8
-  (:method ((str string) location)
9
-    (pushnew str (gethash location *injections*) :test #'string=)))
6
+(defun add-injection (injection location)
7
+  (push injection (getf *injections* location)))
8
+
9
+(defun find-injections (content)
10
+  (flet ((injections-for (location)
11
+           (loop for (injection . predicate) in (getf *injections* location)
12
+              when (funcall predicate content)
13
+              collect injection)))
14
+    (list :head (injections-for :head)
15
+          :body (injections-for :body))))
10 16
 
11 17
 (defun theme-package (&key (name (theme *config*)))
12 18
   "Find the package matching the theme NAME."
@@ -30,4 +36,3 @@
30 36
 ;; {template base}
31 37
 ;; {template post}
32 38
 ;; {template index}
33
-

+ 10 - 2
themes/hyde/base.tmpl

@@ -10,7 +10,11 @@
10 10
     <link href="http://fonts.googleapis.com/css?family=Inconsolata" rel="stylesheet" type="text/css" />
11 11
     <link href= "{$config.domain}/css/style.css" rel="stylesheet" type="text/css" />
12 12
     <link rel="alternate" href="{$config.domain}/rss.xml" type="application/rss+xml" />
13
-    {if $headInject} {$headInject |noAutoescape} {/if}
13
+    {if $injections.head}
14
+      {foreach $injection in $injections.head}
15
+        {$injection |noAutoescape}
16
+      {/foreach}
17
+    {/if}
14 18
   </head>
15 19
   <body>
16 20
     <div class="navigation">
@@ -23,7 +27,11 @@
23 27
     <div id="content">
24 28
       {$raw |noAutoescape}
25 29
     </div>
26
-    {if $bodyInject} {$bodyInject |noAutoescape} {/if}
30
+    {if $injections.body}
31
+      {foreach $injection in $injections.body}
32
+        {$injection |noAutoescape}
33
+      {/foreach}
34
+    {/if}
27 35
     <div class="fineprint">
28 36
       <hr>
29 37
       Unless otherwise credited all material