diff options
Diffstat (limited to 'scalatex')
5 files changed, 43 insertions, 104 deletions
diff --git a/scalatex/api/src/main/scala/scalatex/stages/Omg/scala.scala b/scalatex/api/src/main/scala/scalatex/stages/Omg/scala.scala deleted file mode 100644 index 81fa1f9..0000000 --- a/scalatex/api/src/main/scala/scalatex/stages/Omg/scala.scala +++ /dev/null @@ -1,8 +0,0 @@ -package scalatex.stages.Omg - -/** - * Created by haoyi on 12/3/14. - */ -class scala { - -} diff --git a/scalatex/build.sbt b/scalatex/build.sbt index 4769bad..1d22b6a 100644 --- a/scalatex/build.sbt +++ b/scalatex/build.sbt @@ -35,10 +35,4 @@ lazy val scalatexSbtPlugin = project.settings(sharedSettings:_*) name := "scalatex-sbt-plugin", scalaVersion := "2.10.4", sbtPlugin := true -) -lazy val compilerPlugin = project.settings(sharedSettings:_*) - .dependsOn(api) - .settings( - name := "scalatex-compiler-plugin", - libraryDependencies += "org.scala-lang" % "scala-compiler" % scalaVersion.value )
\ No newline at end of file diff --git a/scalatex/compilerPlugin/src/main/resources/scalac-plugin.xml b/scalatex/compilerPlugin/src/main/resources/scalac-plugin.xml deleted file mode 100755 index a446f13..0000000 --- a/scalatex/compilerPlugin/src/main/resources/scalac-plugin.xml +++ /dev/null @@ -1,4 +0,0 @@ -<plugin> - <name>demo-plugin</name> - <classname>scalatex.CompilerPlugin</classname> -</plugin>
\ No newline at end of file diff --git a/scalatex/compilerPlugin/src/main/scala/scalatex/CompilerPlugin.scala b/scalatex/compilerPlugin/src/main/scala/scalatex/CompilerPlugin.scala deleted file mode 100755 index e122de5..0000000 --- a/scalatex/compilerPlugin/src/main/scala/scalatex/CompilerPlugin.scala +++ /dev/null @@ -1,79 +0,0 @@ -package scalatex - -import java.nio.file.Paths - -import scala.reflect.internal.util.BatchSourceFile -import scala.reflect.io.VirtualFile -import scala.tools.nsc.{ Global, Phase } -import scala.tools.nsc.plugins.{ Plugin, PluginComponent } - -class CompilerPlugin(val global: Global) extends Plugin { - import global._ - - override def init(options: List[String], error: String => Unit): Boolean = true - - val name = "scalatex" - val description = "Compiles scalatex files into Scala compilation units" - val components = List[PluginComponent](DemoComponent) - private object DemoComponent extends PluginComponent { - - val global = CompilerPlugin.this.global - import global._ - - override val runsAfter = List("parser") - override val runsBefore = List("namer") - - val phaseName = "Demo" - - override def newPhase(prev: Phase) = new GlobalPhase(prev) { - val splitOptions = options.map(o => o.splitAt(o.indexOf(":")+1)) - val scalatexRoots = splitOptions.collect{case ("root:", p) => p} - override def run() = { - def recursiveListFiles(f: java.io.File): Iterator[java.io.File] = { - val (dirs, files) = - Option(f.listFiles()) - .toSeq - .flatten - .partition(_.isDirectory) - files.iterator ++ dirs.iterator.flatMap(recursiveListFiles) - } - for { - scalatexRoot <- scalatexRoots - file <- recursiveListFiles(new java.io.File(scalatexRoot)) - } { - val name = file.getCanonicalPath - val fakeJfile = new java.io.File(name) - val txt = io.Source.fromFile(name).mkString - val virtualFile = new VirtualFile(name) { - override def file = fakeJfile - } - val sourceFile = new BatchSourceFile(virtualFile, txt) - val unit = new CompilationUnit(sourceFile) - val objectName = name.slice(name.lastIndexOf('/')+1, name.lastIndexOf('.')) - val pkgName = - Paths.get(scalatexRoot) - .relativize(fakeJfile.getParentFile.toPath) - .toString - .split("/") - .map(s => s"package $s") - .mkString("\n") - - val shim = s""" - $pkgName - import scalatags.Text.all._ - - object $objectName{ - def apply() = scalatex.twf("${name}") - } - """ - unit.body = global.newUnitParser(shim).parse() - global.currentRun.compileLate(unit) - } - } - - def name: String = phaseName - - def apply(unit: global.CompilationUnit): Unit = {} - } - } -} diff --git a/scalatex/scalatexSbtPlugin/src/main/scala/SbtPlugin.scala b/scalatex/scalatexSbtPlugin/src/main/scala/SbtPlugin.scala index f09dc17..df163f0 100644 --- a/scalatex/scalatexSbtPlugin/src/main/scala/SbtPlugin.scala +++ b/scalatex/scalatexSbtPlugin/src/main/scala/SbtPlugin.scala @@ -1,16 +1,52 @@ package scalatex +import java.nio.file.Paths + import sbt.Keys._ import sbt._ object SbtPlugin extends sbt.Plugin{ val scalatexDirectory = taskKey[sbt.File]("Clone stuff from github") - override val settings = Seq( + val mySeq = Seq( scalatexDirectory := sourceDirectory.value / "scalatex", - scalacOptions += { - "-P:scalatex:root:" + scalatexDirectory.value.getCanonicalPath - }, - watchSources += scalatexDirectory.value, - addCompilerPlugin("com.lihaoyi" %% "scalatex-compiler-plugin" % "0.1.0"), - libraryDependencies += "com.lihaoyi" %% "scalatex-api" % "0.1.0" + managedSources ++= { + val inputDir = scalatexDirectory.value + val outputDir = sourceManaged.value / "scalatex" + val inputFiles = (inputDir ** "*.scalatex").get + println("Generating Scalatex Sources...") + val outputFiles = for(inFile <- inputFiles) yield { + val outFile = new sbt.File( + outputDir.getAbsolutePath + inFile.getAbsolutePath.drop(inputDir.getAbsolutePath.length) + ) + val name = inFile.getName + val objectName = name.slice(name.lastIndexOf('/')+1, name.lastIndexOf('.')) + val pkgName = + inFile.getAbsolutePath + .drop(inputDir.getAbsolutePath.length + 1) + .toString + .split("/") + .dropRight(1) + .map(s => s"package $s") + .mkString("\n") + IO.write( + outFile, + s""" + |$pkgName + |import scalatags.Text.all._ + | + |object $objectName{ + | def apply() = scalatex.twf("${inFile.getAbsolutePath}") + |} + | + |${IO.readLines(inFile).map("//"+_).mkString("\n")} + """.stripMargin + ) + outFile + } + outputFiles + } + ) + val scalatexSettings = inConfig(Test)(mySeq) ++ inConfig(Compile)(mySeq) ++ Seq( + libraryDependencies += "com.lihaoyi" %% "scalatex-api" % "0.1.0", + watchSources ++= ((scalatexDirectory in Compile).value ** "*.scalatex").get ) } |