Skip to content

Commit

Permalink
Revert " #296 save Golubina lessons to xml"
Browse files Browse the repository at this point in the history
This reverts commit 0ef18d1
  • Loading branch information
zuevval committed Aug 1, 2021
1 parent 1fc80de commit c061fcd
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 53 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,25 +19,7 @@ interface DataStorage {
}

typealias StepWithAnnotations = Pair<Step, List<StepAnnotationName>>

class LessonWithSteps(
val lesson: Lesson,
val steps: List<StepWithAnnotations>
) : XmlAble {

override val xmlTag: String = "lesson"
override val xmlParams: Map<String, String> = mapOf("name" to lesson.name)

override val xmlBody: HtmlText
get() = {
var stepBuilder: HtmlText = ""
for (step in steps.dropLast(1)) {
stepBuilder += (step.first.data.toXml() + "\n")
}
stepBuilder + steps.takeLast(1)[0].first.data.toXml()
}()

}
typealias LessonWithSteps = Pair<Lesson, List<StepWithAnnotations>>

class data(
private val materials: MaterialsBuilder,
Expand Down Expand Up @@ -120,21 +102,21 @@ class DataBuilder(
}

coursesBuilder.data.forEach { (course, lessonsWithSteps) ->
require(lessonsWithSteps.first().steps.first().first.data is FirstInfo) {
require(lessonsWithSteps.first().second.first().first.data is FirstInfo) {
"First step of the course (${course.name}) should be FirstInfo"
}
require(lessonsWithSteps.last().steps.last().first.data is LastInfo) {
require(lessonsWithSteps.last().second.last().first.data is LastInfo) {
"Last step of the course (${course.name}) should be LastInfo"
}

val courseId = courses.size + 1L
_courses += course.copy(id = courseId)

lessonsWithSteps.forEachIndexed { iLesson, lessonWithAnnotation ->
lessonsWithSteps.forEachIndexed { iLesson, (lesson, stepsWithAnnotations) ->
val lessonId = iLesson + 1L
_lessons += lessonWithAnnotation.lesson.copy(id = lessonId, courseId = courseId)
_lessons += lesson.copy(id = lessonId, courseId = courseId)

lessonWithAnnotation.steps.forEachIndexed { iStep, (step, stepAnnotationNames) ->
stepsWithAnnotations.forEachIndexed { iStep, (step, stepAnnotationNames) ->
val stepId = iStep + 1L
_steps += step
.copy(id = stepId, courseId = courseId, lessonId = lessonId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class LessonsBuilder(block: LessonsBuilder.() -> Unit) {

fun lesson(name: String, description: String = "", block: StepsBuilder.() -> Unit) =
StepsBuilder(block).side {
_lessons += LessonWithSteps(
_lessons += Pair(
Lesson(UNDEFINED_ID, UNDEFINED_ID, name, description),
it.steps
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import com.github.braillesystems.learnbraille.data.entities.BrailleDot.E
import com.github.braillesystems.learnbraille.data.entities.BrailleDot.F
import com.github.braillesystems.learnbraille.res.PunctuationSigns.Hyphen

val golubinaIntroLessons by lessons {
internal val golubinaIntroLessons by lessons {

lesson(
name = "Знакомство с шеститочием"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,10 @@
package com.github.braillesystems.learnbraille.data.entities

import com.github.braillesystems.learnbraille.data.dsl.lessons
import com.github.braillesystems.learnbraille.data.entities.BrailleDot.E
import com.github.braillesystems.learnbraille.data.entities.BrailleDot.F
import com.github.braillesystems.learnbraille.res.golubinaIntroLessons
import org.junit.Assert.assertEquals
import org.junit.Test
import java.io.File

internal val testLessons by lessons {
lesson(name = "first lesson") {
+FirstInfo("first title")
}
}
import com.github.braillesystems.learnbraille.data.entities.BrailleDot.F
import com.github.braillesystems.learnbraille.data.entities.BrailleDot.E

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

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

var xmlText = ""
for (lessons in golubinaIntroLessons.lessons) {
xmlText += (lessons.toXml() + "\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 c061fcd

Please sign in to comment.