racket/collects/scribblings/main/private/utils.ss
Eli Barzilay bdfcca7d11 Use an nonexistent css class for installation warning message, so when
it's installed on the web page it's easy to add the missing class with
a `display: none' so it's not show without any html rehacking.
Disabled the "(installation)" suffix to the main title for now: it's
also used for the window title and that shouldn't have the suffix
because the browser window will have it.

svn: r11452
2008-08-27 11:19:20 +00:00

102 lines
3.7 KiB
Scheme

#reader scribble/reader
#lang scheme/base
(require "../config.ss"
scribble/manual
scribble/struct
scribble/decode
scheme/list
setup/dirs)
(provide main-page script script-ref not-on-the-web)
(define page-info
(let ([links (filter pair? links)])
(lambda (id)
(cond [(assq id links) => cdr]
[else (error 'main-page "page id not found: ~e" id)]))))
(define (script #:noscript [noscript null] . body)
(make-script-element #f noscript "text/javascript" (flatten body)))
(define (script-ref #:noscript [noscript null] path)
(make-script-element #f noscript "text/javascript" path))
;; this is for content that should not be displayed on the web (this
;; is done by a class name that is not included in the usual css file,
;; but for the web version the css is extended with this class as
;; something that is not displayed)
(define (not-on-the-web . body)
(make-element "hide_when_on_the_web" (decode-content body)))
;; the second argument specifies installation/user specific, and if
;; it's missing, then it's a page with a single version
(define (main-page id [installation-specific? '?])
(define info (page-info id))
(define title-string (car info))
(define root (cadr info))
(define path (caddr info))
(define user-doc? (eq? installation-specific? #f))
(define inst-doc? (eq? installation-specific? #t))
(define up-path
;; massage the current path to an up string
(regexp-replace* #rx"[^/]*/" (regexp-replace #rx"[^/]+$" path "") "../"))
(define page-title
(title #:style '(no-toc) title-string
#;
;; the "(installation)" part shouldn't be visible on the web, but
;; there's no way (currently) to not have it in the window title
;; too.
(cond [inst-doc? (not-on-the-web " (installation)")]
[user-doc? ""] ; can be " (user)"
[else ""])
))
(define toc
(map (lambda (item)
(let ([link-id (if (pair? item) (car item) item)])
((if (eq? id link-id) caddr cadr) item)))
(front-toc-items up-path)))
(make-splice `(,page-title
,@toc
,@(if user-doc?
(list @script{SetPLTRoot("@(version)", "@up-path")@";"})
'()))))
;; FIXME: Use this to avoid hard-wiring manual titles and paths in config.ss
(define (resolve s [f s])
(resolved-module-path-name
(module-path-index-resolve
(module-path-index-join `(lib ,(format "scribblings/~a/~a.scrbl" s f))
#f))))
(define (front-toc-items up)
(map (lambda (item)
(if (eq? item '---)
(list '--- (make-toc-element #f null '(nbsp)))
(let ()
(define id (car item))
(define info (page-info id))
(define label (car info))
(define root (cadr info))
(define path (caddr info))
(define text (make-element "tocsubseclink" (list label)))
(define dest
(case root
[(plt) (build-path (find-doc-dir) path)]
[(user) (string-append up path)]
[(#f) path]
[else (error "internal error (main-page)")]))
(define (onclick style)
(if (eq? root 'user)
(make-with-attributes
style
`([onclick
. ,(format "return GotoPLTRoot(\"~a\", \"~a\");"
(version) path)]))
style))
(define (elt style)
(make-toc-element
#f null (list (link dest #:style (onclick style) text))))
(list id (elt "tocviewlink") (elt "tocviewselflink")))))
links))