source+output-path function

pull/9/head
Matthew Butterick 11 years ago
parent 2137b702b1
commit 8b13215ac7

@ -117,7 +117,8 @@
(with-syntax ([stem-source? (format-id stx "~a-source?" #'stem)] (with-syntax ([stem-source? (format-id stx "~a-source?" #'stem)]
[has-stem-source? (format-id stx "has-~a-source?" #'stem)] [has-stem-source? (format-id stx "has-~a-source?" #'stem)]
[has/is-stem-source? (format-id stx "has/is-~a-source?" #'stem)] [has/is-stem-source? (format-id stx "has/is-~a-source?" #'stem)]
[->stem-source-path (format-id stx "->~a-source-path" #'stem)]) [->stem-source-path (format-id stx "->~a-source-path" #'stem)]
[->stem-source+output-paths (format-id stx "->~a-source+output-paths" #'stem)])
#'(begin #'(begin
;; does file have particular extension ;; does file have particular extension
(define+provide/contract (stem-source? x) (define+provide/contract (stem-source? x)
@ -137,7 +138,12 @@
;; add the file extension if it's not there ;; add the file extension if it's not there
(define+provide/contract (->stem-source-path x) (define+provide/contract (->stem-source-path x)
(pathish? . -> . path?) (pathish? . -> . path?)
(->path (if (stem-source? x) x (add-ext x file-ext))))))])) (->path (if (stem-source? x) x (add-ext x file-ext))))
(define+provide/contract (->stem-source+output-paths path)
(pathish? . -> . (values path? path?))
(values (->complete-path (->stem-source-path path))
(->complete-path (->output-path path))))))]))
(make-source-utility-functions preproc world:preproc-source-ext) (make-source-utility-functions preproc world:preproc-source-ext)
@ -148,7 +154,6 @@
(define+provide/contract (->output-path x) (define+provide/contract (->output-path x)
(coerce/path? . -> . coerce/path?) (coerce/path? . -> . coerce/path?)
(if (or (markup-source? x) (preproc-source? x) (null-source? x)) (if (or (markup-source? x) (preproc-source? x) (null-source? x))

@ -122,11 +122,11 @@
(define (render-null-source path #:force force) (define (render-null-source path #:force force)
;; this op is trivial & fast, so do it every time. ;; this op is trivial & fast, so do it every time.
(define source-path (->complete-path (->null-source-path path))) (define-values (source-path output-path) (->null-source+output-paths path))
(define output-path (->complete-path (->output-path path)))
(message (format "Copying ~a to ~a" (message (format "Copying ~a to ~a"
(file-name-from-path source-path) (file-name-from-path source-path)
(file-name-from-path output-path))) (file-name-from-path output-path)))
(copy-file source-path output-path #t)) (copy-file source-path output-path #t))
(define (render-preproc-source source-path output-path) (define (render-preproc-source source-path output-path)
@ -141,12 +141,9 @@
(store-render-in-mod-dates source-path) ; don't store mod date until render has completed! (store-render-in-mod-dates source-path) ; don't store mod date until render has completed!
(rendered-message output-path)) (rendered-message output-path))
(define (render-preproc-source-if-needed input-path #:force [force-render #f]) (define (render-preproc-source-if-needed path #:force [force-render #f])
;; input-path might be either a preproc-source path or preproc-output path (define-values (source-path output-path) (->preproc-source+output-paths path))
;; But the coercion functions will figure it out.
(define source-path (->complete-path (->preproc-source-path input-path)))
(define output-path (->complete-path (->output-path input-path)))
(define render-needed? (define render-needed?
(or (or
@ -175,12 +172,9 @@
(->boolean (> (len (get-output-string port-for-catching-file-info)) 0))) (->boolean (> (len (get-output-string port-for-catching-file-info)) 0)))
(define (complete-markup-source-path x) (define (render-markup path [template-name #f] #:force [force-render #f])
(->complete-path (->markup-source-path (->path x)))) (define-values (source-path output-path) (->markup-source+output-paths path))
(define (render-markup x [template-name #f] #:force [force-render #f])
(define source-path (complete-markup-source-path x))
;; todo: this won't work with source files nested down one level ;; todo: this won't work with source files nested down one level
(define-values (source-dir ignored also-ignored) (split-path source-path)) (define-values (source-dir ignored also-ignored) (split-path source-path))
@ -204,7 +198,7 @@
ft-path))) ft-path)))
(render template-path #:force force-render) ; bc template might have its own preprocessor source (render template-path #:force force-render) ; bc template might have its own preprocessor source
(define output-path (->output-path source-path))
;; 2) Render the source file with template, if needed. ;; 2) Render the source file with template, if needed.
;; Render is expensive, so we avoid it when we can. Four conditions where we render: ;; Render is expensive, so we avoid it when we can. Four conditions where we render:

Loading…
Cancel
Save