|
|
@ -6,6 +6,7 @@
|
|
|
|
sugar/define
|
|
|
|
sugar/define
|
|
|
|
sugar/file
|
|
|
|
sugar/file
|
|
|
|
sugar/coerce
|
|
|
|
sugar/coerce
|
|
|
|
|
|
|
|
version/utils
|
|
|
|
"private/file-utils.rkt"
|
|
|
|
"private/file-utils.rkt"
|
|
|
|
"cache.rkt"
|
|
|
|
"cache.rkt"
|
|
|
|
"private/log.rkt"
|
|
|
|
"private/log.rkt"
|
|
|
@ -69,7 +70,7 @@
|
|
|
|
has/is-markup-source?
|
|
|
|
has/is-markup-source?
|
|
|
|
has/is-scribble-source?
|
|
|
|
has/is-scribble-source?
|
|
|
|
has/is-markdown-source?))])
|
|
|
|
has/is-markdown-source?))])
|
|
|
|
(pred so-path))
|
|
|
|
(pred so-path))
|
|
|
|
(define-values (source-path output-path) (->source+output-paths so-path))
|
|
|
|
(define-values (source-path output-path) (->source+output-paths so-path))
|
|
|
|
(render-to-file-if-needed source-path #f output-path)]
|
|
|
|
(render-to-file-if-needed source-path #f output-path)]
|
|
|
|
[(pagetree-source? so-path) (render-pagenodes so-path)])
|
|
|
|
[(pagetree-source? so-path) (render-pagenodes so-path)])
|
|
|
@ -140,19 +141,21 @@
|
|
|
|
(define render-proc (for/first ([test (in-list tests)]
|
|
|
|
(define render-proc (for/first ([test (in-list tests)]
|
|
|
|
[render-proc (in-list render-procs)]
|
|
|
|
[render-proc (in-list render-procs)]
|
|
|
|
#:when (test source-path))
|
|
|
|
#:when (test source-path))
|
|
|
|
render-proc))
|
|
|
|
render-proc))
|
|
|
|
(unless render-proc
|
|
|
|
(unless render-proc
|
|
|
|
(raise-argument-error 'render (format "valid rendering function for ~a" source-path) render-proc))
|
|
|
|
(raise-argument-error 'render (format "valid rendering function for ~a" source-path) render-proc))
|
|
|
|
|
|
|
|
|
|
|
|
(define template-path (or maybe-template-path (get-template-for source-path output-path)))
|
|
|
|
(define template-path (or maybe-template-path (get-template-for source-path output-path)))
|
|
|
|
|
|
|
|
|
|
|
|
;; output-path and template-path may not have an extension, so check them in order with fallback
|
|
|
|
;; output-path and template-path may not have an extension, so check them in order with fallback
|
|
|
|
(message (format "rendering /~a"
|
|
|
|
(message (format "rendering /~a"
|
|
|
|
(find-relative-path (current-project-root) source-path)))
|
|
|
|
(find-relative-path (current-project-root) source-path)))
|
|
|
|
(match-define-values ((cons render-result _) _ real _)
|
|
|
|
(match-define-values ((cons render-result _) _ real _)
|
|
|
|
(parameterize ([current-poly-target (->symbol (or (get-ext output-path)
|
|
|
|
(parameterize ([current-directory (->complete-path (dirname source-path))]
|
|
|
|
|
|
|
|
[current-poly-target (->symbol (or (get-ext output-path)
|
|
|
|
(and template-path (get-ext template-path))
|
|
|
|
(and template-path (get-ext template-path))
|
|
|
|
(current-poly-target)))])
|
|
|
|
(current-poly-target)))]
|
|
|
|
|
|
|
|
[current-render-source source-path])
|
|
|
|
(time-apply render-proc (list source-path template-path output-path))))
|
|
|
|
(time-apply render-proc (list source-path template-path output-path))))
|
|
|
|
;; wait till last possible moment to store mod dates, because render-proc may also trigger its own subrenders
|
|
|
|
;; wait till last possible moment to store mod dates, because render-proc may also trigger its own subrenders
|
|
|
|
;; e.g., of a template.
|
|
|
|
;; e.g., of a template.
|
|
|
@ -170,13 +173,14 @@
|
|
|
|
;; todo: add test to avoid copying if unnecessary (good idea in case the file is large)
|
|
|
|
;; todo: add test to avoid copying if unnecessary (good idea in case the file is large)
|
|
|
|
(file->bytes source-path))
|
|
|
|
(file->bytes source-path))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(define-namespace-anchor render-module-ns)
|
|
|
|
|
|
|
|
|
|
|
|
(define (render-scribble-source source-path . _)
|
|
|
|
(define (render-scribble-source source-path . _)
|
|
|
|
;((complete-path?) #:rest any/c . ->* . string?)
|
|
|
|
;((complete-path?) #:rest any/c . ->* . string?)
|
|
|
|
(local-require scribble/core scribble/manual (prefix-in scribble- scribble/render))
|
|
|
|
(local-require scribble/core scribble/manual (prefix-in scribble- scribble/render))
|
|
|
|
(define source-dir (dirname source-path))
|
|
|
|
(define source-dir (dirname source-path))
|
|
|
|
;; make fresh namespace for scribble rendering (avoids dep/zo caching)
|
|
|
|
;; make fresh namespace for scribble rendering (avoids dep/zo caching)
|
|
|
|
(parameterize ([current-namespace (make-base-namespace)]
|
|
|
|
(parameterize ([current-namespace (make-base-namespace)])
|
|
|
|
[current-directory (->complete-path source-dir)])
|
|
|
|
|
|
|
|
(define outer-ns (namespace-anchor->namespace render-module-ns))
|
|
|
|
(define outer-ns (namespace-anchor->namespace render-module-ns))
|
|
|
|
(namespace-attach-module outer-ns 'scribble/core)
|
|
|
|
(namespace-attach-module outer-ns 'scribble/core)
|
|
|
|
(namespace-attach-module outer-ns 'scribble/manual)
|
|
|
|
(namespace-attach-module outer-ns 'scribble/manual)
|
|
|
@ -193,11 +197,7 @@
|
|
|
|
(delete-file (->output-path source-path))))
|
|
|
|
(delete-file (->output-path source-path))))
|
|
|
|
|
|
|
|
|
|
|
|
(define (render-preproc-source source-path . _)
|
|
|
|
(define (render-preproc-source source-path . _)
|
|
|
|
(parameterize ([current-directory (->complete-path (dirname source-path))])
|
|
|
|
(cached-doc (->string source-path)))
|
|
|
|
(render-datum-through-eval (syntax->datum
|
|
|
|
|
|
|
|
(with-syntax ([SOURCE-PATH source-path])
|
|
|
|
|
|
|
|
#'(begin (require pollen/cache)
|
|
|
|
|
|
|
|
(cached-doc SOURCE-PATH)))))))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(define (render-markup-or-markdown-source source-path [maybe-template-path #f] [maybe-output-path #f])
|
|
|
|
(define (render-markup-or-markdown-source source-path [maybe-template-path #f] [maybe-output-path #f])
|
|
|
|
(define output-path (or maybe-output-path (->output-path source-path)))
|
|
|
|
(define output-path (or maybe-output-path (->output-path source-path)))
|
|
|
@ -207,36 +207,18 @@
|
|
|
|
(unless template-path
|
|
|
|
(unless template-path
|
|
|
|
(raise-argument-error 'render-markup-or-markdown-source "valid template path" 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
|
|
|
|
(render-from-source-or-output-path template-path) ; because template might have its own preprocessor source
|
|
|
|
(define datum-to-eval
|
|
|
|
(parameterize ([current-output-port (current-error-port)])
|
|
|
|
(syntax->datum
|
|
|
|
(eval (with-syntax ([MODNAME (gensym)]
|
|
|
|
(with-syntax ([DIRECTORY-REQUIRE-FILES (require-directory-require-files source-path)]
|
|
|
|
[SOURCE-PATH-STRING (->string source-path)]
|
|
|
|
[DOC-ID (setup:main-export source-path)]
|
|
|
|
[TEMPLATE-PATH-STRING (->string template-path)]
|
|
|
|
[META-ID (setup:meta-export source-path)]
|
|
|
|
[REQUIRE (if (version<? (version) "6.3") 'local-require 'require)])
|
|
|
|
[SOURCE-PATH-STRING (path->string source-path)]
|
|
|
|
#'(begin
|
|
|
|
[CPR (current-project-root)]
|
|
|
|
(module MODNAME pollen/private/render-helper
|
|
|
|
[HERE-PATH-KEY (setup:here-path-key source-path)]
|
|
|
|
#:source SOURCE-PATH-STRING
|
|
|
|
[COMMAND-CHAR (setup:command-char source-path)]
|
|
|
|
#:template TEMPLATE-PATH-STRING
|
|
|
|
[TEMPLATE-PATH (->string template-path)])
|
|
|
|
#:result-id result)
|
|
|
|
#'(begin
|
|
|
|
(REQUIRE 'MODNAME)
|
|
|
|
(require (for-syntax racket/base)
|
|
|
|
result)))))
|
|
|
|
pollen/private/external/include-template
|
|
|
|
|
|
|
|
pollen/cache
|
|
|
|
|
|
|
|
pollen/private/log
|
|
|
|
|
|
|
|
pollen/pagetree
|
|
|
|
|
|
|
|
pollen/core)
|
|
|
|
|
|
|
|
DIRECTORY-REQUIRE-FILES
|
|
|
|
|
|
|
|
(parameterize ([current-pagetree (make-project-pagetree CPR)]
|
|
|
|
|
|
|
|
[current-metas (cached-metas SOURCE-PATH-STRING)])
|
|
|
|
|
|
|
|
(local-require pollen/template pollen/top)
|
|
|
|
|
|
|
|
(define DOC-ID (cached-doc SOURCE-PATH-STRING))
|
|
|
|
|
|
|
|
(define META-ID (current-metas))
|
|
|
|
|
|
|
|
(define here (path->pagenode (or (select-from-metas 'HERE-PATH-KEY META-ID) 'unknown)))
|
|
|
|
|
|
|
|
(if (bytes? DOC-ID) ; if main export is binary, just pass it through
|
|
|
|
|
|
|
|
DOC-ID
|
|
|
|
|
|
|
|
(include-template #:command-char COMMAND-CHAR (file TEMPLATE-PATH))))))))
|
|
|
|
|
|
|
|
;; set current-directory because include-template wants to work relative to source location
|
|
|
|
|
|
|
|
(parameterize ([current-directory (->complete-path (dirname source-path))])
|
|
|
|
|
|
|
|
(render-datum-through-eval datum-to-eval)))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(define (templated-source? path)
|
|
|
|
(define (templated-source? path)
|
|
|
|
(or (markup-source? path) (markdown-source? path)))
|
|
|
|
(or (markup-source? path) (markdown-source? path)))
|
|
|
@ -244,7 +226,7 @@
|
|
|
|
(define (file-exists-or-has-source? path) ; path could be #f
|
|
|
|
(define (file-exists-or-has-source? path) ; path could be #f
|
|
|
|
(and path (for/first ([proc (in-list (list values ->preproc-source-path ->null-source-path))]
|
|
|
|
(and path (for/first ([proc (in-list (list values ->preproc-source-path ->null-source-path))]
|
|
|
|
#:when (file-exists? (proc path)))
|
|
|
|
#:when (file-exists? (proc path)))
|
|
|
|
path)))
|
|
|
|
path)))
|
|
|
|
|
|
|
|
|
|
|
|
(define (get-template-from-metas source-path output-path-ext)
|
|
|
|
(define (get-template-from-metas source-path output-path-ext)
|
|
|
|
(with-handlers ([exn:fail:contract? (λ (e) #f)]) ; in case source-path doesn't work with cached-require
|
|
|
|
(with-handlers ([exn:fail:contract? (λ (e) #f)]) ; in case source-path doesn't work with cached-require
|
|
|
@ -275,7 +257,7 @@
|
|
|
|
;; output-path may not have an extension
|
|
|
|
;; output-path may not have an extension
|
|
|
|
(define output-path-ext (or (get-ext output-path) (current-poly-target)))
|
|
|
|
(define output-path-ext (or (get-ext output-path) (current-poly-target)))
|
|
|
|
(for/or ([proc (list get-template-from-metas get-default-template get-fallback-template)])
|
|
|
|
(for/or ([proc (list get-template-from-metas get-default-template get-fallback-template)])
|
|
|
|
(file-exists-or-has-source? (proc source-path output-path-ext))))))
|
|
|
|
(file-exists-or-has-source? (proc source-path output-path-ext))))))
|
|
|
|
|
|
|
|
|
|
|
|
(module-test-external
|
|
|
|
(module-test-external
|
|
|
|
(require pollen/setup sugar/file sugar/coerce)
|
|
|
|
(require pollen/setup sugar/file sugar/coerce)
|
|
|
@ -296,10 +278,3 @@
|
|
|
|
(check-false (get-template-for (->complete-path "foo.poly.pm")))
|
|
|
|
(check-false (get-template-for (->complete-path "foo.poly.pm")))
|
|
|
|
(check-equal? (get-template-for (->complete-path "foo.html.pm")) fallback.html)))
|
|
|
|
(check-equal? (get-template-for (->complete-path "foo.html.pm")) fallback.html)))
|
|
|
|
|
|
|
|
|
|
|
|
(define-namespace-anchor render-module-ns)
|
|
|
|
|
|
|
|
(define (render-datum-through-eval datum-to-eval)
|
|
|
|
|
|
|
|
;; render a datum, not a syntax object, so that it can have fresh bindings.
|
|
|
|
|
|
|
|
(parameterize ([current-namespace (make-base-namespace)]
|
|
|
|
|
|
|
|
[current-output-port (current-error-port)])
|
|
|
|
|
|
|
|
(namespace-attach-module (namespace-anchor->namespace render-module-ns) 'pollen/setup) ; brings in params
|
|
|
|
|
|
|
|
(eval datum-to-eval)))
|
|
|
|
|
|
|
|