Skip to content

Commit

Permalink
Improve docs
Browse files Browse the repository at this point in the history
  • Loading branch information
Nicceboy committed Aug 30, 2024
1 parent 70019d0 commit cb9a9d0
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 3 deletions.
10 changes: 8 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
[package]
name = "moodle_xml"
name = "moodle-xml"
description = "A library for generating Moodle quizzes in XML format."
repository = "https://github.com/ouspg/moodle-xml-rs"
authors = ["Niklas Saari", "Eetu Lassi"]
readme = "README.md"
version = "0.1.0"
edition = "2021"
license-file = "LICENSE"
keywords = ["moodle", "xml", "quiz"]

[dependencies]
xml-rs = "0.8.20"
xml-rs = "0.8"

[dev-dependencies]
tempfile = "3"
57 changes: 56 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,62 @@
Moodle has a specific XML format for importing and exporting questions from [Quiz Module](https://docs.moodle.org/404/en/Quiz_activity).

This project provides a Rust library for generating such XML-based Moodle quizzes.
The library attempts to ensure that the generated XML is valid and can be imported into Moodle without a hassle.

# License
## Usage

Currently, multiple-choice, true-false and short answer questions are mainly supported.

```rust
use moodle_xml::prelude::*;

// Create a short answer question, with name and description. Use default case sensitivity which is false.
let mut question = ShortAnswerQuestion::new("Knowing capitals part 1".into(), "What is the capital of France?".into(), None);
// Define the fraction value for the answer, correct answer and correct answer feedback.
let answer = Answer::new(100, "Paris".into(), Some("Yes, correct!".into()));
question.add_answers(answer.into()).unwrap();

// Create a quiz with questions
let mut quiz = Quiz::new(question.into());

// Sets a category for the quiz, which will result as "$course$/capitals" in XML, creating a new category "capitals" if it doesn't exist
// when importing the quiz into Moodle.
let categories = vec!["capitals".into()];
quiz.set_categories(categories);

// Generate the XML.
let filename = "quiz.xml";
quiz.to_xml(filename).unwrap();
```

The previous will generate a file named "quiz.xml" with the following content:

```xml
<?xml version="1.0" encoding="utf-8"?>
<quiz>
<question type="category">
<category>
<text>$course$/capitals/</text>
</category>
</question>
<question type="shortanswer">
<name>
<text>Knowing capitals part 1</text>
</name>
<questiontext format="html">
<text><![CDATA[What is the capital of France?]]></text>
</questiontext>
<answer fraction="100" format="html">
<text>Paris</text>
<feedback format="html">
<text>Yes, correct!</text>
</feedback>
</answer>
<usecase>0</usecase>
</question>
</quiz>
```

## License

MIT
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#![doc = include_str!("../README.md")]
pub mod answer;
pub mod question;
pub mod quiz;
Expand Down

0 comments on commit cb9a9d0

Please sign in to comment.