summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--tempest.asd2
-rw-r--r--tempest.lisp32
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 ()
- )