more scribble rendering and doc details

svn: r9261

original commit: b9d7824c8e97ee2b46300d7d4f5dd72102b0c008
This commit is contained in:
Matthew Flatt 2008-04-11 19:09:26 +00:00
parent ec179d4cbf
commit 21ef05890a
5 changed files with 66 additions and 44 deletions

View File

@ -13,7 +13,8 @@
(define render% (define render%
(class object% (class object%
(init-field dest-dir) (init-field dest-dir
[refer-to-existing-files #f])
(define/public (get-dest-directory) dest-dir) (define/public (get-dest-directory) dest-dir)
@ -370,29 +371,33 @@
;; ---------------------------------------- ;; ----------------------------------------
(define/public (install-file fn) (define/public (install-file fn)
(let ([src-dir (path-only fn)] (if refer-to-existing-files
[dest-dir (get-dest-directory)] (if (string? fn)
[fn (file-name-from-path fn)]) (string->path fn)
(let ([src-file (build-path (or src-dir (current-directory)) fn)] fn)
[dest-file (build-path (or dest-dir (current-directory)) fn)]) (let ([src-dir (path-only fn)]
(unless (and (file-exists? dest-file) [dest-dir (get-dest-directory)]
(call-with-input-file* [fn (file-name-from-path fn)])
src-file (let ([src-file (build-path (or src-dir (current-directory)) fn)]
(lambda (src) [dest-file (build-path (or dest-dir (current-directory)) fn)])
(call-with-input-file* (unless (and (file-exists? dest-file)
dest-file (call-with-input-file*
(lambda (dest) src-file
(or (equal? (port-file-identity src) (lambda (src)
(port-file-identity dest)) (call-with-input-file*
(let loop () dest-file
(let ([s (read-bytes 4096 src)] (lambda (dest)
[d (read-bytes 4096 dest)]) (or (equal? (port-file-identity src)
(and (equal? s d) (port-file-identity dest))
(or (eof-object? s) (loop))))))))))) (let loop ()
(when (file-exists? dest-file) (delete-file dest-file)) (let ([s (read-bytes 4096 src)]
(make-directory* (path-only dest-file)) [d (read-bytes 4096 dest)])
(copy-file src-file dest-file)) (and (equal? s d)
(path->string fn)))) (or (eof-object? s) (loop)))))))))))
(when (file-exists? dest-file) (delete-file dest-file))
(make-directory* (path-only dest-file))
(copy-file src-file dest-file))
(path->string fn)))))
;; ---------------------------------------- ;; ----------------------------------------

View File

@ -777,7 +777,11 @@
`((width ,(to-num w)) `((width ,(to-num w))
(height ,(to-num h)))) (height ,(to-num h))))
null))))]) null))))])
`((img ((src ,(install-file src))) ,@sz)))] `((img ((src ,(let ([p (install-file src)])
(if (path? p)
(url->string (path->url p))
p))))
,@sz)))]
[else (super render-element e part ri)]))) [else (super render-element e part ri)])))
(define/override (render-table t part ri need-inline?) (define/override (render-table t part ri need-inline?)

View File

@ -1850,7 +1850,11 @@
(provide commandline) (provide commandline)
(define (commandline . s) (define (commandline . s)
(make-paragraph (list (hspace 2) (apply tt s)))) (make-paragraph (cons (hspace 2) (map (lambda (s)
(if (string? s)
(make-element 'tt (list s))
s))
s))))
(define (elemtag t . body) (define (elemtag t . body)
(make-target-element #f (decode-content body) `(elem ,t))) (make-target-element #f (decode-content body) `(elem ,t)))

View File

@ -63,20 +63,20 @@
;; dest-file can be #f, which will make it return a string holding the ;; dest-file can be #f, which will make it return a string holding the
;; resulting html ;; resulting html
(define (xref-render xrefs doc dest-file (define (xref-render xrefs doc dest-file
#:render% [render% (html:render-mixin render%)]) #:render% [render% (html:render-mixin render%)]
;; In case rendering writes a file (like an image file), which to the #:refer-to-existing-files? [use-existing? (not dest-file)])
;; temp directory: (let* ([dest-file (if (string? dest-file) (string->path dest-file) dest-file)]
(parameterize ([current-directory (find-system-path 'temp-dir)]) [renderer (new render%
(let* ([dest-file (if (string? dest-file) (string->path dest-file) dest-file)] [dest-dir (and dest-file (path-only dest-file))]
[renderer (new render% [dest-dir (and dest-file (path-only dest-file))] [refer-to-existing-files use-existing?]
[css-path 'inline])] [css-path 'inline])]
[ci (send renderer collect (list doc) (list dest-file))] [ci (send renderer collect (list doc) (list dest-file))]
[_ (send renderer transfer-info ci (resolve-info-ci (xrefs-ri xrefs)))] [_ (send renderer transfer-info ci (resolve-info-ci (xrefs-ri xrefs)))]
[ri (send renderer resolve (list doc) (list dest-file) ci)] [ri (send renderer resolve (list doc) (list dest-file) ci)]
[xs (send renderer render (list doc) (list dest-file) ri)]) [xs (send renderer render (list doc) (list dest-file) ri)])
(if dest-file (if dest-file
(void) (void)
(car xs))))) (car xs))))
;; Returns (values <tag-or-#f> <form?>) ;; Returns (values <tag-or-#f> <form?>)
(define xref-binding-tag (define xref-binding-tag

View File

@ -133,19 +133,28 @@ the binding and its original name.}
@defproc[(xref-render [xref xref?] @defproc[(xref-render [xref xref?]
[doc part?] [doc part?]
[dest path-string?] [dest (or/c path-string? false/c)]
[#:render% using-render% (subclass?/c render%) [#:render% using-render% (subclass?/c render%)
(render-mixin render%)]) (render-mixin render%)]
void?]{ [#:refer-to-existing-files? use-existing? any/c (not dest)])
(or/c void? any/c)]{
Renders @scheme[doc] using the cross-reference info in @scheme[xref] Renders @scheme[doc] using the cross-reference info in @scheme[xref]
to the destination @scheme[dest]. For example, @scheme[doc] might be a to the destination @scheme[dest]. For example, @scheme[doc] might be a
generated document of search results using link tags described in generated document of search results using link tags described in
@scheme[xref]. @scheme[xref].
If @scheme[dest] is @scheme[#f], no file is written, and the result is
an X-expression for the rendered page. Otherwise, the file
@scheme[dest] is written and the result is @|void-const|.
The optional @scheme[using-render%] argument is as for The optional @scheme[using-render%] argument is as for
@scheme[load-xref]. It determines the kind of output that is @scheme[load-xref]. It determines the kind of output that is
generated.} generated.
If @scheme[use-existing?] is true, then files referenced during
rendering (such as image files) are referenced from their existing
locations, instead of copying to the directory of @scheme[dest].}
@defproc[(xref-index [xref xref?]) (listof entry?)]{ @defproc[(xref-index [xref xref?]) (listof entry?)]{