CS18 Bridge Assignment: Processing Documents
[Work in Pyret, putting your work in a file called markup.arr
]
You’re working for a new bakery. The owners want to create a collection of posters about the company’s products and services. The marketing team is trying to produce the content, but the graphic design team can’t stop arguing about the layout, so everyone is stuck.
For example, here are two versions of a draft poster about ordering custom cakes:
Custom Cake Orders
- Pick a base flavor: vanilla or chocolate
- Pick a filling: berries or icing
- Include a message
Prices
Start at $15 for a small cake.
CUSTOM CAKE ORDERS
!! Pick a base flavor: vanilla or chocolate !!
!! Pick a filling: berries or icing !!
!! Include a message !!
PRICES
start at $15 for a small cake.
Notice how the text is exactly the same in both versions, but the styling is different (and we haven’t even gotten to colors, font selection, or where to put the logo!). Having taken a programming class, you realize that the styling could be controlled by a function: different functions that take the same text could produce differently-formatted outputs. But how do you give the content to a function such that it can determine which parts should get bolded, capitalized, etc?
Task
Your main task in this assignment is to figure out how to pass the content of a poster as an argument to a function that would format the text of a poster. Your focus here is on the datatype for the content, not on the formatter.
As a simple example, if you represented the poster text just as a string, you could have a simple formatter that produces the string in all-caps:
fun formatCaps(content :: String) -> String:
string-to-upper(content)
where:
formatCaps("Brown") is "BROWN"
formatCaps("HELLO") is "HELLO"
end
Or a formatter that puts the first word of the content in bold:
fun formatBold(content :: String) -> String:
pull-out-first = string-split(content, " ")
"<bold>" + pull-out-first.get(0) + "</bold> "
+ pull-out-first.get(1)
where:
formatBold("a b c") is "<bold>a</bold> b c"
end
(the output string here is in HTML, the format used to produce web pages)
If you look at our sample poster above, the different formats aren’t working just on the first word: there seem to be different parts to the content, and different parts get formatted differently (for example, in the first version subheadings are in bold, but in the second they are in all-caps). This means you will need some data structure for the content that lets you format different parts differently.
Your job is to design a data structure (using a combination of lists and data blocks in Pyret) that will capture poster content. Your data structure should be sufficient to capture the sample poster used in the above example. It should allow a poster with an arbitrary number of sections and an arbitrary number of items in the list.
Your final file for this assignment should have four main items:
-
Any data blocks needed as part of your content data structure
-
An example of the sample poster content captured in your data structure (you are only capturing the textual content, not the bold, caps, etc – the latter would be added by the function).
-
One example of a formatting function that takes content (your data structure) as input and produces a (formatted) string in which all section titles are in all-caps and all instructions are in bold (use <bold>
tags as shown in the example above). Put this in a block comment within your file.
-
A paragraph summarizing a takeaway that you have from this assignment. There isn’t a “right” answer here. Reflection is a useful learning strategy for you, and this will help me gauge what ideas you’re picking up on as you (hopefully) head into 18.
CS18 Bridge Assignment: Processing Documents
[Work in Pyret, putting your work in a file called
markup.arr
]You’re working for a new bakery. The owners want to create a collection of posters about the company’s products and services. The marketing team is trying to produce the content, but the graphic design team can’t stop arguing about the layout, so everyone is stuck.
For example, here are two versions of a draft poster about ordering custom cakes:
Custom Cake Orders
Prices
Start at $15 for a small cake.
CUSTOM CAKE ORDERS
!! Pick a base flavor: vanilla or chocolate !!
!! Pick a filling: berries or icing !!
!! Include a message !!
PRICES
start at $15 for a small cake.
Notice how the text is exactly the same in both versions, but the styling is different (and we haven’t even gotten to colors, font selection, or where to put the logo!). Having taken a programming class, you realize that the styling could be controlled by a function: different functions that take the same text could produce differently-formatted outputs. But how do you give the content to a function such that it can determine which parts should get bolded, capitalized, etc?
Task
Your main task in this assignment is to figure out how to pass the content of a poster as an argument to a function that would format the text of a poster. Your focus here is on the datatype for the content, not on the formatter.
As a simple example, if you represented the poster text just as a string, you could have a simple formatter that produces the string in all-caps:
Or a formatter that puts the first word of the content in bold:
(the output string here is in HTML, the format used to produce web pages)
If you look at our sample poster above, the different formats aren’t working just on the first word: there seem to be different parts to the content, and different parts get formatted differently (for example, in the first version subheadings are in bold, but in the second they are in all-caps). This means you will need some data structure for the content that lets you format different parts differently.
Your job is to design a data structure (using a combination of lists and data blocks in Pyret) that will capture poster content. Your data structure should be sufficient to capture the sample poster used in the above example. It should allow a poster with an arbitrary number of sections and an arbitrary number of items in the list.
Your final file for this assignment should have four main items:
Any data blocks needed as part of your content data structure
An example of the sample poster content captured in your data structure (you are only capturing the textual content, not the bold, caps, etc – the latter would be added by the function).
One example of a formatting function that takes content (your data structure) as input and produces a (formatted) string in which all section titles are in all-caps and all instructions are in bold (use
<bold>
tags as shown in the example above). Put this in a block comment within your file.A paragraph summarizing a takeaway that you have from this assignment. There isn’t a “right” answer here. Reflection is a useful learning strategy for you, and this will help me gauge what ideas you’re picking up on as you (hopefully) head into 18.