From 423ac382f9e73bf1ca7fc6b400f98db087cd7d22 Mon Sep 17 00:00:00 2001 From: Case Duckworth Date: Wed, 5 Jun 2024 09:21:25 -0500 Subject: Write executable This involved moving `src' to `lib' and making `bin'. `bin' holds the program, which only imports `jimmy.main' from lib. --- lib/wrap.scm | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 lib/wrap.scm (limited to 'lib/wrap.scm') diff --git a/lib/wrap.scm b/lib/wrap.scm new file mode 100644 index 0000000..f801029 --- /dev/null +++ b/lib/wrap.scm @@ -0,0 +1,21 @@ +(declare (module (jimmy wrap))) + +(import scheme (chicken base) + (jimmy emit) + (jimmy util) + (only (chicken io) read-string) + (only (chicken port) with-output-to-string) + (only (chicken string) string-translate* string-intersperse)) + +;; templates are strings with variables interpolated with "{{variables}}" + +(define-public (wrap document template) + (let* ((meta (map (lambda (el) + (cons (string-append "{{" (car el) "}}") + (string-intersperse (cdr el) " "))) + (alist-walk document 'meta))) + (body (cons "{{body}}" (emit-string document)))) + (string-translate* template (cons body meta)))) + +(define-public (wrap-with document file) + (wrap document (with-input-from-file file read-string))) -- cgit 1.4.1-21-gabe81