diff options
author | Jan Christopher Vogt <oss.nsp@cvogt.org> | 2017-04-02 15:07:41 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-04-02 15:07:41 -0400 |
commit | a40300405524c0b4f8bf5959ec06e3fe1e93837f (patch) | |
tree | 92807a01d9dd62fccd9903e18ce8765960c91603 /stage2 | |
parent | 50f4b1778d9ba3de15433d710d2e61cd1a73337a (diff) | |
parent | cf2c37852a925eb3a31d237bfe00730d8e687686 (diff) | |
download | cbt-a40300405524c0b4f8bf5959ec06e3fe1e93837f.tar.gz cbt-a40300405524c0b4f8bf5959ec06e3fe1e93837f.tar.bz2 cbt-a40300405524c0b4f8bf5959ec06e3fe1e93837f.zip |
Merge pull request #477 from cvogt/scalatex
Add Scalatex plugin
Diffstat (limited to 'stage2')
-rw-r--r-- | stage2/Lib.scala | 9 | ||||
-rw-r--r-- | stage2/libraries.scala | 7 | ||||
-rw-r--r-- | stage2/plugins/Scalatex.scala | 77 |
3 files changed, 83 insertions, 10 deletions
diff --git a/stage2/Lib.scala b/stage2/Lib.scala index 52973f1..56f24c6 100644 --- a/stage2/Lib.scala +++ b/stage2/Lib.scala @@ -160,13 +160,8 @@ final class Lib(val logger: Logger) extends Stage1Lib(logger){ }.getOrElse{ if( context =!= null && (context.workingDirectory / name).exists ){ val newContext = context.copy( workingDirectory = context.workingDirectory / name ) - callInternal( - DirectoryDependency( newContext.cwd )( newContext ).dependency, - members.tail, - previous :+ taskName, - newContext, - callback - ) + val build = DirectoryDependency( newContext, None ).dependency + callInternal( build, members.tail, previous :+ taskName, newContext, callback ) } else { val p = previous.mkString(".") val msg = (if(p.nonEmpty) p ++ s" has " else " ") diff --git a/stage2/libraries.scala b/stage2/libraries.scala index eb7de13..08a7a74 100644 --- a/stage2/libraries.scala +++ b/stage2/libraries.scala @@ -15,16 +15,17 @@ class libraries( context: Context, scalaVersion: String, scalaMajorVersion: Stri def file = dep( "file" ) def interfaces = dep( "interfaces" ) def proguard = dep( "proguard" ) - def scalatestRunner = dep( "scalatest-runner" ) def reflect = dep( "reflect" ) + def scalatestRunner = dep( "scalatest-runner" ) + def scalatex = dep( "scalatex" ) } object scala { private def _maven = ( g: String, a: String, v: String ) => { MavenResolver( context.cbtLastModified, context.paths.mavenCache, mavenCentral )( - context.logger, context.transientCache, context.classLoaderCache - ) bindOne MavenDependency( g, a, v ) + context.logger, context.transientCache, context.classLoaderCache + ) bindOne MavenDependency( g, a, v ) } def compiler = _maven( "org.scala-lang", "scala-compiler", scalaVersion ) diff --git a/stage2/plugins/Scalatex.scala b/stage2/plugins/Scalatex.scala new file mode 100644 index 0000000..6276332 --- /dev/null +++ b/stage2/plugins/Scalatex.scala @@ -0,0 +1,77 @@ +package cbt +import java.io.File +import java.nio.file.Files +trait Scalatex extends BaseBuild { + override def dependencies = super.dependencies :+ libraries.cbt.scalatex + + def scalatex = ( + Scalatex.apply( + lib, + Math.max( context.cbtLastModified, ( dependencies ++ context.parentBuild ).map( _.lastModified ).max ) + ) + .config( + lib.autoRelative( + lib.sourceFiles( sources, _.string endsWith ".scalatex" ) + ++ projectDirectory.listFiles.toVector.filter( _.toString.endsWith( ".scalatex" ) ) + ).map { + case ( file, name ) => file -> name.stripPrefix( File.separator ).stripSuffix( ".scalatex" ) + }, + lib.autoRelative( Seq( projectDirectory / "static" ) ), + target / "html", + projectDirectory / "src_generated" / "scalatex", + dependencyClasspath + ) + ) +} +/** @param htmlTarget directory where the html files are generated + */ +object Scalatex { + case class apply( + lib: Lib, parentsLastModified: Long + )( + implicit + logger: Logger, transientCache: java.util.Map[AnyRef, AnyRef], classLoaderCache: cbt.ClassLoaderCache + ) { + case class config( + scalatexFiles: Seq[( File, String )], + staticFiles: Seq[( File, String )], + htmlTarget: File, + srcGenerated: File, + dependencyClasspath: ClassPath, + transform: String = "cbt.plugins.scalatex.runtime.layout", // function String => String + linkStaticFile: Boolean = true, + `package`: String = "cbt.plugins.scalatex.runtime" + ) { + def apply = { + staticFiles.map { + case ( file, relative ) => file -> htmlTarget / relative + }.collect { + case ( from, to ) if from.isDirectory => to.mkdirs + case ( from, to ) if !from.isDirectory && !to.exists => Files.createLink( to.toPath, from.toPath ) + } + lib.cached( + srcGenerated, + ( parentsLastModified +: scalatexFiles.map( _._1 ).map( _.lastModified ) ).max + ) { () => + lib.writeIfChanged( + srcGenerated / "ScalatexGenerated.scala", + s"""// Last generated at ${java.time.ZonedDateTime.now} +package ${`package`} +object ScalatexGenerate extends cbt.plugins.scalatex.runtime.AbstractMain{ + def dependencyClasspath: Seq[java.io.File] = Seq( + ${dependencyClasspath.files.map( _.quote ).mkString( ",\n " )} + ) + def htmlTarget = ${htmlTarget.quote} + import scalatags.Text.all._ + def files = Seq[(String, scalatags.Text.all.SeqFrag[scalatags.Text.all.Frag])]( + ${scalatexFiles.map { case ( from, to ) => s"${to.quote} -> scalatex.twf(${from.string.quote})" }.mkString( ",\n " )} + ) + def render: scalatags.Text.all.SeqFrag[scalatags.Text.all.Frag] => String => String = $transform +} +""".trim ++ "\n" + ) + } + } + } + } +} |