(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)))