From 815e669310f5e73d13cc121bd7f6cdaec5b6ec0d Mon Sep 17 00:00:00 2001 From: Case Duckworth Date: Sun, 26 May 2024 22:49:44 -0500 Subject: Updates! I totally forgot to actually commit things for a while, so uh Updates!!! --- src/wrap.scm | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) (limited to 'src/wrap.scm') 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 @@ (declare (module (jimmy wrap))) (import scheme (chicken base) + (jimmy emit) (jimmy util) - (chicken format)) + (only (chicken io) read-string) + (only (chicken port) with-output-to-string) + (only (chicken string) string-translate*)) -;;; open question: how to do templating? +;; templates are strings with variables interpolated with "{{variables}}" (define-public (wrap document template) - #f) + (let* ((meta (map (lambda (el) + (cons (string-append "{{" (car el) "}}") + (string-intersperse (cdr el) " "))) + (alist-walk document 'meta))) + (body (cons "{{body}}" + (with-output-to-string + (lambda () (emit document)))))) + (string-translate* template (cons body meta)))) -(define (meta-get key document) - (alist-walk document 'meta key)) +(define-public (wrap-with document file) + (wrap document (with-input-from-file file read-string))) -- cgit 1.4.1-21-gabe81