From 5cb00e1b99b2af40b3551a67d729e22f9f709ac3 Mon Sep 17 00:00:00 2001 From: Will Crichton Date: Mon, 27 Jun 2022 15:12:09 -0700 Subject: [PATCH] Add example quiz and publish on CI --- .github/workflows/main.yml | 8 ++++++++ example/.gitignore | 2 ++ example/book.toml | 8 ++++++++ example/src/SUMMARY.md | 3 +++ example/src/chapter_1.md | 5 +++++ example/src/quiz.toml | 37 +++++++++++++++++++++++++++++++++++++ 6 files changed, 63 insertions(+) create mode 100644 example/.gitignore create mode 100644 example/book.toml create mode 100644 example/src/SUMMARY.md create mode 100644 example/src/chapter_1.md create mode 100644 example/src/quiz.toml diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 42a96e5..35fe6fa 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -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 + diff --git a/example/.gitignore b/example/.gitignore new file mode 100644 index 0000000..59415e7 --- /dev/null +++ b/example/.gitignore @@ -0,0 +1,2 @@ +book +src/mdbook-quiz \ No newline at end of file diff --git a/example/book.toml b/example/book.toml new file mode 100644 index 0000000..e39fdec --- /dev/null +++ b/example/book.toml @@ -0,0 +1,8 @@ +[book] +authors = ["Will Crichton"] +language = "en" +multilingual = false +src = "src" +title = "example" + +[preprocessor.quiz] diff --git a/example/src/SUMMARY.md b/example/src/SUMMARY.md new file mode 100644 index 0000000..7390c82 --- /dev/null +++ b/example/src/SUMMARY.md @@ -0,0 +1,3 @@ +# Summary + +- [Chapter 1](./chapter_1.md) diff --git a/example/src/chapter_1.md b/example/src/chapter_1.md new file mode 100644 index 0000000..d12ea51 --- /dev/null +++ b/example/src/chapter_1.md @@ -0,0 +1,5 @@ +# Chapter 1 + +Here's a *quiz!* + +{{#quiz ./quiz.toml}} diff --git a/example/src/quiz.toml b/example/src/quiz.toml new file mode 100644 index 0000000..4c374f2 --- /dev/null +++ b/example/src/quiz.toml @@ -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`. +""" \ No newline at end of file