repos
/
Oh, Ducks!
/ annotate_shade
summary
|
shortlog
|
log
|
tree
|
commit
|
commitdiff
|
headdiff
|
annotate
|
headblob
|
headfilediff
|
filehistory
normal
|
plain
|
shade
|
zebra
&allow-other-keys is not actually necessary
Annotate for file /templates.lisp
2009-11-18 pix
1
(in-package #:oh-ducks)
10:23:05 '
2
'
3
(defclass css-selector-template (unify::expression-template)
2009-11-21 pix
4
((parser :initarg :parser :initform nil) ;; subtype generally determines parser
2009-11-18 pix
5
(specifiers :reader specifiers) ;; list of (specifier . variable) and (specifier . template)
10:23:05 '
6
))
'
7
2009-11-21 pix
8
(defvar *model-handler-map* nil "A mapping between model types and handler functions.")
16:12:13 '
9
(defun add-handler (model handler)
'
10
(push (cons model handler) *model-handler-map*))
'
11
(defun get-handler-for-model (model)
'
12
(let ((handler (cdr (assoc model *model-handler-map*))))
'
13
(typecase handler
'
14
(null nil)
'
15
(function (funcall handler))
'
16
(symbol (funcall (symbol-function handler)))
'
17
(t handler))))
2009-11-18 pix
18
10:23:05 '
19
(defvar *default-parser* nil "Determines the default parser when none is specified.")
'
20
'
21
(defun %spec-includes-opts (spec)
'
22
(keywordp (first (second spec))))
'
23
'
24
(defun combine-selectors (selector parent)
'
25
(let ((combinator (car (last selector))))
'
26
(cond
'
27
((null parent)
'
28
selector)
'
29
((combinator-p combinator)
'
30
(setf (slot-value combinator 'matcher) parent)
'
31
selector)
'
32
(t
'
33
(nconc selector (list (make-instance 'descendant-combinator :matcher parent)))))))
'
34
'
35
(defun parse-specifiers (specs template parent)
'
36
(loop :for (css-specifier . rest) :in specs
'
37
:for selector = (combine-selectors (parse-selector css-specifier) parent)
'
38
:collect (cons selector
'
39
(cond
'
40
((unify::template-p rest) rest)
'
41
((unify::variablep rest) rest)
'
42
((consp rest)
'
43
(make-instance (class-of template)
'
44
:spec (list* (first (template-spec template)) rest)
'
45
:css-specifiers rest
'
46
:parent selector))))))
'
47
2010-01-02 pix
48
(defmethod initialize-instance :after ((template css-selector-template) &key css-specifiers parent)
2009-11-18 pix
49
(let* ((spec (template-spec template))
10:23:05 '
50
(specifiers-and-vars (or css-specifiers (if (%spec-includes-opts spec)
'
51
(cddr spec)
'
52
(rest spec)))))
'
53
(setf (slot-value template 'specifiers)
'
54
(parse-specifiers specifiers-and-vars template parent))))
2009-12-04 pix
55
;; Don't bother trying to save :parser when compiling
05:16:28 '
56
(defmethod make-load-form ((object css-selector-template) &optional env)
'
57
(declare (ignore env))
'
58
`(make-template ',(first (template-spec object)) ',(template-spec object)))
'
59