Skip to content

Commit

Permalink
#296 make lessons xmlable again
Browse files Browse the repository at this point in the history
  • Loading branch information
zuevval committed Aug 1, 2021
1 parent c061fcd commit 6b0fa2c
Showing 1 changed file with 46 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,38 @@
package com.github.braillesystems.learnbraille.data.entities

import com.github.braillesystems.learnbraille.data.dsl.LessonWithSteps
import com.github.braillesystems.learnbraille.data.dsl.lessons
import org.junit.Assert.assertEquals
import org.junit.Test

import com.github.braillesystems.learnbraille.data.entities.BrailleDot.F
import com.github.braillesystems.learnbraille.data.entities.BrailleDot.E
import com.github.braillesystems.learnbraille.res.golubinaIntroLessons
import java.io.File

internal val testLessons by lessons {
lesson(name = "first lesson") {
+FirstInfo("first title")
}
}

internal fun toXml(lesson: LessonWithSteps): HtmlText {
return object : XmlAble {
override val xmlTag: String = "lesson"

override val xmlParams: Map<String, String>
get() = mapOf("name" to lesson.first.name.replace("\"", "'"))

override val xmlBody: HtmlText
get() = {
var stepBuilder: HtmlText = ""
for(step in lesson.second.dropLast(1)){
stepBuilder += (step.first.data.toXml() + "\n") // TODO [... <br>] -> [<p>...</p>]
}
stepBuilder + lesson.second.takeLast(1)[0].first.data.toXml()
}()
}.toXml()
}

class ToXmlTest {
@Test
Expand All @@ -21,4 +49,22 @@ class ToXmlTest {
assertEquals(expectedXml, stepData.toXml().replace("\n", ""))
}
}

@Test
fun lessonToXml() {
println(toXml(testLessons.lessons[0]))

var xmlText = ""
for(lessons in golubinaIntroLessons.lessons) {
xmlText += (toXml(lessons) + "\n")
}

val xmlLinesList = xmlText.split("\n")
File("course.xml").printWriter().use { out ->
out.println("<?xml version=\"1.0\" encoding=\"utf-8\"?>")
out.println("<root>")
xmlLinesList.forEach { out.println(it) }
out.println("</root>")
}
}
}

0 comments on commit 6b0fa2c

Please sign in to comment.