aboutsummaryrefslogtreecommitdiff
path: root/libraries/scalatex/AbstractMain.scala
diff options
context:
space:
mode:
authorChristopher Vogt <oss.nsp@cvogt.org>2017-03-17 03:36:17 -0400
committerChristopher Vogt <oss.nsp@cvogt.org>2017-04-02 13:41:02 -0400
commit435267714fd9be710945d5d6c2d0ee1f18294e12 (patch)
tree49fcc2f8e5d0204658a3204b04b1a28c18076242 /libraries/scalatex/AbstractMain.scala
parentb10412e7c29c1c0e6c46170e14696bdd48646e02 (diff)
downloadcbt-435267714fd9be710945d5d6c2d0ee1f18294e12.tar.gz
cbt-435267714fd9be710945d5d6c2d0ee1f18294e12.tar.bz2
cbt-435267714fd9be710945d5d6c2d0ee1f18294e12.zip
Add Scalatex plugin
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: _* )
+}