aboutsummaryrefslogtreecommitdiff
path: root/libraries/scalatex/AbstractMain.scala
diff options
context:
space:
mode:
Diffstat (limited to 'libraries/scalatex/AbstractMain.scala')
-rw-r--r--libraries/scalatex/AbstractMain.scala34
1 files changed, 34 insertions, 0 deletions
diff --git a/libraries/scalatex/AbstractMain.scala b/libraries/scalatex/AbstractMain.scala
new file mode 100644
index 0000000..ab876d9
--- /dev/null
+++ b/libraries/scalatex/AbstractMain.scala
@@ -0,0 +1,34 @@
+package cbt.plugins.scalatex.runtime
+
+import java.io.File
+import java.nio.file.{ Files, Paths }
+import scalatags.Text.all._
+trait AbstractMain{
+ def dependencyClasspath: Seq[File]
+ def files: Seq[(String,SeqFrag[Frag])]
+ def htmlTarget: File
+ def render: SeqFrag[Frag] => String => String
+ def main(args: Array[String]): Unit = {
+ val changed = files.flatMap{
+ case (name, contents) =>
+ val path = htmlTarget.toPath.resolve(name + ".html")
+ import Files._
+ createDirectories(path.getParent)
+ val newContents = render(contents)(name)
+ if( !exists(path) || new String( Files.readAllBytes( path ) ) != newContents ){
+ write( path, newContents.getBytes )
+ Some( path )
+ } else None
+ }
+ if( args.lift(0).map(_=="open").getOrElse(false) )
+ changed.headOption.foreach{ file =>
+ System.out.println(file)
+ val old = Option(System.getProperty("apple.awt.UIElement"))
+ System.setProperty("apple.awt.UIElement", "true")
+ java.awt.Desktop.getDesktop().open(file.toFile)
+ old.foreach(System.setProperty("apple.awt.UIElement", _))
+ }
+ else System.out.println(changed.mkString("\\n"))
+ }
+ val repl = new cbt.plugins.scalatex.runtime.repl( this.getClass.getClassLoader, dependencyClasspath: _* )
+}