diff options
| author | eltrac <hi@eltr.ac> | 2026-08-26 21:54:51 +0800 |
|---|---|---|
| committer | eltrac <hi@eltr.ac> | 2026-08-26 21:54:51 +0800 |
| commit | dd6d84581ef3a2fd1cca8c368ea54eb103033c66 (patch) | |
| tree | e517a8dc4d0a615a0f7df8ed45b83d1b8f8f89d8 | |
| parent | bdeb8e4b397dcf3ba61ac1d38e046236f8d44a5d (diff) | |
main: build templates in a dir and watch for a dir
| -rw-r--r-- | tempest.asd | 2 | ||||
| -rw-r--r-- | tempest.lisp | 32 |
2 files changed, 22 insertions, 12 deletions
diff --git a/tempest.asd b/tempest.asd index 1b8f438..44e5c7c 100644 --- a/tempest.asd +++ b/tempest.asd @@ -6,6 +6,6 @@ :license "AGPL-v3-or-later" :version "0.0.1" :serial t - :depends-on ("file-notify" "spinneret" "str" "arrows") + :depends-on ("file-notify" "spinneret" "str" "arrows" "cl-fad") :components ((:file "package") (:file "tempest"))) diff --git a/tempest.lisp b/tempest.lisp index e08b4d0..a0ecb22 100644 --- a/tempest.lisp +++ b/tempest.lisp @@ -1,16 +1,13 @@ (in-package #:tempest) -(defparameter path-to-watch "./") - (defun read-tempest-string (filename) "Read file content as string. If it's not a .lisp file and does not have tempest comment at top, return NIL." (let ((content (uiop:read-file-string filename))) - (if (and (str:ends-with-p ".lisp" filename :ignore-case T) - (str:starts-with-p ";;;; TEMPEST" content)) + (if (str:starts-with-p ";;;; TEMPEST" content) content NIL))) (defun compile-to-html (tempest-string) - "Compile tempest file content to HTML string using spinneret." + "Compiles spinneret string to HTML string. Redirects to standard output." (let ((*read-eval* nil)) (-> (concatenate 'string "(spinneret:with-html " tempest-string ")") read-from-string @@ -28,11 +25,24 @@ target-file)) NIL))) -(defun watch () - (file-notify:watch path-to-watch) +(defun build (dir) + (cl-fad:walk-directory dir + (lambda (path-name) + (let ((name (namestring path-name))) + (when (str:ends-with-p ".lisp" name :ignore-case T) + (build-template name)))))) + +;; TODO handle frequent/simultaneous events, only build once +;; TODO handle :MOVE event, delete old one and create new one +;; TODO handle :DELETE event, delete template as well +(defun watch (dir) + (file-notify:watch dir) (file-notify:with-events (file change :timeout T) - (when (str:ends-with-p ".lisp" file :ignore-case T) - (print (list file change))))) + (when (and (str:ends-with-p ".lisp" file :ignore-case T) + (or (eql change :MODIFY) + (eql change :CREATE))) + (let ((built-file (build-template file))) + (if built-file + (format t "Built ~a, because of ~a~%" built-file change) + nil))))) -(defun main () - ) |
