aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.md7
-rw-r--r--builtin.lisp4
-rwxr-xr-xtemper.lisp32
-rw-r--r--test.html6
4 files changed, 28 insertions, 21 deletions
diff --git a/README.md b/README.md
index c8feed5..d3cba3d 100644
--- a/README.md
+++ b/README.md
@@ -21,8 +21,8 @@ Put the result of a form in the template with `<%=`.
```html
<ul>
- <% (dotimes (_ 10)) %>
- <li> <%= i %> </li>
+ <% (dotimes (n 10)) %>
+ <li> <%= n %> </li>
<% ) %>
</ul>
```
@@ -49,3 +49,6 @@ Use the `render` function to include a template in another.
and check if `about.lisp.html` exists
* [ ] Makefile to compile and install
* [ ] escape interpolated value
+* [ ] file/directory command line arguments
+* [ ] passing template variable in command line
+* [ ] extends a base template (like Django)
diff --git a/builtin.lisp b/builtin.lisp
index 3da200e..8cfc25e 100644
--- a/builtin.lisp
+++ b/builtin.lisp
@@ -1,7 +1,3 @@
-(load "/home/charles/.clisprc.lisp")
-(ql:quickload "uiop")
-
-
(defun make-index (dirname &key (item-tag "li") (surrounding-tag "ul") (include-date nil))
(setf filepaths (uiop:directory-files dirname))
; (when test (delete-if #'(lambda (x) (not (test x))) filenames))
diff --git a/temper.lisp b/temper.lisp
index 9f5350c..36732d2 100755
--- a/temper.lisp
+++ b/temper.lisp
@@ -1,5 +1,7 @@
#!/usr/bin/clisp
+(load "/home/charles/.clisprc.lisp")
+(ql:quickload "uiop")
(load "helper.lisp")
(load "config.lisp")
(load "builtin.lisp")
@@ -60,16 +62,28 @@
")"))))))
-(defun render-stream (stream &rest args)
- (setq tokens (lex (read-all-stream stream)))
- (eval (apply #'generate (cons tokens args))))
+(defgeneric render (input &rest args))
-(defun render (filename &rest args)
- (with-open-file (stream filename)
- (apply #'render-stream (cons stream args))))
+(defmethod render ((input stream) &rest args)
+ (prog1
+ (eval (apply #'generate (cons (lex (read-all-stream input)) args)))
+ (setf *temper-buf* "")))
-(princ (render-stream *standard-input* 'foo "bon" 'bar "jour"))
+(defmethod render ((filename string) &rest args)
+ (with-open-file (input filename)
+ (apply #'render (cons input args))))
-; (princ (render "test.html" 'foo "bon" 'bar "jour"))
-; (print (make-index "d"))
+(when (null *args*)
+ (princ (render *standard-input*))
+ (exit))
+
+
+(dolist (arg *args*)
+ (if (uiop:directory-pathname-p arg)
+ (uiop:collect-sub*directories ; TODO
+ dirname
+ (constantly t)
+ (constantly t)
+ (lambda (f) (print f)))
+ (princ (render arg))))
diff --git a/test.html b/test.html
deleted file mode 100644
index fada913..0000000
--- a/test.html
+++ /dev/null
@@ -1,6 +0,0 @@
-<h1><%= foo %> | <%= bar %></h1>
-<ul>
- <% (dotimes (n 10) %>
- <li><%= (+ n 4 5) %></li>
- <% ) %>
-</ul>