Skip to content

Commit 4c08c84

Browse files
committed
Take into account categories within the example overview
1 parent 2910571 commit 4c08c84

File tree

1 file changed

+20
-9
lines changed

1 file changed

+20
-9
lines changed

src/main/scala/org/janalyse/Synchronize.scala

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,27 @@ object Synchronize {
1212
}
1313

1414
private def formatChangesForFileExt(changes:List[Change], fileExt:String):String = {
15-
val formattedExamples = for {
16-
change <- changes.sortBy(_.example.filename)
17-
filename = change.example.filename
18-
summary <- change.example.summary
19-
url <- change.publishedUrls.get("gist") // TODO - Hardcoded for gist
20-
} yield {
21-
s"- [$filename]($url) : $summary"
15+
def formatChanges(changes: List[Change]) = {
16+
for {
17+
change <- changes.sortBy(_.example.filename)
18+
filename = change.example.filename
19+
summary <- change.example.summary
20+
url <- change.publishedUrls.get("gist") // TODO - Hardcoded for gist
21+
} yield {
22+
s"- [$filename]($url) : $summary"
23+
}
2224
}
23-
val count = formattedExamples.size
24-
val content = formattedExamples.mkString("\n")
25+
26+
val markdownFormattedLinesForExamples =
27+
changes.groupBy(_.example.category).toList.sortBy{case(k,_)=>k}.flatMap{
28+
case (None, changes) =>
29+
formatChanges(changes)
30+
case (Some(category), changes) =>
31+
s"- $category"::(formatChanges(changes).map(line => s" $line"))
32+
}
33+
34+
val count = changes.size
35+
val content = markdownFormattedLinesForExamples.mkString("\n")
2536
val exampleFileType = fileExtToExampleType(fileExt)
2637
s"## $count $exampleFileType examples\n$content"
2738
}

0 commit comments

Comments
 (0)