aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCharles Cabergs <me@cacharle.xyz>2021-01-09 21:45:15 +0100
committerCharles Cabergs <me@cacharle.xyz>2021-01-09 21:45:15 +0100
commit82b803603f519bcd91eb4a2fbc9bb5c2bfa6e168 (patch)
tree0ef60f270812fd1e7ba041773c853bc4497e5a24
parentfc9c7130b08ebc7ad4dbd0f16040251089c11f33 (diff)
downloadtemper-82b803603f519bcd91eb4a2fbc9bb5c2bfa6e168.tar.gz
temper-82b803603f519bcd91eb4a2fbc9bb5c2bfa6e168.tar.bz2
temper-82b803603f519bcd91eb4a2fbc9bb5c2bfa6e168.zip
Added render functions, Splitting into multiple files
-rw-r--r--.gitignore1
-rw-r--r--config.lisp4
-rw-r--r--helper.lisp12
-rwxr-xr-x[-rw-r--r--]temper.lisp37
4 files changed, 30 insertions, 24 deletions
diff --git a/.gitignore b/.gitignore
index 6e92f57..88de909 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1 +1,2 @@
tags
+tags.lock
diff --git a/config.lisp b/config.lisp
new file mode 100644
index 0000000..26e7a69
--- /dev/null
+++ b/config.lisp
@@ -0,0 +1,4 @@
+(defconstant +temper-open+ "<%")
+(defconstant +temper-close+ "%>")
+(defconstant +temper-close-len+ (length +temper-close+))
+(defconstant +temper-interpolate+ #\=)
diff --git a/helper.lisp b/helper.lisp
new file mode 100644
index 0000000..d2b9d77
--- /dev/null
+++ b/helper.lisp
@@ -0,0 +1,12 @@
+; read a stream into a string
+(defun read-all-stream (stream)
+ (let ((line (read-line stream nil)))
+ (if line (concatenate 'string line '(#\linefeed) (read-all-stream stream)) "")))
+
+
+; convert variable arguments into variable keyword arguments
+(defun rest-keys (&rest args)
+ (if (null args)
+ '()
+ (destructuring-bind (key value &rest args) args
+ (cons (list key value) (apply #'rest-keys args)))))
diff --git a/temper.lisp b/temper.lisp
index a039f9c..2bd63cc 100644..100755
--- a/temper.lisp
+++ b/temper.lisp
@@ -1,14 +1,8 @@
-(defun read-all ()
- (let ((line (read-line *standard-input* nil)))
- (if line
- (concatenate 'string line '(#\linefeed) (read-all))
- "")))
+#!/usr/bin/env clisp
+(load "helper.lisp")
+(load "config.lisp")
-(defconstant +temper-open+ "<%")
-(defconstant +temper-close+ "%>")
-(defconstant +temper-close-len+ (length +temper-close+))
-(defconstant +temper-interpolate+ #\=)
(defun lex (input)
(let ((pos (search +temper-open+ input)))
@@ -50,14 +44,6 @@
tokens)))
-(defun rest-keys (&rest args)
- (if (null args)
- '()
- (destructuring-bind (key value &rest args) args
- (cons (list key value) (apply #'rest-keys args)))))
-
-
-
(defun generate (tokens &rest args)
`(let ,(apply #'rest-keys args)
(progn
@@ -69,12 +55,15 @@
")"))))))
-(setq tokens (lex (read-all)))
-(setq code (generate tokens 'foo "bonjour" 'bar "aurevoir"))
-; (format t "~S" code)
-(princ (eval code))
-; (setq res (generate (lex (read-all))))
-; (format t "~A" (eval res))
+(defun render-stream (stream &rest args)
+ (setq tokens (lex (read-all-stream stream)))
+ (eval (apply #'generate (cons tokens args))))
+
+(defun render (filename &rest args)
+ (with-open-file (stream filename)
+ (apply #'render-stream (cons stream args))))
+
+; (princ (render-stream *standard-input* 'foo "bon" 'bar "jour"))
-; (format t "~S" (rest-keys :baz 10 :foo 4 :bar 5))
+(princ (render "test.html" 'foo "bon" 'bar "jour"))