New release CL-EMB 0.3.0
CL-EMB is a library to embed Common Lisp and special template tags into normal text files. Can be used for dynamically generated HTML pages.
You can download it from http://common-lisp.net/project/cl-emb/ or install with ASDF-Install.
CL-USER> (asdf:operate 'asdf:load-op :asdf-install) CL-USER> (asdf-install:install :cl-emb)
Changes: - API change: EXECUTE-EMB's optional parameters are now keyword parameters. You have to change your calls like this:
OLD: (emb:execute-emb "foo" '(:language "Common Lisp"))
NEW: (emb:execute-emb "foo" :env '(:language "Common Lisp"))
See the added keyword :ENV before the plist.
- Generator loops. The additional keyword parameter GENERATOR-MAKER to EXECUTE-EMB lets you supply a function, which returns a generator function. Generator functions are described on http://www.cs.northwestern.edu/academics/courses/325/readings/graham/generat...
Basically these are functions which answer to command codes :TEST (==> return true when there's no further data from the generator), :GET (==> return current value), :NEXT (==> return next value)
The new template tags @genloop and @endgenloop are used to build a loop which uses this generator function. First the function supplied to GENERATOR-MAKER is called with the corresponding keyword to the parameter of @genloop and the value in the plist with this key. ("<% @genloop foo %>" ==> first parameter :FOO, second parameter (getf env :foo)).
The loop itself tests if there are further values for iterations by calling the generator function with the command :TEST. Then the first value is fetched with :NEXT. (No :GET is used at the moment.) The returned values have to be plists.
A simple example from the README:
CL-USER> (emb:register-emb "test10" "Square root from 1 to <% @var numbers %>: <% @genloop numbers %>sqrt(<% @var number %>) = <% @var sqrt %> <% @endgenloop %>") #<CL-EMB::EMB-FUNCTION {581EC765}> CL-USER> (declare (ignore key)) (let ((i 1)) #'(lambda (cmd) (ecase cmd (:test (> i n)) (:get `(:number ,i :sqrt ,(sqrt i))) (:next (prog1 `(:number ,i :sqrt ,(sqrt i)) (unless (> i n) (incf i)))))))) MAKE-SQRT-1-TO-N-GEN CL-USER> (emb:execute-emb "test10" :env '(:numbers 10) :generator-maker 'make-sqrt-1-to-n-gen) "Square root from 1 to 10: sqrt(1) = 1.0 sqrt(2) = 1.4142135 sqrt(3) = 1.7320508 sqrt(4) = 2.0 sqrt(5) = 2.236068 sqrt(6) = 2.4494898 sqrt(7) = 2.6457512 sqrt(8) = 2.828427 sqrt(9) = 3.0 sqrt(10) = 3.1622777 "
cl-emb-announce@common-lisp.net