diff options
Diffstat (limited to 'src/wrap.scm')
-rw-r--r-- | src/wrap.scm | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/src/wrap.scm b/src/wrap.scm index 3537dea..0ed8868 100644 --- a/src/wrap.scm +++ b/src/wrap.scm | |||
@@ -1,13 +1,23 @@ | |||
1 | (declare (module (jimmy wrap))) | 1 | (declare (module (jimmy wrap))) |
2 | 2 | ||
3 | (import scheme (chicken base) | 3 | (import scheme (chicken base) |
4 | (jimmy emit) | ||
4 | (jimmy util) | 5 | (jimmy util) |
5 | (chicken format)) | 6 | (only (chicken io) read-string) |
7 | (only (chicken port) with-output-to-string) | ||
8 | (only (chicken string) string-translate*)) | ||
6 | 9 | ||
7 | ;;; open question: how to do templating? | 10 | ;; templates are strings with variables interpolated with "{{variables}}" |
8 | 11 | ||
9 | (define-public (wrap document template) | 12 | (define-public (wrap document template) |
10 | #f) | 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}}" | ||
18 | (with-output-to-string | ||
19 | (lambda () (emit document)))))) | ||
20 | (string-translate* template (cons body meta)))) | ||
11 | 21 | ||
12 | (define (meta-get key document) | 22 | (define-public (wrap-with document file) |
13 | (alist-walk document 'meta key)) | 23 | (wrap document (with-input-from-file file read-string))) |