diff --git a/Cargo.toml b/Cargo.toml index 66aebb7..a2cd695 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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" diff --git a/README.md b/README.md index 781f454..d74bc68 100644 --- a/README.md +++ b/README.md @@ -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 + + + + + $course$/capitals/ + + + + + Knowing capitals part 1 + + + + + + Paris + + Yes, correct! + + + 0 + + +``` + +## License MIT diff --git a/src/lib.rs b/src/lib.rs index e9be4c2..31b4a55 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,3 +1,4 @@ +#![doc = include_str!("../README.md")] pub mod answer; pub mod question; pub mod quiz;