A guide to the (planet dyoo/scribble-bootstrap:1:=0) Scribble library
Danny Yoo <[email protected]>
The (planet dyoo/scribble-bootstrap:1:=0) library provides preliminary Scribble document support for the Bootstrap curriculum. Specifically, it allows documents to include conditional content (e.g. generating content for teachers or students), as well as commands to embed forms and embedded WeScheme instances.
It will eventually include support for validating the content of these forms, as well as saving the contents of the form to server-side storage.
1 Getting started
Let’s start with the following document:
"example.scrbl"
#lang planet dyoo/scribble-bootstrap @title{Example} This is a Scribble document that includes conditional output. @;; Let us declare the following tags. @declare-tags[reading instruction pedagogy exercise skit] @;; We can tag certain content to be generated conditionally: @tag[reading]{This is text for reading.} @tag[instruction]{ This is text for instruction. @tag[pedagogy]{This is text for pedagogy.}}
We can then generate different renderings of this document based on the audience, by using a SCRIBBLE_TAGS environmental variable to provide the necessary context.
$ SCRIBBLE_TAGS=reading scribble example.scrbl
should generate the file "example.html" with content for readers.
$ SCRIBBLE_TAGS=instruction scribble example.scrbl
To generate content that shows for both instruction and pedagogy, use quotes (") so the Unix shell allows you to assign multiple tags into SCRIBBLE_TAGS:
$ SCRIBBLE_TAGS="instruction pedagogy" scribble \
example.scrbl
2 API
The (planet dyoo/scribble-bootstrap:1:=0) library includes a Scribble-based language that provides all the bindings of scribble/base, as well as the following forms:
(declare-tags tags ...)
#lang planet dyoo/scribble-bootstrap @declare-tags[instruction pedagogy example]
(tag tags body ...)
#lang planet dyoo/scribble-bootstrap @declare-tags[student teacher] @tag[student]{Can be seen by student.} @tag[teacher]{Can be seen by teacher.}
A section can be tagged with multiple tags at a time by providing a parenthesized list of tags.
@tag[(student teacher)]{Can be seen by both students and teachers.} |
This acts as as a union: if the document is generated in a context including any of the tags, then it will be rendered.
@tag[teacher]{ @tag[student]{ Hello world. } }
Using tag with a tag that hasn’t been previously declared with declare-tags is a compile-time error.
$ SCRIBBLE_TAGS=reading scribble example.scrbl
(fill-in-the-blank #:id id [ #:columns columns #:label label]) → element? id : string? columns : number? = 50 label : (or/c string? #f) = #f
#lang planet dyoo/scribble-bootstrap This is a fill in the blank: @fill-in-the-blank[#:id "name" #:label "What's your name?"]
(free-response #:id id [ #:columns columns #:rows height #:label label]) → element? id : string? columns : number? = 50 height : number? = 20 label : (or/c string? #f) = #f
#lang planet dyoo/scribble-bootstrap This is a free-response: @free-response[#:id "summary"]
(embedded-wescheme #:id id [ #:width width #:height height #:public-id pid #:interactions-text interactions-text #:hide-header? hide-header #:hide-footer? hide-footer #:hide-definitions? hide-definitions?]) → element? id : string? width : (or/c number string?) = "90%" height : (or/c number string?) = "500px" pid : (or/c string? #f) = #f interactions-text : (or/c string #f) = #f hide-header : boolean? = #f hide-footer : boolean? = #t hide-definitions? : boolean? = #f
If provided a #:public-id, the embedded instance will load the published WeScheme program with that id.
If provided a #:interactions-text, the embedded instance will initialize the interactions window with the given string.
3 Caveats
At the moment, the conditional tag logic is performed at compile-time rather than run-time. This means that if you compile a ".scrbl" file with raco make, that decision has been committed to the bytecode, so that if you re-render the document, scribble does not revisit the choice.
Scribble itself uses the term "tag" as a mechanism for cross-referencing and linking. The bootstrap support’s use of the "tag" term is not the same. (We may want to use different terminology to avoid this conflict.)