much faster way of rendering preproc sources

pull/9/head
Matthew Butterick 11 years ago
parent ddb8da0181
commit 8ba87de8b3

@ -7,7 +7,8 @@
(provide (except-out (all-from-out racket/base) #%module-begin)
(rename-out [module-begin #%module-begin]))
(require (only-in scribble/text output))
(require (only-in scribble/text output)
(only-in racket/list flatten))
(define-syntax-rule (module-begin expr ...)
(#%module-begin
@ -27,8 +28,6 @@
(require 'pollen-inner) ; provides 'doc
(define text (trim (->list doc) whitespace?)) ; if single line, text will be a string
(provide text (all-from-out 'pollen-inner))
(output text)))
;; reduce text to simplest represetnation: a single ouput string
(define text (apply string-append (flatten (trim (->list doc) whitespace?))))
(provide text (all-from-out 'pollen-inner))))

@ -154,27 +154,35 @@
(define-values (source-dir source-name _) (split-path source-path))
(define output-path (->complete-path (->output-path x)))
;; Three conditions under which we refresh:
(define source-reloaded? (handle-source-rerequire source-path))
;; Four conditions under which we render preproc sources:
(if (or
;; 1) explicitly forced refresh
;; 1) explicitly forced render:
force
;; 2) output file doesn't exist (so it definitely won't appear in mod-dates)
;; also, this is convenient for development:
;; you can trigger a refresh just by deleting the file
;; you can trigger a render just by deleting the file
(not (file-exists? output-path))
;; 3) file otherwise needs refresh (e.g., it changed)
(mod-date-expired? source-path))
;; use single quotes to escape spaces in pathnames
(let ([command (format "~a '~a' > '~a'" RACKET_PATH source-path output-path)])
;; 3) file otherwise needs render (e.g., it changed)
(mod-date-expired? source-path)
;; 4) source had to be reloaded (some other change)
source-reloaded?)
;; how we render: import 'text from preproc source file and write to output path
(begin
(rendering-message (format "~a from ~a"
(file-name-from-path output-path)
(file-name-from-path source-path)))
(store-refresh-in-mod-dates source-path)
;; discard output using open-output-nowhere
(parameterize ([current-directory source-dir]
[current-output-port nowhere-port])
(system command))
(let ([text (dynamic-require source-path 'text)])
(display-to-file text output-path #:exists 'replace)))
(rendered-message output-path))
;; otherwise, skip file because there's no trigger for refresh
(up-to-date-message output-path)))

Loading…
Cancel
Save