Skip to content

Commit

Permalink
Add example quiz and publish on CI
Browse files Browse the repository at this point in the history
  • Loading branch information
willcrichton committed Jun 27, 2022
1 parent 9fe0983 commit 5cb00e1
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 0 deletions.
8 changes: 8 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,11 @@ jobs:
# so we don't need to run pnpm build here.
- run: pnpm test && pnpm lint
working-directory: js
- run: cargo install --path . --debug --locked
- run: mdbook build
working-directory: example
- uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./example/book

2 changes: 2 additions & 0 deletions example/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
book
src/mdbook-quiz
8 changes: 8 additions & 0 deletions example/book.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[book]
authors = ["Will Crichton"]
language = "en"
multilingual = false
src = "src"
title = "example"

[preprocessor.quiz]
3 changes: 3 additions & 0 deletions example/src/SUMMARY.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Summary

- [Chapter 1](./chapter_1.md)
5 changes: 5 additions & 0 deletions example/src/chapter_1.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Chapter 1

Here's a *quiz!*

{{#quiz ./quiz.toml}}
37 changes: 37 additions & 0 deletions example/src/quiz.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
[[questions]]
type = "MultipleChoice"
prompt.prompt = "What does it mean if a variable `x` is immutable?"
prompt.choices = [
"`x` is stored in the immutable region of memory.",
"After being defined, `x` can be changed at most once.",
"`x` cannot be changed after being assigned to a value.",
"You cannot create a reference to `x`."
]
answer.answer = 2
context = """
Immutable means "not mutable", or not changeable.
"""

[[questions]]
type = "ShortAnswer"
prompt.prompt = "What is the keyword used after `let` to indicate that a variable can be mutated?"
answer.answer = "mut"
context = """
For example, you can make a mutable variable `x` by writing: `let mut x = 1`.
"""

[[questions]]
type = "Tracing"
prompt.program = """
fn main() {
let x = 1;
println!("{x}");
x += 1;
println!("{x}");
}
"""
answer.doesCompile = false
answer.lineNumber = 4
context = """
This is a compiler error because line 4 tries to mutate `x` when `x` is not marked as `mut`.
"""

0 comments on commit 5cb00e1

Please sign in to comment.