-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
279ab33
commit 257148a
Showing
2 changed files
with
51 additions
and
4 deletions.
There are no files selected for viewing
33 changes: 33 additions & 0 deletions
33
src/mmt-stex/src/info/kwarc/mmt/stex/Extensions/Frontend.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package info.kwarc.mmt.stex.Extensions | ||
|
||
import info.kwarc.mmt.api.archives.Archive | ||
import info.kwarc.mmt.api.utils.JSONArray.toList | ||
import info.kwarc.mmt.api.utils.{File, JSON, JSONArray, JSONObject, JSONString} | ||
import info.kwarc.mmt.stex.STeXServer | ||
|
||
trait FrontendExtension { this : STeXServer => | ||
def getFrontendElements = { | ||
getArchives.collect({ | ||
case a : Archive => | ||
val file = a.root / "META-INF" / "archive.json" | ||
if (file.exists()) { | ||
parseJson(File.read(file),a) | ||
} else Nil | ||
}).flatten | ||
} | ||
private def parseJson(s:String,a:Archive) : List[JSONObject] = { | ||
JSON.parse(s) match { | ||
case arr : JSONArray => toList(arr).collect{case jo:JSONObject => doObj(jo,a)} | ||
case o : JSONObject => List(doObj(o,a)) | ||
case _ => Nil | ||
} | ||
} | ||
private def doObj(j:JSONObject,a:Archive) : JSONObject = { | ||
JSONObject((JSONString("archive"),JSONString(a.id)) :: (j.map.map { | ||
case (k@JSONString("landing"|"notes"|"slides"|"file"),JSONString(v)) => | ||
if (!v.endsWith(".tex")) (k,JSONString(v + ".tex")) else (k,JSONString(v)) | ||
//case (JSONString("thumbnail"), v) => ??? | ||
case o => o | ||
})) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters