Update storage of injections to support predicates.
This commit is contained in:
parent
395897e758
commit
04ada1eaea
3 changed files with 23 additions and 11 deletions
|
@ -15,8 +15,7 @@ Additional args to render CONTENT can be passed via RENDER-ARGS."
|
|||
:content content
|
||||
:raw (apply 'render content render-args)
|
||||
:pubdate (make-pubdate)
|
||||
:body-inject (gethash :body *injections*)
|
||||
:head-inject (gethash :head *injections*)))))
|
||||
:injections (find-injections content)))))
|
||||
(ensure-directories-exist filepath)
|
||||
(with-open-file (out filepath
|
||||
:direction :output
|
||||
|
|
|
@ -1,12 +1,18 @@
|
|||
(in-package :coleslaw)
|
||||
|
||||
(defparameter *injections* (make-hash-table :test #'equal)
|
||||
"A hash table for storing JS to inject in the theme templates.")
|
||||
(defparameter *injections* ()
|
||||
"A list that stores pairs of (string . predicate) to inject in the page.")
|
||||
|
||||
(defgeneric add-injection (str location)
|
||||
(:documentation "Add STR to the list of elements injected in LOCATION.")
|
||||
(:method ((str string) location)
|
||||
(pushnew str (gethash location *injections*) :test #'string=)))
|
||||
(defun add-injection (injection location)
|
||||
(push injection (getf *injections* location)))
|
||||
|
||||
(defun find-injections (content)
|
||||
(flet ((injections-for (location)
|
||||
(loop for (injection . predicate) in (getf *injections* location)
|
||||
when (funcall predicate content)
|
||||
collect injection)))
|
||||
(list :head (injections-for :head)
|
||||
:body (injections-for :body))))
|
||||
|
||||
(defun theme-package (&key (name (theme *config*)))
|
||||
"Find the package matching the theme NAME."
|
||||
|
@ -30,4 +36,3 @@
|
|||
;; {template base}
|
||||
;; {template post}
|
||||
;; {template index}
|
||||
|
||||
|
|
|
@ -10,7 +10,11 @@
|
|||
<link href="http://fonts.googleapis.com/css?family=Inconsolata" rel="stylesheet" type="text/css" />
|
||||
<link href= "{$config.domain}/css/style.css" rel="stylesheet" type="text/css" />
|
||||
<link rel="alternate" href="{$config.domain}/rss.xml" type="application/rss+xml" />
|
||||
{if $headInject} {$headInject |noAutoescape} {/if}
|
||||
{if $injections.head}
|
||||
{foreach $injection in $injections.head}
|
||||
{$injection |noAutoescape}
|
||||
{/foreach}
|
||||
{/if}
|
||||
</head>
|
||||
<body>
|
||||
<div class="navigation">
|
||||
|
@ -23,7 +27,11 @@
|
|||
<div id="content">
|
||||
{$raw |noAutoescape}
|
||||
</div>
|
||||
{if $bodyInject} {$bodyInject |noAutoescape} {/if}
|
||||
{if $injections.body}
|
||||
{foreach $injection in $injections.body}
|
||||
{$injection |noAutoescape}
|
||||
{/foreach}
|
||||
{/if}
|
||||
<div class="fineprint">
|
||||
<hr>
|
||||
Unless otherwise credited all material
|
||||
|
|
Loading…
Add table
Reference in a new issue