diff options
author | lihaoyi <haoyi.sg@gmail.com> | 2013-10-27 23:45:09 -0700 |
---|---|---|
committer | lihaoyi <haoyi.sg@gmail.com> | 2013-10-27 23:45:09 -0700 |
commit | 680216d364b760e0f41c25c4f69fc061150a0341 (patch) | |
tree | 77f90f75097fb0297c4a00ce0dd65ffe3a84f7a2 | |
download | workbench-680216d364b760e0f41c25c4f69fc061150a0341.tar.gz workbench-680216d364b760e0f41c25c4f69fc061150a0341.tar.bz2 workbench-680216d364b760e0f41c25c4f69fc061150a0341.zip |
first commit
-rw-r--r-- | .gitignore | 7 | ||||
-rw-r--r-- | plugin/build.sbt | 1 | ||||
-rw-r--r-- | plugin/src/main/scala/scala/js/resource/Plugin.scala | 30 | ||||
-rw-r--r-- | runtime/project/Build.scala | 11 | ||||
-rw-r--r-- | runtime/project/build.properties | 1 | ||||
-rw-r--r-- | runtime/project/build.sbt | 5 | ||||
-rw-r--r-- | runtime/src/main/scala/scala/js/Resources.scala | 12 |
7 files changed, 67 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..aeea8ed --- /dev/null +++ b/.gitignore @@ -0,0 +1,7 @@ +target/ +.cache +.classpath +.project +.settings/ +.idea +.idea_modules diff --git a/plugin/build.sbt b/plugin/build.sbt new file mode 100644 index 0000000..7c0db51 --- /dev/null +++ b/plugin/build.sbt @@ -0,0 +1 @@ +sbtPlugin := true
\ No newline at end of file diff --git a/plugin/src/main/scala/scala/js/resource/Plugin.scala b/plugin/src/main/scala/scala/js/resource/Plugin.scala new file mode 100644 index 0000000..cfa68af --- /dev/null +++ b/plugin/src/main/scala/scala/js/resource/Plugin.scala @@ -0,0 +1,30 @@ +package scala.js.resource + +import sbt._ +import Keys._ + +object Plugin extends sbt.Plugin { + val myTask = taskKey[Set[File]]("prepares resources") + val resourceSettings = Seq( + watchSources := { + watchSources.value ++ (resources in Compile).value + }, + + myTask := { + val fileData = for{ + resourceRoot <- (resources in Compile).value + (file, path) <- Path.allSubpaths(resourceRoot) + } yield { + path -> new sun.misc.BASE64Encoder().encode(IO.readBytes(file)).replace("\n", "").replace("\r", "") + } + + val bundle = crossTarget.value / "resources.js" + val fileLines = for((path, data) <- fileData) yield { " \"" + path + "\": ScalaJS.Resource(\"" + data + "\")" } + + + IO.write(bundle, "\nScalaJS.resources = {\n" + fileLines.mkString(",\n") + "\n}" ) + + Set(bundle) + } + ) +} diff --git a/runtime/project/Build.scala b/runtime/project/Build.scala new file mode 100644 index 0000000..b7d4ecc --- /dev/null +++ b/runtime/project/Build.scala @@ -0,0 +1,11 @@ +import sbt._ +import Keys._ +import ch.epfl.lamp.sbtscalajs.ScalaJSPlugin._ +import ScalaJSKeys._ + +object Build extends sbt.Build { + lazy val resource = + project.in(file(".")) + .settings(scalaJSSettings: _*) + .settings(name := "resources") +}
\ No newline at end of file diff --git a/runtime/project/build.properties b/runtime/project/build.properties new file mode 100644 index 0000000..1ebc8a2 --- /dev/null +++ b/runtime/project/build.properties @@ -0,0 +1 @@ + sbt.version=0.13.0 diff --git a/runtime/project/build.sbt b/runtime/project/build.sbt new file mode 100644 index 0000000..3407493 --- /dev/null +++ b/runtime/project/build.sbt @@ -0,0 +1,5 @@ +addSbtPlugin("ch.epfl.lamp" % "scalajs-sbt-plugin" % "0.1-SNAPSHOT") + +addSbtPlugin("com.github.mpeltonen" % "sbt-idea" % "1.5.1") + + diff --git a/runtime/src/main/scala/scala/js/Resources.scala b/runtime/src/main/scala/scala/js/Resources.scala new file mode 100644 index 0000000..7bf344c --- /dev/null +++ b/runtime/src/main/scala/scala/js/Resources.scala @@ -0,0 +1,12 @@ +package scala.js + + +object Resource { + def apply(path: String) = { + Dynamic.global.ScalaJS.resources(path) + } +} + +class Resource(base64: String){ + lazy val string = Dynamic.global.atob(base64) +}
\ No newline at end of file |