From 89f4b39a10c31106cb40dd4d102bbdb17dbec364 Mon Sep 17 00:00:00 2001 From: iliyangermanov Date: Sat, 21 Dec 2024 21:56:04 +0200 Subject: [PATCH] DSL demo --- .../kotlin/ivy/learn/dsl/LessonDslDemo.kt | 86 +++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 samples/src/jvmMain/kotlin/ivy/learn/dsl/LessonDslDemo.kt diff --git a/samples/src/jvmMain/kotlin/ivy/learn/dsl/LessonDslDemo.kt b/samples/src/jvmMain/kotlin/ivy/learn/dsl/LessonDslDemo.kt new file mode 100644 index 0000000..fa09a50 --- /dev/null +++ b/samples/src/jvmMain/kotlin/ivy/learn/dsl/LessonDslDemo.kt @@ -0,0 +1,86 @@ +package ivy.learn.dsl + +import ivy.learn.TextStyle + +fun main() { + +} + +fun exampleLesson() = lessonContent { + intro() + whyQuestion() + whyExplanation() + arraysInternals() + internalsQuestion() + openQuestion("open") { + question = "What is 2 + 2? (enter exact answer)" + correctAnswer = "4" + } +} + +private fun LessonContentScope.intro() { + text("intro") { + text = "Arrays" + style = TextStyle.Heading + } + text("intro_text") { + text = "The most fundamental data structure" + } +} + +private fun LessonContentScope.whyQuestion() { + question("why_q") { + question = "Why arrays are so important?" + clarification = "Think about their properties." + answer( + text = "Lorem ipsum", + correct = true, + explanation = "Lorem ipsum" + ) + answer( + text = "Lorem ipsum 2", + explanation = "test" + ) + } +} + +private fun LessonContentScope.whyExplanation() { + text("why_explain") { + text = "Lorem ipsum" + style = TextStyle.BodySpacingLarge + } +} + +private fun LessonContentScope.arraysInternals() { + image("internals_img") { + imageUrl = "url" + } + text("internals") { + text = "lorem ipsum" + style = TextStyle.BodySpacingMedium + } +} + +private fun LessonContentScope.internalsQuestion() { + question("internals_q") { + question = "Why Lorem ipsum?" + answer( + text = "Abc", + correct = true, + explanation = "..." + ) + answer( + text = "Def", + correct = true, + explanation = "..." + ) + answer( + text = "42", + explanation = "..." + ) + answer( + text = "3.14", + explanation = "..." + ) + } +} \ No newline at end of file