summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore1
-rw-r--r--package.lisp3
-rw-r--r--tempest.asd2
-rw-r--r--tempest.lisp34
-rw-r--r--template.example.lisp14
5 files changed, 48 insertions, 6 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..e8720a2
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1 @@
+/template.example.html
diff --git a/package.lisp b/package.lisp
index 0c58617..19eaecc 100644
--- a/package.lisp
+++ b/package.lisp
@@ -1,3 +1,4 @@
(defpackage #:tempest
(:use #:cl)
- (:local-nicknames (#:file-notify #:org.shirakumo.file-notify)))
+ (:local-nicknames (#:file-notify #:org.shirakumo.file-notify))
+ (:import-from :arrows :-> :->> :as->))
diff --git a/tempest.asd b/tempest.asd
index c506418..1b8f438 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")
+ :depends-on ("file-notify" "spinneret" "str" "arrows")
:components ((:file "package")
(:file "tempest")))
diff --git a/tempest.lisp b/tempest.lisp
index 34b8c01..e08b4d0 100644
--- a/tempest.lisp
+++ b/tempest.lisp
@@ -2,11 +2,37 @@
(defparameter path-to-watch "./")
-(defun main ()
+(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))
+ content NIL)))
+
+(defun compile-to-html (tempest-string)
+ "Compile tempest file content to HTML string using spinneret."
+ (let ((*read-eval* nil))
+ (-> (concatenate 'string "(spinneret:with-html " tempest-string ")")
+ read-from-string
+ eval)))
+
+(defun build-template (filename)
+ (let ((raw (read-tempest-string filename)))
+ (if raw
+ (let ((target-file (str:replace-all ".lisp" ".html" filename)))
+ (with-open-file (*standard-output* target-file
+ :direction :output
+ :if-exists :supersede
+ :if-does-not-exist :create)
+ (compile-to-html raw)
+ target-file))
+ NIL)))
+
+(defun watch ()
(file-notify:watch path-to-watch)
(file-notify:with-events (file change :timeout T)
(when (str:ends-with-p ".lisp" file :ignore-case T)
- (print (list file change))))
- (format t "Tempest is starting."))
+ (print (list file change)))))
-(main)
+(defun main ()
+ )
diff --git a/template.example.lisp b/template.example.lisp
new file mode 100644
index 0000000..80ddcfe
--- /dev/null
+++ b/template.example.lisp
@@ -0,0 +1,14 @@
+;;;; TEMPEST
+;;;; out = "template.html"
+
+(:doctype)
+(:html
+ (:head
+ (:title "This is an example"))
+ (:body
+ (:main :class "container"
+ (:h1
+ (:span "If I ever start to think straight")
+ (:span "This heart will start a " (:em "tempest") " in me.")))
+ (:p "So yeah, I'm a Paramore fan.")
+ (:p "Just go and create something amazing.")))