(I contacted Mariano by email, but since he already sent me a snippet to try out it's better if we continue the discussion in the open. I'll copy my question and his first answer(s))
I am getting my feet wet at running a web app from a binary, not from sources, and I am now trying to figure out how to use Djula templates from there.
Do you have any experience, any hints for this?
I use Deploy.
I initialize Djula templates at run time, not build time, but that is not enough for a binary, because the templates are not in a "src/templates/" directory any more, they are compiled and somewhere else in the binary, maybe…
For example:
(defun init-error-templates ()
"Set the default error templates to the system's absolute location.
Called at startup."
(format! t "--- setting default error templates to ~a~&"
(setf *error-template-directory*
(asdf:system-relative-pathname :cosmo
*default-error-template-directory*))))
I used asdf:system-relative-pathname
, it's necessary or even required when working on the REPL (where the current working directory can be
anything).
I learnt how to declare my templates as static files in the .asd:
(:module "src/templates"
:components
((:static-file "admin.html")
(:static-file "base.html")
(:static-file "list.html")
…
but I don't know how to access them.
(edit) I learned how to list them and get their names and their absolute path: lisp-tips/lisp-tips#37
But I still don't know if I can use them with my binary.
Finally, on Discord, Shinmera shows me the use of deploy:runtime-directory:
https://github.com/Shirakumo/trial/blob/master/toolkit.lisp#L46-L50
maybe it helps…
I understand that, to be present in a self-contained binary, a Lisp thing has to be compiled. So maybe I should declare all the templates I use as parameters at build time.
addition: I also went to the 40ants' Gitter, Alexander created a demo project to show how to embed any static resource in a binary: https://github.com/svetlyak40wt/cl-static-resources and yes, it's easy (just create a defvar
and store the file content), but it doesn't use Djula templates.