Provide asset observers for caching. Added ASSET-WRITE-DATE and ASSET-SOURCES, and unexported PREPROCESS-ASSET.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111
diff --git a/asset.lisp b/asset.lisp
index cd1d698..0366ef4 100644
--- a/asset.lisp
+++ b/asset.lisp
@@ -29,13 +29,18 @@
:type string)
(source-ext :initarg :source-ext
:reader asset-source-ext
- :type keyword)))
+ :type keyword)
+ (sources :initarg :sources
+ :reader asset-sources
+ :type list)))
(defgeneric asset-ext (asset))
(defgeneric asset-url (asset))
(defgeneric asset-path (asset))
(defgeneric asset-source-path (asset))
(defgeneric asset-include (output context asset &key &allow-other-keys))
+
+(defgeneric asset-write-date (asset))
(defgeneric compile-asset (asset output))
;; Base implementation
@@ -62,6 +67,13 @@
(ignore-errors (format stream "~S" (asset-path asset)))
(ignore-errors (format stream " ~S" (asset-source-path asset)))))
+(defmethod slot-unbound (class (asset asset) (slot (eql 'sources)))
+ (setf (slot-value asset 'sources) (list asset)))
+
+(defmethod asset-write-date ((asset asset))
+ (loop for a in (asset-sources asset)
+ maximize (file-write-date (asset-source-path a))))
+
(defmethod compile-asset ((asset asset) (output stream))
(let ((path (asset-source-path asset)))
(msg "CP ~A" path)
diff --git a/find.lisp b/find.lisp
index 7c394d9..c07fca0 100644
--- a/find.lisp
+++ b/find.lisp
@@ -148,9 +148,15 @@
(defmethod asset-path ((spec string))
(asset-path (find-asset spec)))
+(defmethod asset-write-date ((spec string))
+ (asset-write-date (find-asset spec)))
+
(defmethod asset-source-path ((spec string))
(asset-source-path (find-asset spec)))
+(defmethod asset-sources ((spec string))
+ (asset-sources (find-asset spec)))
+
(defmethod asset-include (output
context
(spec string)
diff --git a/package.lisp b/package.lisp
index c5353bc..faec8d8 100644
--- a/package.lisp
+++ b/package.lisp
@@ -40,6 +40,8 @@
;; Observers
#:asset-path
#:asset-url
+ #:asset-sources
+ #:asset-write-date
#:assets-dirs
#:find-asset
#:find-assets-from-spec
@@ -47,7 +49,6 @@
#:locate-precompiled-assets
;; Rendering
#:process-asset
- #:preprocess-asset
#:asset-include
;; Precompile
#:debug-msg
diff --git a/preprocess.lisp b/preprocess.lisp
index afc8361..371a7c7 100644
--- a/preprocess.lisp
+++ b/preprocess.lisp
@@ -83,19 +83,21 @@
(defgeneric preprocess-asset (asset))
-(defmethod preprocess-asset ((asset asset))
+(defmethod preprocess-asset ((asset preprocessed-asset))
(nreverse (preprocess/asset asset nil)))
-(defmethod preprocess-asset ((spec string))
- (preprocess-asset (find-asset spec)))
+(defmethod slot-unbound (class
+ (asset preprocessed-asset)
+ (slot (eql 'sources)))
+ (setf (slot-value asset 'sources) (preprocess-asset asset)))
;; Compile preprocessed assets
(defmethod compile-asset ((asset preprocessed-asset) (output stream))
(let ((assets (preprocess-asset asset)))
- (dolist (a assets)
- (msg "P ~A" (asset-source-path a))
- (process-asset a output))))
+ (loop for a in assets
+ do (msg "P ~A" (asset-source-path a))
+ do (process-asset a output))))
(defmethod compile-asset ((asset preprocessed-asset) (output pathname))
(ensure-directories-exist output)