diff --git a/scribble-doc/scribblings/scribble/blueboxes.scrbl b/scribble-doc/scribblings/scribble/blueboxes.scrbl index 39623511..ffcde312 100644 --- a/scribble-doc/scribblings/scribble/blueboxes.scrbl +++ b/scribble-doc/scribblings/scribble/blueboxes.scrbl @@ -2,7 +2,8 @@ @(require scribble/manual "utils.rkt" (for-label scribble/core scribble/blueboxes - racket/contract)) + racket/contract + setup/xref)) @title[#:tag "blueboxes"]{Blue Boxes Utilities} @@ -14,7 +15,7 @@ @defproc[(fetch-blueboxes-strs [tag tag?] [#:blueboxes-cache blueboxes-cache blueboxes-cache? - (make-blueboxes-cache)]) + (make-blueboxes-cache #t)]) (or/c #f (non-empty-listof string?))]{ Returns a list of strings that show the content of the blue box (without any styling information) for the documentation referenced @@ -25,13 +26,21 @@ was used to document the export). } -@defproc[(make-blueboxes-cache [populate? boolean?]) blueboxes-cache?]{ +@defproc[(make-blueboxes-cache + [populate? boolean?] + [#:blueboxes-dirs blueboxes-dirs (listof path?) (get-doc-search-dirs)]) + blueboxes-cache?]{ Constructs a new (mutable) blueboxes cache. If @racket[populate?] is @racket[#f], the cache is initially unpopulated, in which case it is filled in the first time the cache is passed to @racket[fetch-bluebxoes-strs]. Otherwise, the cache is - initially populated. + populated immediately. + + The @racket[blueboxes-dirs] argument is a list of directories that are + looked inside for @filepath{blueboxes.rktd} files. The default value + is only an approximation for where those files usually reside. See + also @racket[get-rendered-doc-directories]. } @defproc[(blueboxes-cache? [v any/c]) boolean?]{ diff --git a/scribble-lib/info.rkt b/scribble-lib/info.rkt index bd172a8d..f2dbf27f 100644 --- a/scribble-lib/info.rkt +++ b/scribble-lib/info.rkt @@ -12,8 +12,7 @@ "at-exp-lib" "draw-lib" "syntax-color-lib" - "sandbox-lib" - "racket-index")) + "sandbox-lib")) (define build-deps '("rackunit-lib" "eli-tester")) @@ -23,4 +22,4 @@ (define pkg-authors '(mflatt eli)) -(define version "1.9") +(define version "1.10") diff --git a/scribble-lib/scribble/blueboxes.rkt b/scribble-lib/scribble/blueboxes.rkt index af34c411..742dd00b 100644 --- a/scribble-lib/scribble/blueboxes.rkt +++ b/scribble-lib/scribble/blueboxes.rkt @@ -1,5 +1,5 @@ #lang racket/base -(require setup/xref +(require setup/dirs racket/serialize racket/contract scribble/core) @@ -8,12 +8,14 @@ (contract-out [fetch-blueboxes-strs (->* (tag?) (#:blueboxes-cache blueboxes-cache?) (or/c #f (non-empty-listof string?)))] - [make-blueboxes-cache (-> boolean? blueboxes-cache?)] + [make-blueboxes-cache (->* (boolean?) (#:blueboxes-dirs (listof path?)) blueboxes-cache?)] [blueboxes-cache? (-> any/c boolean?)])) -(struct blueboxes-cache (info) #:mutable) -(define (make-blueboxes-cache populate?) - (blueboxes-cache (and populate? (build-blueboxes-cache)))) +(struct blueboxes-cache (info-or-paths) #:mutable) +(define (make-blueboxes-cache populate? #:blueboxes-dirs [blueboxes-dirs (get-doc-search-dirs)]) + (define cache (blueboxes-cache blueboxes-dirs)) + (when populate? (populate-cache! cache)) + cache) (define (fetch-blueboxes-strs tag #:blueboxes-cache [cache (make-blueboxes-cache #f)]) (define plain-strs (fetch-strs-for-single-tag tag cache)) @@ -33,9 +35,8 @@ plain-strs])) (define (fetch-strs-for-single-tag tag cache) - (unless (blueboxes-cache-info cache) - (set-blueboxes-cache-info! cache (build-blueboxes-cache))) - (for/or ([ent (in-list (blueboxes-cache-info cache))]) + (populate-cache! cache) + (for/or ([ent (in-list (blueboxes-cache-info-or-paths cache))]) (define offset+lens (hash-ref (list-ref ent 2) tag #f)) (cond [offset+lens @@ -52,14 +53,19 @@ (read-line port))))))] [else #f]))) +(define (populate-cache! cache) + (define cache-content (blueboxes-cache-info-or-paths cache)) + (when ((listof path?) cache-content) + (set-blueboxes-cache-info-or-paths! cache (build-blueboxes-cache cache-content)))) + ;; build-blueboxes-cache : (listof (list file-path int hash[tag -o> (cons int int)])) -(define (build-blueboxes-cache) +(define (build-blueboxes-cache blueboxes-dirs) (filter values - (for*/list ([doc-dir-name (in-list (get-rendered-doc-directories #f #f))]) - (define x (build-path doc-dir-name "blueboxes.rktd")) - (and (file-exists? x) - (call-with-input-file x + (for*/list ([doc-dir-name (in-list blueboxes-dirs)]) + (define blueboxes.rktd (build-path doc-dir-name "blueboxes.rktd")) + (and (file-exists? blueboxes.rktd) + (call-with-input-file blueboxes.rktd (λ (port) (port-count-lines! port) (define first-line (read-line port)) @@ -72,6 +78,6 @@ #f)]) (deserialize (read port)))) (and desed - (list x + (list blueboxes.rktd (+ (string->number first-line) pos) desed))))))))