Skip to content

Commit

Permalink
Convert w1 activities from webr-teachr to quarto-live + qlcheckr
Browse files Browse the repository at this point in the history
  • Loading branch information
mitchelloharawild committed Feb 18, 2025
1 parent 80153c2 commit dd08ed9
Show file tree
Hide file tree
Showing 19 changed files with 2,542 additions and 53 deletions.
15 changes: 15 additions & 0 deletions _extensions/r-wasm/live/_extension.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
title: Quarto Live
author: George Stagg
version: 0.1.2-dev
quarto-required: ">=1.4.0"
contributes:
filters:
- live.lua
formats:
common:
ojs-engine: true
filters:
- live.lua
html: default
revealjs: default
dashboard: default
40 changes: 40 additions & 0 deletions _extensions/r-wasm/live/_gradethis.qmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
```{webr}
#| edit: false
#| output: false
webr::install("gradethis", quiet = TRUE)
library(gradethis)
options(webr.exercise.checker = function(
label, user_code, solution_code, check_code, envir_result, evaluate_result,
envir_prep, last_value, engine, stage, ...
) {
if (is.null(check_code)) {
# No grading code, so just skip grading
invisible(NULL)
} else if (is.null(label)) {
list(
correct = FALSE,
type = "warning",
message = "All exercises must have a label."
)
} else if (is.null(solution_code)) {
list(
correct = FALSE,
type = "warning",
message = htmltools::tags$div(
htmltools::tags$p("A problem occurred grading this exercise."),
htmltools::tags$p(
"No solution code was found. Note that grading exercises using the ",
htmltools::tags$code("gradethis"),
"package requires a model solution to be included in the document."
)
)
)
} else {
gradethis::gradethis_exercise_checker(
label = label, solution_code = solution_code, user_code = user_code,
check_code = check_code, envir_result = envir_result,
evaluate_result = evaluate_result, envir_prep = envir_prep,
last_value = last_value, stage = stage, engine = engine)
}
})
```
32 changes: 32 additions & 0 deletions _extensions/r-wasm/live/_knitr.qmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
```{r echo=FALSE}
# Setup knitr for handling {webr} and {pyodide} blocks
# TODO: With quarto-dev/quarto-cli#10169, we can implement this in a filter
# We'll handle `include: false` in Lua, always include cell in knitr output
knitr::opts_hooks$set(include = function(options) {
if (options$engine == "webr" || options$engine == "pyodide") {
options$include <- TRUE
}
options
})
# Passthrough engine for webr
knitr::knit_engines$set(webr = function(options) {
knitr:::one_string(c(
"```{webr}",
options$yaml.code,
options$code,
"```"
))
})
# Passthrough engine for pyodide
knitr::knit_engines$set(pyodide = function(options) {
knitr:::one_string(c(
"```{pyodide}",
options$yaml.code,
options$code,
"```"
))
})
```
Loading

0 comments on commit dd08ed9

Please sign in to comment.