A guide to the (planet dyoo/scribble-bootstrap:3:0) Scribble library
Danny Yoo <[email protected]>
The (planet dyoo/scribble-bootstrap:3: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:3 |
@title{Example} |
This is a Scribble document that includes conditional output. |
|
@;; Let us declare the following tags. |
@declare-tags[reading pedagogy group] |
|
@;; We can tag certain content to be generated conditionally: |
@tag[reading]{This is text for reading.} |
|
@tag[group]{ |
This is text for group work. |
@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.
For example, at the Unix command line:
$ SCRIBBLE_TAGS=reading scribble example.scrbl |
should generate the file "example.html" with content for readers.
We can generate the code in an instructional context:
$ SCRIBBLE_TAGS=group scribble example.scrbl |
which omits the content for the reading context, and also excludes the
pedagogic content.
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="group pedagogy" scribble \ |
example.scrbl |
will show the content for both group and pedagogy.
2 API
The (planet dyoo/scribble-bootstrap:3:0) library includes a Scribble-based
language that provides all the bindings of scribble/base, as
well as the following forms:
2.1 Tagging Content
Declares the set of tags that will be used in this document. Any use of
tag later in the document will verify that the tags have already been
declared in a
declare-tags.
For example:
This form acts as an ifdef, and blocks off a section of the scribble document
with a tag. Its content shows only in a context that includes the given tag.
For example:
#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.
Nested tags act as intersection. For example:
@tag[teacher]{ |
@tag[student]{ |
Hello world. |
} |
} |
should generate no content unless both the teacher and
student tags are in play.
Using tag with a tag that hasn’t been previously declared with
declare-tags is a compile-time error.
Tagged content will be generated during Scribble-generation time if the
SCRIBBLE_TAGS environmental variable includes them. For example:
$ SCRIBBLE_TAGS=reading scribble example.scrbl |
generates "example.scrbl" in a context that enables tagged content using the reading tag.
2.2 Question types and formatting
Creates an empty one-line text element. The #:columns allows
customization of the number of columns of the element. The #:label
element shows placeholder text content when the element is empty.
Example:
#lang planet dyoo/scribble-bootstrap |
This is a fill in the blank: @fill-in-the-blank[#:id "name" |
#:label "What's your name?"] |
Creates an empty multi-line element. The #:columns and
#:rows keywords allow customization of the number of columns and
rows of the element. The #:label element shows placeholder text
content when the element is empty.
Example:
(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 |
Creates an embedded WeScheme instance. The keywords #:width and
#:height control the dimensions of the embedded instance.
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.
For example:
#lang planet dyoo/scribble-bootstrap |
@embedded-wescheme[#:id "example3" |
#:interactions-text "(+ 1 2 3)" |
#:hide-header? #t |
#:hide-footer? #t |
#:hide-definitions? #t] |
(row #:count [count number?] body ...) |
Creates a number of rows with the same content across the body.
For example, the following generates five rows of name/contract
fill-in-the-blank fields:
In the context of a
row, the parameter
current-row can be
dereferenced to get the current row number.
The current row number. Counting starts from zero. Outside the context
of a
row, defined as
#f.
(worksheet body ...) → element |
body : (listof pre-flow?) |
Construct a worksheet.
For example:
The selection will have the CSS style BootstrapWorksheet.
(lesson body ...) → element |
body : (listof pre-flow?) |
Construct a lesson.
For example:
The selection will have the CSS style BootstrapLesson.
(drill body ...) → element? |
body : (listof pre-flow?) |
Construct a drill.
For example:
The selection will have the CSS style BootstrapDrill.
(exercise body ...) → element? |
body : (listof pre-flow?) |
Construct an exercise.
For example:
The selection will have the CSS style BootstrapExercise.
(demo body ...) → element? |
body : (listof pre-flow?) |
Construct a demo.
For example:
#lang planet dyoo/scribble-bootstrap |
|
@demo{ |
This is a demo. |
|
} |
|
The selection will have the CSS style BootstrapDemo.
(skit body ...) → element? |
body : (listof pre-flow?) |
Construct a skit.
For example:
#lang planet dyoo/scribble-bootstrap |
|
@skit{ |
This is a skit. |
|
} |
|
The selection will have the CSS style BootstrapSkit.
An
itemlist that collects a point-itemized list of material items.
For example:
The list will have the CSS style BootstrapMaterialsList, and each item will
have the CSS style BootstrapMaterialsListItem.
(goals items ...) → element? |
items : (listof item?) |
An
itemlist that collects a point-itemized list of goal items.
For example:
The list will have the CSS style BootstrapGoalsList, and each item will
have the CSS style BootstrapGoalsListItem.
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.)