diff options
author | Case Duckworth | 2024-06-05 09:21:25 -0500 |
---|---|---|
committer | Case Duckworth | 2024-06-05 09:21:25 -0500 |
commit | 423ac382f9e73bf1ca7fc6b400f98db087cd7d22 (patch) | |
tree | 1992e3dc7e71cd40eb7cdbc0b6d0c3cdf82c4332 /lib/wrap.scm | |
parent | Update README, add COPYING (diff) | |
download | jimmy-423ac382f9e73bf1ca7fc6b400f98db087cd7d22.tar.gz jimmy-423ac382f9e73bf1ca7fc6b400f98db087cd7d22.zip |
Write executable
This involved moving `src' to `lib' and making `bin'. `bin' holds the program, which only imports `jimmy.main' from lib.
Diffstat (limited to 'lib/wrap.scm')
-rw-r--r-- | lib/wrap.scm | 21 |
1 files changed, 21 insertions, 0 deletions
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 @@ | |||
1 | (declare (module (jimmy wrap))) | ||
2 | |||
3 | (import scheme (chicken base) | ||
4 | (jimmy emit) | ||
5 | (jimmy util) | ||
6 | (only (chicken io) read-string) | ||
7 | (only (chicken port) with-output-to-string) | ||
8 | (only (chicken string) string-translate* string-intersperse)) | ||
9 | |||
10 | ;; templates are strings with variables interpolated with "{{variables}}" | ||
11 | |||
12 | (define-public (wrap document template) | ||
13 | (let* ((meta (map (lambda (el) | ||
14 | (cons (string-append "{{" (car el) "}}") | ||
15 | (string-intersperse (cdr el) " "))) | ||
16 | (alist-walk document 'meta))) | ||
17 | (body (cons "{{body}}" (emit-string document)))) | ||
18 | (string-translate* template (cons body meta)))) | ||
19 | |||
20 | (define-public (wrap-with document file) | ||
21 | (wrap document (with-input-from-file file read-string))) | ||