Skip to content

Commit 68b973d

Browse files
authored
Merge pull request #16 from vsoch/add/quiz
Adding quiz element
2 parents 4db620f + bcdae2d commit 68b973d

File tree

8 files changed

+117
-1
lines changed

8 files changed

+117
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ Critical items to know are:
1414
- changed behaviour
1515

1616
## [master](https://github.com/vsoch/mkdocs-jekyll/tree/master)
17+
- basic support for multiple choice quizzes (0.0.12)
1718
- adding colored buttons, various fixed to navigation (0.0.11)
1819
- getting search working (0.0.1)
1920
- start of theme (0.0.0)

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.0.11
1+
0.0.12

_data/quizzes/example-quiz.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
title: This is the Quiz Title
2+
randomized: false
3+
questions:
4+
5+
- type: "multiple-choice"
6+
question: "What is your favorite color?"
7+
items:
8+
- choice: Red
9+
correct: null
10+
- choice: Blue
11+
correct: null
12+
- choice: Green
13+
correct: null
14+
followup: There is no correct answer to asking your favorite color! All choices would be good.
15+
16+
- type: "multiple-choice"
17+
question: "True or False, Pittsburgh is West of Philadelphia"
18+
items:
19+
- choice: True
20+
correct: true
21+
- choice: False
22+
correct: false
23+
followup: |
24+
The answer is True! Pittsburgh is 304.9 miles West of Philadelphia, or approximately
25+
a car ride of 4 hours and 52 minutes. Buckle up!

_data/toc.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@
77
url: "docs/getting-started#development"
88
- title: Customization
99
url: "docs/getting-started#customization"
10+
- title: "Extras"
11+
url: "docs/extras"
12+
children:
13+
- title: Quizzes
14+
url: "docs/extras/example-quiz"
1015
- title: "About"
1116
url: "about"
1217
- title: "News"

_docs/extras/example-quiz.md

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
---
2+
title: Quiz
3+
---
4+
5+
# Quizzes
6+
7+
As of version 0.0.12, mkdocs-jekyll has support for basic quizzes! These are
8+
intended to help educate your users about the content of your documentation.
9+
For a quiz, you can add a new file to the folder `_data/quizzes`, and write a
10+
questions file based on the format shown in `_data/quizzes/example-quiz.yml`.
11+
Here is a simple example of a multiple choice question (which can also serve as
12+
True/False):
13+
14+
```yaml
15+
title: This is the Quiz Title
16+
randomized: false
17+
questions:
18+
19+
- type: "multiple-choice"
20+
question: "True or False, Pittsburgh is West of Philadelphia"
21+
items:
22+
- choice: True
23+
correct: true
24+
- choice: False
25+
correct: false
26+
followup: |
27+
The answer is True! Pittsburgh is 304.9 miles West of
28+
Philadelphia, or approximately a car ride of
29+
4 hours and 52 minutes. Buckle up!
30+
```
31+
32+
The quiz is rendered with a "Show Answer" button below each question, and when
33+
the user clicks it, any questions that are flagged with `correct: true` will be
34+
bolded, and if a followup section is included, it will be displayed.
35+
See the live example at the end of this page.
36+
37+
## Options
38+
39+
#### Title
40+
41+
If you include a title, it will be rendered at the top of the quiz. This is
42+
optional - you can leave it out and add it before the include on the page.
43+
44+
#### Random
45+
46+
If you want your questions to be presented randomly, just add randomized: true
47+
to the data.
48+
49+
50+
## Example Quiz
51+
52+
If I want to include the quiz located at `_data/quizzes/example-quiz.yml`, I
53+
can do so like this:
54+
55+
```
56+
{% raw %}{% include quiz.html file='example-quiz' %}{% endraw %}
57+
```
58+
59+
The rendered quiz is shown here:
60+
61+
62+
{% include quiz.html file='example-quiz' %}

_docs/extras/index.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
---
2+
title: Extras
3+
---
4+
5+
# Extras
6+
7+
Extras include other integrations that aren't relevant to style or customization,
8+
but can further enhance your documentation pages. Currently, we have support
9+
for adding interactive quizzes.
10+
11+
- [Quizzes](example-quiz)
12+
13+
14+
Would you like to see another question type, or another kind of extra? Please
15+
[open an issue])({{ site.repo }}/issues/new).

_includes/quiz.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{% assign quiz = site.data.quizzes[include.file] %}
2+
{% if quiz.randomize == true %}{% assign questions = quiz.questions | sample %}{% else %}{% assign questions = quiz.questions %}{% endif %}{% if quiz.title %}<h2>{{ quiz.title }}</h2>{% endif %}{% for item in questions %}
3+
{% if item.type == "multiple-choice" %}{% include quiz/multiple-choice.html item=item count=forloop.index %}{% endif %}<br>{% endfor %}

_includes/quiz/multiple-choice.html

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<div class="admonition question">
2+
<p class="admonition-title">{% if include.item.question %}{{ include.item.question }}{% else %}Question {{ include.count }}{% endif %}</p>
3+
<p>{% for choice in include.item.items %}{% if choice.correct == true %}<span class="correct-{{ include.count }}">{% endif %}{{ forloop.index }}. {{ choice.choice }}{% if choice.correct == true %}</span>{% endif %}<br>{% endfor %}</p>
4+
</div><button class="btn btn-success" onclick='$(".correct-{{ include.count }}").css("font-weight", 600);$(".correct-more-{{ include.count }}").css("display", "inline")'>Show Answer</button>
5+
{% if include.item.followup %}<p class="well correct-more-{{ include.count }}" style="display:none">{{ include.item.followup }}</p>{% endif %}

0 commit comments

Comments
 (0)