|
|
|
@ -90,29 +90,33 @@
|
|
|
|
|
(unless output-path
|
|
|
|
|
(raise-argument-error caller "valid output path" output-path))
|
|
|
|
|
(define template-path (or maybe-template-path (get-template-for source-path output-path)))
|
|
|
|
|
(define render-cache-activated? (setup:render-cache-active source-path))
|
|
|
|
|
(define render-needed?
|
|
|
|
|
(cond
|
|
|
|
|
[force?]
|
|
|
|
|
[(not (file-exists? output-path)) 'file-missing]
|
|
|
|
|
[(mod-date-missing-or-changed? source-path template-path) 'mod-key-missing-or-changed]
|
|
|
|
|
[(not (setup:render-cache-active source-path)) 'render-cache-deactivated]
|
|
|
|
|
[(not render-cache-activated?) 'render-cache-deactivated]
|
|
|
|
|
[else #false]))
|
|
|
|
|
(when render-needed?
|
|
|
|
|
(define render-result
|
|
|
|
|
(let ([key (paths->key source-path template-path output-path)])
|
|
|
|
|
(let ([key (paths->key source-path template-path output-path)]
|
|
|
|
|
[render-thunk (λ () (render source-path template-path output-path))]) ; returns either string or bytes
|
|
|
|
|
(if render-cache-activated?
|
|
|
|
|
(hash-ref! render-ram-cache
|
|
|
|
|
;; within a session, this will prevent repeat players like "template.html.p"
|
|
|
|
|
;; from hitting the file cache repeatedly
|
|
|
|
|
key
|
|
|
|
|
(λ ()
|
|
|
|
|
(cache-ref! key
|
|
|
|
|
(λ () (render source-path template-path output-path))
|
|
|
|
|
render-thunk
|
|
|
|
|
#:dest-path 'output
|
|
|
|
|
#:notify-cache-use
|
|
|
|
|
(λ (str)
|
|
|
|
|
(message (format "from cache /~a"
|
|
|
|
|
(find-relative-path (current-project-root) output-path))))))))) ; will either be string or bytes
|
|
|
|
|
(display-to-file render-result output-path
|
|
|
|
|
(find-relative-path (current-project-root) output-path))))))
|
|
|
|
|
(render-thunk))))
|
|
|
|
|
(display-to-file render-result
|
|
|
|
|
output-path
|
|
|
|
|
#:exists 'replace
|
|
|
|
|
#:mode (if (string? render-result) 'text 'binary))))
|
|
|
|
|
|
|
|
|
@ -211,7 +215,10 @@
|
|
|
|
|
(unless template-path
|
|
|
|
|
(raise-argument-error 'render-markup-or-markdown-source "valid template path" template-path))
|
|
|
|
|
(render-from-source-or-output-path template-path) ; because template might have its own preprocessor source
|
|
|
|
|
(parameterize ([current-output-port (current-error-port)])
|
|
|
|
|
(parameterize ([current-output-port (current-error-port)]
|
|
|
|
|
[current-namespace (make-base-namespace)])
|
|
|
|
|
(define outer-ns (namespace-anchor->namespace render-module-ns))
|
|
|
|
|
(namespace-attach-module outer-ns 'pollen/setup)
|
|
|
|
|
(eval (with-syntax ([MODNAME (gensym)]
|
|
|
|
|
[SOURCE-PATH-STRING (->string source-path)]
|
|
|
|
|
[TEMPLATE-PATH-STRING (->string template-path)])
|
|
|
|
|