From d3dcb2f481c58a009e627b7e47c9cb39995d3692 Mon Sep 17 00:00:00 2001 From: "Zhian N. Kamvar" Date: Mon, 20 Nov 2023 15:58:14 -0800 Subject: [PATCH] update handouts --- vignettes/intro-episode.Rmd | 31 +++++++++++++++++++++++++++++++ vignettes/intro-lesson.Rmd | 11 +++++++++++ 2 files changed, 42 insertions(+) diff --git a/vignettes/intro-episode.Rmd b/vignettes/intro-episode.Rmd index 043bfb3..a546eb3 100644 --- a/vignettes/intro-episode.Rmd +++ b/vignettes/intro-episode.Rmd @@ -288,6 +288,37 @@ We can see that the chunks now have names, but the proof is in the rendering: intro$show() ``` +## Handouts + +**NOTE: This will change in version 0.8.0**. It is possible to generate a code +handout by using the `$handout()` method. This will grab all challenge blocks +along with any code block that contains `purl = TRUE` and strip out everything +else. You can also specifiy `solution = TRUE` to include the solutions: + +```{r handout-basic} +writeLines(intro$handout()) +writeLines(intro$handout(solution = TRUE)) +``` + +I want to show that the `purl = TRUE` method actually works, so I'll take the +`chunks` from above and include the last one: + +```{r handout-purl} +xml2::xml_set_attr(chunks[chunk_names == "pyramid"], "purl", TRUE) +writeLines(intro$handout()) +``` + +The `path` arguments allows this to be written to a file so that it can be +converted to a script using `knitr::purl` + +```{r handout-file} +tmp <- tempfile() +intro$handout(path = tmp) +writeLines(readLines(tmp)) +``` + +## Reset + One of the things about manipulating these documents in code is that it is possible to go back and reset if things are not correct, which is why we have the `$reset()` method: diff --git a/vignettes/intro-lesson.Rmd b/vignettes/intro-lesson.Rmd index 7ff0b44..ea08c64 100644 --- a/vignettes/intro-lesson.Rmd +++ b/vignettes/intro-lesson.Rmd @@ -202,6 +202,16 @@ to_check <- c("page", "code", "output", "images", "warning", "error") wb_lesson$summary(collection = c("episodes", "built"))[to_check] ``` +## Handouts + +This is another method wrapped from the Episode method, where it combines the +output into a single file and prepends the Episode title before each section: + +```{r handouts} +writeLines(wb_lesson$handout()) +``` + + ## Creating a New Lesson with Child Documents If you are unfamiliar with the concept of child documents, please read @@ -294,6 +304,7 @@ glue("The lineage of {path_rel(parent, start = rel)} is: {pretty_lineage}") ``` + ## Jekyll Lessons There are some methods that are specific to lessons that are built with Jekyll.