diff options
| author | Charles Cabergs <me@cacharle.xyz> | 2020-12-08 18:43:30 +0100 |
|---|---|---|
| committer | Charles Cabergs <me@cacharle.xyz> | 2020-12-08 18:43:30 +0100 |
| commit | cf57d609d10fa2ea9f690bcca6896b5926340e12 (patch) | |
| tree | 16bbff764f4355a0fcf1e9f82c94e2bad56cfc70 | |
| download | temper-cf57d609d10fa2ea9f690bcca6896b5926340e12.tar.gz temper-cf57d609d10fa2ea9f690bcca6896b5926340e12.tar.bz2 temper-cf57d609d10fa2ea9f690bcca6896b5926340e12.zip | |
Initial commit
| -rw-r--r-- | README.md | 11 | ||||
| -rw-r--r-- | temper.lisp | 30 | ||||
| -rw-r--r-- | test.html | 13 |
3 files changed, 54 insertions, 0 deletions
diff --git a/README.md b/README.md new file mode 100644 index 0000000..ade9374 --- /dev/null +++ b/README.md @@ -0,0 +1,11 @@ +# temper + +Common Listp templating language. + +## Usage + +```html +{% (loop :for i in '(1 2 3)) %} + <li> {{ i }} </li> +{% ) %} +``` diff --git a/temper.lisp b/temper.lisp new file mode 100644 index 0000000..5ff5008 --- /dev/null +++ b/temper.lisp @@ -0,0 +1,30 @@ +(defun read-all () + (let ((line (read-line *standard-input* nil))) + (if line + (concatenate 'string line '(#\linefeed) (read-all)) + ""))) + + +(setq *temper-open* "{%") +(setq *temper-close* "%}") + +(defun parse (input) + (let ((pos (search *temper-open* input))) + (if (null pos) + (list "\"" input "\"") + (let* ((before (subseq input 0 pos)) + (input (subseq input pos)) + (end-pos (search *temper-close* input)) + (close-len (length *temper-close*)) + (code (subseq input close-len end-pos)) + (input (subseq input (+ end-pos close-len)))) + (append (list "\"" before "\"" code) (parse input)))))) + + + +(setq res (append '("(concatenate 'string ") (parse (read-all)) '(" ) ") )) +(setq str (format nil "~{~A~^ ~}" res)) +(princ str) +; (print (eval (read-from-string str))) + +; (read-from-string (parse (read-all))) diff --git a/test.html b/test.html new file mode 100644 index 0000000..55009bb --- /dev/null +++ b/test.html @@ -0,0 +1,13 @@ +asdf +{% (string-upcase %} +<p> + bonjour + {% (subseq %} + foofoofoo + {% 3 6) %} + aurevoir +</p> + +{% ) %} + +yooooo |
