From 0a314e33d33455714feff55f2d23ee8a84a3b133 Mon Sep 17 00:00:00 2001 From: Matthew Flatt Date: Sun, 16 May 2010 08:57:05 -0600 Subject: [PATCH] add 'filebox' Scribble function original commit: bb2611559163dbb80c7d1736785fa381be9f316c --- collects/scribble/private/manual-scheme.rkt | 17 +++++------- collects/scribble/private/manual-style.rkt | 25 ++++++++++++++++-- collects/scribble/racket.rkt | 5 +++- collects/scribble/scheme.css | 22 ++++++++++++++++ collects/scribblings/scribble/manual.scrbl | 29 ++++++++++++++++----- 5 files changed, 79 insertions(+), 19 deletions(-) diff --git a/collects/scribble/private/manual-scheme.rkt b/collects/scribble/private/manual-scheme.rkt index 016a2afd..96b2d66d 100644 --- a/collects/scribble/private/manual-scheme.rkt +++ b/collects/scribble/private/manual-scheme.rkt @@ -65,16 +65,13 @@ ',#'lang (to-element ',#'lang)) #'(racket lang))))) - #'lang)] - [(file ...) - (if (syntax-e #'filename) - (list - (datum->syntax - #'filename - `(code:comment (unsyntax (t "In \"" ,(syntax-e #'filename) "\":"))) - #'filename)) - null)]) - (syntax/loc stx (racketblock file ... modtag rest ...)))] + #'lang)]) + (if (syntax-e #'filename) + (quasisyntax/loc stx + (filebox + filename + #,(syntax/loc stx (racketblock0 modtag rest ...)))) + (syntax/loc stx (racketblock modtag rest ...))))] [(_ lang rest ...) (syntax/loc stx (racketmod #:file #f lang rest ...))])) diff --git a/collects/scribble/private/manual-style.rkt b/collects/scribble/private/manual-style.rkt index 5c7087aa..98f74075 100644 --- a/collects/scribble/private/manual-style.rkt +++ b/collects/scribble/private/manual-style.rkt @@ -4,9 +4,12 @@ "../base.ss" (only-in "../basic.ss" aux-elem itemize) "../scheme.ss" - (only-in "../core.ss" make-style plain) + (only-in "../core.ss" make-style plain + make-nested-flow + [element? core:element?]) "manual-utils.ss" "on-demand.ss" + "manual-sprop.rkt" racket/list racket/contract racket/string) @@ -18,6 +21,7 @@ (rename-out [image image/plain]) itemize aux-elem) +(provide/contract [filebox ((or/c core:element? string?) pre-flow? . -> . block?)]) (define styling-f/c (() () #:rest (listof pre-content?) . ->* . element?)) @@ -53,7 +57,7 @@ [litchar (() () #:rest (listof string?) . ->* . element?)] [t (() () #:rest (listof pre-content?) . ->* . paragraph?)] [commandline (() () #:rest (listof pre-content?) . ->* . paragraph?)] - [menuitem (string? string? . -> . element?)]) + [menuitem (string? string? . -> . element?)]) (define PLaneT (make-element "planetName" '("PLaneT"))) @@ -210,3 +214,20 @@ [(eq? i 'rsquo) (list 'prime)] [else (list i)]))) c)))) + +(define (filebox filename . inside) + (make-nested-flow + (make-style "Sfilebox" scheme-properties) + (list + (make-styled-paragraph + (list (make-element + (make-style "Sfilename" scheme-properties) + (if (string? filename) + (filepath filename) + filename))) + (make-style "Sfiletitle" scheme-properties)) + (make-nested-flow + (make-style "Sfilecontent" scheme-properties) + (decode-flow inside))))) + + diff --git a/collects/scribble/racket.rkt b/collects/scribble/racket.rkt index 2ccb86b7..eb5c38ba 100644 --- a/collects/scribble/racket.rkt +++ b/collects/scribble/racket.rkt @@ -270,7 +270,10 @@ [line (or (syntax-line first) 0)]) (define (finish-line!) (when multi-line? - (set! docs (cons (make-paragraph omitable (reverse content)) + (set! docs (cons (make-paragraph omitable + (if (null? content) + (list (hspace 1)) + (reverse content))) docs)) (set! content null))) (define out diff --git a/collects/scribble/scheme.css b/collects/scribble/scheme.css index da22913d..21b42dbd 100644 --- a/collects/scribble/scheme.css +++ b/collects/scribble/scheme.css @@ -164,3 +164,25 @@ margin-left: 1em; margin-right: 1em; } + +.Sfilebox { + margin-left: 1em; + margin-right: 1em; +} + +.Sfiletitle { + text-align: right; + margin: 0em 0em 0em 0em; +} + +.Sfilename { + border-top: 1px solid #6C8585; + border-right: 1px solid #6C8585; + padding-left: 0.5em; + padding-right: 0.5em; + background-color: #ECF5F5; +} + +.Sfilecontent { + margin: 0em 0em 0em 0em; +} diff --git a/collects/scribblings/scribble/manual.scrbl b/collects/scribblings/scribble/manual.scrbl index 773fd9f7..3665dc62 100644 --- a/collects/scribblings/scribble/manual.scrbl +++ b/collects/scribblings/scribble/manual.scrbl @@ -143,12 +143,21 @@ without insetting the code.} @defform[(racketinput datum ...)]{Like @racket[racketblock], but the @racket[datum] are typeset after a prompt representing a REPL.} -@defform[(racketmod lang datum ...)]{Like @racket[racketblock], but -the @racket[datum] are typeset inside a @racketmodfont{#lang}-form -module whose language is @racket[lang]. The source location of -@racket[lang] (relative to the body @racket[datum]s) determines the -relative positioning of the @racketmodfont{#lang} line in the typeset -output.} +@defform/subs[(racketmod maybe-file lang datum ...) + ([maybe-file code:blank + (code:line #:file filename-expr)])]{ + +Like @racket[racketblock], but the @racket[datum] are typeset inside a +@racketmodfont{#lang}-form module whose language is @racket[lang]. + +The source location of @racket[lang] (relative to the body +@racket[datum]s) determines the relative positioning of the +@racketmodfont{#lang} line in the typeset output. So, line up +@racket[lang] with the left end of the content code. + +If @racket[#:file] is provided, then the code block is typeset using +@racket[filebox] with @racket[filename-expr] as the filename +argument.} @defform[(racket datum ...)]{Like @racket[racketblock], but typeset on a single line and wrapped with its enclosing paragraph, independent of @@ -1189,6 +1198,14 @@ An alias for @racket[centered] for backward compatibility.} ]} +@defproc[(filebox [filename (or/c string? element?)] [pre-flow pre-flow?] ...) + block?]{ + +Typesets the @racket[pre-flow]s as the content of +@racket[filename]. For example, the content may be inset on the page +with @racket[filename] above it. If @racket[filename] is a string, it +is passed to @racket{filepath} to obtain an @tech{element}.} + @; ------------------------------------------------------------------------ @section[#:tag "index-entries"]{Index-Entry Descriptions}