* Turn report-output? to an overridable method

* New extra-files field, and `render' installs them
  (the render of multi-html copies these files to each directory)
* Add an ++extra argument to the scribble command line
* Fix output of the indirect renderer

svn: r13966

original commit: 9b60be7c5aca4b9d5ff592698c57c4f7b273aa03
This commit is contained in:
Eli Barzilay 2009-03-05 09:49:53 +00:00
parent 77748d9e13
commit 0e562a46da
4 changed files with 31 additions and 13 deletions

View File

@ -19,7 +19,8 @@
[root-path #f] [root-path #f]
[prefix-file #f] [prefix-file #f]
[style-file #f] [style-file #f]
[style-extra-files null]) [style-extra-files null]
[extra-files null])
(define/public (get-dest-directory [create? #f]) (define/public (get-dest-directory [create? #f])
(when (and dest-dir create? (not (directory-exists? dest-dir))) (when (and dest-dir create? (not (directory-exists? dest-dir)))
@ -44,9 +45,9 @@
(substring s 0 (sub1 (string-length s)))) (substring s 0 (sub1 (string-length s))))
sep))) sep)))
(field [report-output? #f]) (field [report-output?? #f])
(define/public (report-output!) (define/public (report-output?) report-output??)
(set! report-output? #t)) (define/public (report-output!) (set! report-output?? #t))
;; ---------------------------------------- ;; ----------------------------------------
@ -348,10 +349,16 @@
;; ---------------------------------------- ;; ----------------------------------------
;; render methods ;; render methods
(define/public (install-extra-files)
(for ([fn extra-files]) (install-file fn)))
(define/public (render ds fns ri) (define/public (render ds fns ri)
;; maybe this should happen even if fns is empty or all #f?
;; or maybe it should happen for each file rendered (when d is not #f)?
(unless (andmap not ds) (install-extra-files))
(map (lambda (d fn) (map (lambda (d fn)
(define (one) (render-one d ri fn)) (define (one) (render-one d ri fn))
(when report-output? (printf " [Output to ~a]\n" fn)) (when (report-output?) (printf " [Output to ~a]\n" fn))
(if fn (if fn
(with-output-to-file fn #:exists 'truncate/replace one) (with-output-to-file fn #:exists 'truncate/replace one)
;; a #f filename means return the contents as a string ;; a #f filename means return the contents as a string

View File

@ -1184,9 +1184,9 @@
render-one-part render-one-part
render-content render-content
part-whole-page? part-whole-page?
format-number) format-number
install-extra-files
(inherit-field report-output?) report-output?)
(define/override (get-suffix) #"") (define/override (get-suffix) #"")
@ -1237,11 +1237,13 @@
(define/override (render ds fns ri) (define/override (render ds fns ri)
(map (lambda (d fn) (map (lambda (d fn)
(when report-output? (when (report-output?)
(printf " [Output to ~a/index.html]\n" fn)) (printf " [Output to ~a/index.html]\n" fn))
(unless (directory-exists? fn) (unless (directory-exists? fn)
(make-directory fn)) (make-directory fn))
(parameterize ([current-subdirectory (file-name-from-path fn)]) (parameterize ([current-subdirectory (file-name-from-path fn)])
;; install files for each directory
(install-extra-files)
(let ([fn (build-path fn "index.html")]) (let ([fn (build-path fn "index.html")])
(with-output-to-file fn #:exists 'truncate/replace (with-output-to-file fn #:exists 'truncate/replace
(lambda () (render-one d ri fn)))))) (lambda () (render-one d ri fn))))))

View File

@ -10,9 +10,12 @@
base-renderer base-suffix target-suffix convert) base-renderer base-suffix target-suffix convert)
%renderer) %renderer)
(class (base-renderer %renderer) (class (base-renderer %renderer)
;; set to a temp directory when doing the sub-rendering
(define tmp-dest-dir #f) (define tmp-dest-dir #f)
(define/override (get-dest-directory create?) (define/override (get-dest-directory create?)
(or tmp-dest-dir (super get-dest-directory create?))) (or tmp-dest-dir (super get-dest-directory create?)))
(define/override (report-output?)
(and (not tmp-dest-dir) (super report-output?)))
(define/override (get-suffix) target-suffix) (define/override (get-suffix) target-suffix)
(define/override (render srcs dests ri) (define/override (render srcs dests ri)
(define tmp-dir (define tmp-dir
@ -35,6 +38,8 @@
(for ([tmp tmp-dests] [dst dests]) (for ([tmp tmp-dests] [dst dests])
(parameterize ([current-directory tmp-dir]) (parameterize ([current-directory tmp-dir])
(convert (file-name-from-path tmp))) (convert (file-name-from-path tmp)))
(when (super report-output?) ; use the original
(printf " [Output to ~a]\n" dst))
(copy-file (build-path tmp-dir (file-name-from-path dst)) dst)) (copy-file (build-path tmp-dir (file-name-from-path dst)) dst))
(cleanup))) (cleanup)))
(super-new))) (super-new)))

View File

@ -23,6 +23,7 @@
(define current-prefix-file (make-parameter #f)) (define current-prefix-file (make-parameter #f))
(define current-style-file (make-parameter #f)) (define current-style-file (make-parameter #f))
(define current-style-extra-files (make-parameter null)) (define current-style-extra-files (make-parameter null))
(define current-extra-files (make-parameter null))
(define current-redirect (make-parameter #f)) (define current-redirect (make-parameter #f))
(define current-redirect-main (make-parameter #f)) (define current-redirect-main (make-parameter #f))
@ -61,6 +62,10 @@
[("--info-out") file "write format-specific link information to <file>" [("--info-out") file "write format-specific link information to <file>"
(current-info-output-file file)] (current-info-output-file file)]
#:multi #:multi
[("++extra") file "add given file"
(current-extra-files (cons file (current-extra-files)))]
[("++style") file "add given .css/.tex file"
(current-style-extra-files (cons file (current-style-extra-files)))]
[("++info-in") file "load format-specific link information from <file>" [("++info-in") file "load format-specific link information from <file>"
(current-info-input-files (current-info-input-files
(cons file (current-info-input-files)))] (cons file (current-info-input-files)))]
@ -76,8 +81,6 @@
'scribble "bad procedure identifier for ++ref-in: ~s" proc-id)) 'scribble "bad procedure identifier for ++ref-in: ~s" proc-id))
(current-xref-input-modules (current-xref-input-modules
(cons (cons mod id) (current-xref-input-modules))))] (cons (cons mod id) (current-xref-input-modules))))]
[("++style") file "add given .css/.tex file"
(current-style-extra-files (cons file (current-style-extra-files)))]
#:args (file . another-file) #:args (file . another-file)
(let ([files (cons file another-file)]) (let ([files (cons file another-file)])
(build-docs (map (lambda (file) (dynamic-require `(file ,file) 'doc)) (build-docs (map (lambda (file) (dynamic-require `(file ,file) 'doc))
@ -91,7 +94,8 @@
[dest-dir dir] [dest-dir dir]
[prefix-file (current-prefix-file)] [prefix-file (current-prefix-file)]
[style-file (current-style-file)] [style-file (current-style-file)]
[style-extra-files (reverse (current-style-extra-files))])]) [style-extra-files (reverse (current-style-extra-files))]
[extra-files (reverse (current-extra-files))])])
(when (current-redirect) (when (current-redirect)
(send renderer set-external-tag-path (current-redirect))) (send renderer set-external-tag-path (current-redirect)))
(when (current-redirect-main) (when (current-redirect-main)