From a84c09efcb2d843ee04ee3299ceb592a00a42267 Mon Sep 17 00:00:00 2001 From: Li Haoyi Date: Sun, 28 Dec 2014 09:09:39 +0100 Subject: wip --- .../SBT__com_chuusai_shapeless_2_11_1_2_4.xml | 13 -- ...BT__com_typesafe_akka_akka_actor_2_11_2_3_6.xml | 13 -- .idea/libraries/SBT__com_typesafe_config_1_2_1.xml | 14 -- .../SBT__io_spray_spray_can_2_11_1_3_2.xml | 14 -- .../SBT__io_spray_spray_http_2_11_1_3_2.xml | 14 -- .../SBT__io_spray_spray_httpx_2_11_1_3_2.xml | 14 -- .../SBT__io_spray_spray_io_2_11_1_3_2.xml | 14 -- .../SBT__io_spray_spray_routing_2_11_1_3_2.xml | 14 -- .../SBT__io_spray_spray_util_2_11_1_3_2.xml | 14 -- .../SBT__org_jvnet_mimepull_mimepull_1_9_4.xml | 13 -- .../SBT__org_parboiled_parboiled_core_1_1_6.xml | 14 -- ...T__org_parboiled_parboiled_scala_2_11_1_1_6.xml | 14 -- book/src/main/scala/book/Book.scala | 91 ------------- book/src/main/scala/book/BookData.scala | 17 ++- book/src/main/scala/book/Main.scala | 87 ++++++++---- book/src/main/scala/book/Utils.scala | 149 +-------------------- book/src/main/scalatex/book/Index.scalatex | 2 +- build.sbt | 8 +- examples/crossBuilds/clientserver | 1 + examples/crossBuilds/clientserver/Procfile | 1 - examples/crossBuilds/clientserver/build.sbt | 38 ------ .../client/shared/main/scala/simple/FileData.scala | 3 - .../client/src/main/scala/simple/Client.scala | 36 ----- .../clientserver/project/build.properties | 1 - .../crossBuilds/clientserver/project/build.sbt | 6 - examples/crossBuilds/clientserver/server/shared | 1 - .../server/src/main/scala/simple/Page.scala | 21 --- .../server/src/main/scala/simple/Server.scala | 46 ------- .../src/main/scala/scalatex/stages/Omg/scala.scala | 8 -- scalatex/build.sbt | 6 - .../src/main/resources/scalac-plugin.xml | 4 - .../src/main/scala/scalatex/CompilerPlugin.scala | 79 ----------- .../src/main/scala/SbtPlugin.scala | 50 ++++++- 33 files changed, 129 insertions(+), 691 deletions(-) delete mode 100644 .idea/libraries/SBT__com_chuusai_shapeless_2_11_1_2_4.xml delete mode 100644 .idea/libraries/SBT__com_typesafe_akka_akka_actor_2_11_2_3_6.xml delete mode 100644 .idea/libraries/SBT__com_typesafe_config_1_2_1.xml delete mode 100644 .idea/libraries/SBT__io_spray_spray_can_2_11_1_3_2.xml delete mode 100644 .idea/libraries/SBT__io_spray_spray_http_2_11_1_3_2.xml delete mode 100644 .idea/libraries/SBT__io_spray_spray_httpx_2_11_1_3_2.xml delete mode 100644 .idea/libraries/SBT__io_spray_spray_io_2_11_1_3_2.xml delete mode 100644 .idea/libraries/SBT__io_spray_spray_routing_2_11_1_3_2.xml delete mode 100644 .idea/libraries/SBT__io_spray_spray_util_2_11_1_3_2.xml delete mode 100644 .idea/libraries/SBT__org_jvnet_mimepull_mimepull_1_9_4.xml delete mode 100644 .idea/libraries/SBT__org_parboiled_parboiled_core_1_1_6.xml delete mode 100644 .idea/libraries/SBT__org_parboiled_parboiled_scala_2_11_1_1_6.xml delete mode 100644 book/src/main/scala/book/Book.scala create mode 160000 examples/crossBuilds/clientserver delete mode 100644 examples/crossBuilds/clientserver/Procfile delete mode 100644 examples/crossBuilds/clientserver/build.sbt delete mode 100644 examples/crossBuilds/clientserver/client/shared/main/scala/simple/FileData.scala delete mode 100644 examples/crossBuilds/clientserver/client/src/main/scala/simple/Client.scala delete mode 100644 examples/crossBuilds/clientserver/project/build.properties delete mode 100644 examples/crossBuilds/clientserver/project/build.sbt delete mode 120000 examples/crossBuilds/clientserver/server/shared delete mode 100644 examples/crossBuilds/clientserver/server/src/main/scala/simple/Page.scala delete mode 100644 examples/crossBuilds/clientserver/server/src/main/scala/simple/Server.scala delete mode 100644 scalatex/api/src/main/scala/scalatex/stages/Omg/scala.scala delete mode 100755 scalatex/compilerPlugin/src/main/resources/scalac-plugin.xml delete mode 100755 scalatex/compilerPlugin/src/main/scala/scalatex/CompilerPlugin.scala diff --git a/.idea/libraries/SBT__com_chuusai_shapeless_2_11_1_2_4.xml b/.idea/libraries/SBT__com_chuusai_shapeless_2_11_1_2_4.xml deleted file mode 100644 index 0ef1f4a..0000000 --- a/.idea/libraries/SBT__com_chuusai_shapeless_2_11_1_2_4.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/libraries/SBT__com_typesafe_akka_akka_actor_2_11_2_3_6.xml b/.idea/libraries/SBT__com_typesafe_akka_akka_actor_2_11_2_3_6.xml deleted file mode 100644 index d697090..0000000 --- a/.idea/libraries/SBT__com_typesafe_akka_akka_actor_2_11_2_3_6.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/libraries/SBT__com_typesafe_config_1_2_1.xml b/.idea/libraries/SBT__com_typesafe_config_1_2_1.xml deleted file mode 100644 index 6a5807f..0000000 --- a/.idea/libraries/SBT__com_typesafe_config_1_2_1.xml +++ /dev/null @@ -1,14 +0,0 @@ - - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/libraries/SBT__io_spray_spray_can_2_11_1_3_2.xml b/.idea/libraries/SBT__io_spray_spray_can_2_11_1_3_2.xml deleted file mode 100644 index ba16743..0000000 --- a/.idea/libraries/SBT__io_spray_spray_can_2_11_1_3_2.xml +++ /dev/null @@ -1,14 +0,0 @@ - - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/libraries/SBT__io_spray_spray_http_2_11_1_3_2.xml b/.idea/libraries/SBT__io_spray_spray_http_2_11_1_3_2.xml deleted file mode 100644 index 6882c9d..0000000 --- a/.idea/libraries/SBT__io_spray_spray_http_2_11_1_3_2.xml +++ /dev/null @@ -1,14 +0,0 @@ - - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/libraries/SBT__io_spray_spray_httpx_2_11_1_3_2.xml b/.idea/libraries/SBT__io_spray_spray_httpx_2_11_1_3_2.xml deleted file mode 100644 index 52bd2f3..0000000 --- a/.idea/libraries/SBT__io_spray_spray_httpx_2_11_1_3_2.xml +++ /dev/null @@ -1,14 +0,0 @@ - - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/libraries/SBT__io_spray_spray_io_2_11_1_3_2.xml b/.idea/libraries/SBT__io_spray_spray_io_2_11_1_3_2.xml deleted file mode 100644 index 5e6ac51..0000000 --- a/.idea/libraries/SBT__io_spray_spray_io_2_11_1_3_2.xml +++ /dev/null @@ -1,14 +0,0 @@ - - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/libraries/SBT__io_spray_spray_routing_2_11_1_3_2.xml b/.idea/libraries/SBT__io_spray_spray_routing_2_11_1_3_2.xml deleted file mode 100644 index 070e877..0000000 --- a/.idea/libraries/SBT__io_spray_spray_routing_2_11_1_3_2.xml +++ /dev/null @@ -1,14 +0,0 @@ - - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/libraries/SBT__io_spray_spray_util_2_11_1_3_2.xml b/.idea/libraries/SBT__io_spray_spray_util_2_11_1_3_2.xml deleted file mode 100644 index 4eb7798..0000000 --- a/.idea/libraries/SBT__io_spray_spray_util_2_11_1_3_2.xml +++ /dev/null @@ -1,14 +0,0 @@ - - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/libraries/SBT__org_jvnet_mimepull_mimepull_1_9_4.xml b/.idea/libraries/SBT__org_jvnet_mimepull_mimepull_1_9_4.xml deleted file mode 100644 index 7fcd3a6..0000000 --- a/.idea/libraries/SBT__org_jvnet_mimepull_mimepull_1_9_4.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/libraries/SBT__org_parboiled_parboiled_core_1_1_6.xml b/.idea/libraries/SBT__org_parboiled_parboiled_core_1_1_6.xml deleted file mode 100644 index 8cf44a6..0000000 --- a/.idea/libraries/SBT__org_parboiled_parboiled_core_1_1_6.xml +++ /dev/null @@ -1,14 +0,0 @@ - - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/libraries/SBT__org_parboiled_parboiled_scala_2_11_1_1_6.xml b/.idea/libraries/SBT__org_parboiled_parboiled_scala_2_11_1_1_6.xml deleted file mode 100644 index fd53a7a..0000000 --- a/.idea/libraries/SBT__org_parboiled_parboiled_scala_2_11_1_1_6.xml +++ /dev/null @@ -1,14 +0,0 @@ - - - - - - - - - - - - - - \ No newline at end of file diff --git a/book/src/main/scala/book/Book.scala b/book/src/main/scala/book/Book.scala deleted file mode 100644 index 71c0d65..0000000 --- a/book/src/main/scala/book/Book.scala +++ /dev/null @@ -1,91 +0,0 @@ -package book -import acyclic.file - -import scalatags.Text.tags2 -import scalatags.Text.all._ - -/** - * Created by haoyi on 10/26/14. - */ -object Book { - val autoResources = Set( - "META-INF/resources/webjars/highlightjs/8.2-1/highlight.min.js", - "META-INF/resources/webjars/highlightjs/8.2-1/styles/idea.min.css", - "META-INF/resources/webjars/highlightjs/8.2-1/languages/scala.min.js", - "META-INF/resources/webjars/highlightjs/8.2-1/languages/javascript.min.js", - "META-INF/resources/webjars/highlightjs/8.2-1/languages/bash.min.js", - "META-INF/resources/webjars/highlightjs/8.2-1/languages/diff.min.js", - "META-INF/resources/webjars/highlightjs/8.2-1/languages/xml.min.js", - "META-INF/resources/webjars/pure/0.5.0/pure-min.css", - "META-INF/resources/webjars/pure/0.5.0/grids-responsive-min.css", - "META-INF/resources/webjars/font-awesome/4.2.0/fonts/FontAwesome.otf", - "META-INF/resources/webjars/font-awesome/4.2.0/fonts/fontawesome-webfont.eot", - "META-INF/resources/webjars/font-awesome/4.2.0/fonts/fontawesome-webfont.svg", - "META-INF/resources/webjars/font-awesome/4.2.0/fonts/fontawesome-webfont.ttf", - "META-INF/resources/webjars/font-awesome/4.2.0/fonts/fontawesome-webfont.woff", - "css/side-menu.css", - "example-opt.js", -// "example-opt.js.map", - "webpage/weather.js", - "favicon.svg", - "favicon.png" - ) - - val fontAwesomeCss = - "META-INF/resources/webjars/font-awesome/4.2.0/css/font-awesome.min.css" - - val manualResources = Set( - "images/javascript-the-good-parts-the-definitive-guide.jpg", - "images/Hello World.png", - "images/Hello World White.png", - "images/Hello World Console.png", - "images/IntelliJ Hello.png", - "images/Dropdown.png", - "images/Scalatags Downloads.png", - fontAwesomeCss - ) - - - val txt = Index() - val data = upickle.write(sect.structure) - val googleAnalytics = - """ - |(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){ - | (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o), - | m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m) - | })(window,document,'script','//www.google-analytics.com/analytics.js','ga'); - | - | ga('create', 'UA-27464920-4', 'auto'); - | ga('send', 'pageview'); - """.stripMargin - val site = Seq( - raw(""), - html( - head( - meta(charset:="utf-8"), - meta(name:="viewport", content:="width=device-width, initial-scale=1.0"), - link(rel:="shortcut icon", `type`:="image/png", href:="favicon.png"), - link(rel:="stylesheet", href:=fontAwesomeCss), - link(rel:="stylesheet", href:="styles.css"), - tags2.title("Hands-on Scala.js"), - script(src:="scripts.js"), - script(raw(googleAnalytics)) - ), - body( - onload:=s"Controller().main($data)", - div(id:="layout")( - a(href:="#menu", id:="menuLink", cls:="menu-link")( - span - ), - div(id:="menu") - - ), - div(id:="main", - div(id:="main-box")( - txt - ) - ) - ) - ) - ).render -} diff --git a/book/src/main/scala/book/BookData.scala b/book/src/main/scala/book/BookData.scala index ff1f23a..8484f10 100644 --- a/book/src/main/scala/book/BookData.scala +++ b/book/src/main/scala/book/BookData.scala @@ -50,11 +50,22 @@ object BookData { def half = div(cls:="pure-u-1 pure-u-md-1-2") - val hl = new Highlighter( - Seq( + val hl = new scalatex.site.Highlighter { + override val pathMappings = Seq( s"$cloneRoot/scala-js" -> "https://github.com/scala-js/scala-js", s"$cloneRoot/workbench-example-app" -> "https://github.com/lihaoyi/workbench-example-app", "" -> "https://github.com/lihaoyi/hands-on-scala-js" ) - ) + override val suffixMappings = Map( + "scala" -> "scala", + "sbt" -> "scala", + "js" -> "javascript" + ) + def scala(s: String) = this.highlight(s, "scala") + def bash(s: String) = this.highlight(s, "bash") + def html(s: String) = this.highlight(s, "html") + def xml(s: String) = this.highlight(s, "xml") + def diff(s: String) = this.highlight(s, "diff") + def javascript(s: String) = this.highlight(s, "javascript") + } } diff --git a/book/src/main/scala/book/Main.scala b/book/src/main/scala/book/Main.scala index 4b862d0..3bae7b8 100644 --- a/book/src/main/scala/book/Main.scala +++ b/book/src/main/scala/book/Main.scala @@ -3,40 +3,74 @@ import acyclic.file import java.io.InputStream import java.nio.file.{Paths, Files} +import scalatags.Text.{attrs, tags2, all} +import scalatags.Text.all._ +import scalatex.site.Section.Tree +import scalatex.site.Site object Main { - def write(txt: String, dest: String) = { - Paths.get(dest).toFile.getParentFile.mkdirs() - Files.deleteIfExists(Paths.get(dest)) - Files.write(Paths.get(dest), txt.getBytes) - } - def copy(src: InputStream, dest: String) = { - Paths.get(dest).toFile.getParentFile.mkdirs() - Files.deleteIfExists(Paths.get(dest)) - Files.copy(src, Paths.get(dest)) - } - def main(args: Array[String]): Unit = { - println("Writing Book") - val outputRoot = System.getProperty("output.root") + "/" - write(Book.site, s"$outputRoot/index.html") - - val jsFiles = Book.autoResources.filter(_.endsWith(".js")).toSet - val cssFiles = Book.autoResources.filter(_.endsWith(".css")).toSet - val miscFiles = Book.autoResources -- cssFiles -- jsFiles + val googleAnalytics = + """ + |(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){ + | (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o), + | m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m) + | })(window,document,'script','//www.google-analytics.com/analytics.js','ga'); + | + | ga('create', 'UA-27464920-4', 'auto'); + | ga('send', 'pageview'); + """.stripMargin + + val data = upickle.write(sect.structure) + + val s = new Site { + def content = Map("index.html" -> Index()) + + override def autoResources = super.autoResources | Set( + "META-INF/resources/webjars/pure/0.5.0/grids-responsive-min.css", + "css/side-menu.css", + "example-opt.js", + "webpage/weather.js", + "favicon.svg", + "favicon.png" + ) + override def manualResources = super.manualResources | Set( + "images/javascript-the-good-parts-the-definitive-guide.jpg", + "images/Hello World.png", + "images/Hello World White.png", + "images/Hello World Console.png", + "images/IntelliJ Hello.png", + "images/Dropdown.png", + "images/Scalatags Downloads.png" + ) + override def headFrags = super.headFrags ++ Seq( + meta(charset:="utf-8"), + meta(name:="viewport", attrs.content:="width=device-width, initial-scale=1.0"), + link(rel:="shortcut icon", `type`:="image/png", href:="favicon.png"), + tags2.title("Hands-on Scala.js"), + script(raw(googleAnalytics)) + ) + override def bodyFrag(frag: Frag) = body( + onload:=s"Controller().main($data)", + div(id:="layout")( + a(href:="#menu", id:="menuLink", cls:="menu-link")( + span + ), + div(id:="menu") + + ), + div(id:="main", + div(id:="main-box")( + frag + ) + ) + ) - for(res <- Book.manualResources ++ miscFiles) { - copy(getClass.getResourceAsStream("/" + res), outputRoot + res) } - for((resources, dest) <- Seq(jsFiles -> "scripts.js", cssFiles -> "styles.css")) { - val blobs = for(res <- resources.iterator) yield { - io.Source.fromInputStream(getClass.getResourceAsStream("/"+res)).mkString - } + s.renderTo(System.getProperty("output.root") + "/") - write(blobs.mkString("\n"), outputRoot + dest) - } val allNames = { def rec(n: Tree[String]): Seq[String] = { @@ -62,5 +96,4 @@ object Main { // lnk.usedLinks } - } diff --git a/book/src/main/scala/book/Utils.scala b/book/src/main/scala/book/Utils.scala index 2c861d0..e551621 100644 --- a/book/src/main/scala/book/Utils.scala +++ b/book/src/main/scala/book/Utils.scala @@ -13,69 +13,18 @@ case class pureTable(header: Frag*){ ) } } -object sect{ - +object sect extends scalatex.site.Section{ var indent = 0 - val headers = Seq[((String, String, Frag) => scalatags.Text.Tag, Option[Frag => Frag])]( - ((h, s, l) => div(cls:="header")( - h1(h, l), - h2(s) - ), Some(f => div(cls:="content", f))), - ((h, s, l) => div(cls:="header")( - h1(id:=munge(h), h, l), - br - ), None), - (h1(_, _, _), None), - (h2(_, _, _), None), - (h3(_, _, _), None), - (h4(_, _, _), None), - (h5(_, _, _), None), - (h6(_, _, _), None) - ) - - var structure = Tree[String]("root", mutable.Buffer.empty) - - val usedRefs = mutable.Set.empty[String] - def ref(s: String, txt: String = "") = { - usedRefs += s - a(if (txt == "") s else txt, href:=s"#${munge(s)}") - } - - def munge(name: String) = { - name.replace(" ", "") - } + override val headers: Seq[Header] = Seq( + Header((h, s, l) => div(cls:="header")(h1(h, l), h2(s)), f => div(cls:="content", f)), + Header((h, s, l) => div(cls:="header")(h1(id:=munge(h), h, l), br)), + h1, h2, h3, h4, h5, h6 + ) } -case class sect(name: String, subname: String = ""){ - sect.indent += 1 - val newNode = Tree[String](name, mutable.Buffer.empty) - val (headerWrap, contentWrap) = sect.headers(sect.indent-1) - sect.structure.children.append(newNode) - val prev = sect.structure - sect.structure = newNode - def apply(args: Frag*) = { - val wrappedContents = contentWrap.getOrElse((x: Frag) => x)(args) - val headingAnchor = a( - cls:="header-link", - href:=s"#${sect.munge(name)}", - " ", - i(cls:="fa fa-link") - ) - val res = Seq[Frag]( - headerWrap(name, subname, headingAnchor)( - cls:="content-subhead", - id:=sect.munge(name) - ), - wrappedContents - ) - sect.indent -= 1 - sect.structure = prev - res - } -} -case class Tree[T](value: T, children: mutable.Buffer[Tree[T]]) + object lnk{ val usedLinks = mutable.Set.empty[String] def apply(name: String, url: String) = { @@ -122,87 +71,3 @@ object lnk{ val scalaPickling = lnk("scala-pickling", "https://github.com/scala/pickling") } } - -class Highlighter(mappings: Seq[(String, String)]){ - def highlight(snippet: Seq[String], lang: String) = { - val string = snippet.mkString - val lines = string.split("\n", -1) - if (lines.length == 1){ - code(cls:=lang + " highlight-me", lines(0), padding:=0, display:="inline") - }else{ - val minIndent = lines.map(_.takeWhile(_ == ' ').length) - .filter(_ > 0) - .min - val stripped = lines.map(_.drop(minIndent)) - .dropWhile(_ == "") - .mkString("\n") - - pre(code(cls:=lang + " highlight-me hljs", stripped)) - } - } - - def javascript(code: String*) = highlight(code, "javascript") - def scala(code: String*) = highlight(code, "scala") - def bash(code: String*) = highlight(code, "bash") - def diff(code: String*) = highlight(code, "diff") - def html(code: String*) = highlight(code, "xml") - - def ref(filepath: String, start: String = "", end: String = "\n") = { - - val lang = filepath.split('.').last match { - case "js" => "javascript" - case "scala" => "scala" - case "sbt" => "scala" - case "sh" => "bash" - case "html" => "xml" - case x => - println("??? " + x) - ??? - } - - val lines = io.Source.fromFile(filepath).getLines().toVector - - def indent(line: String) = line.takeWhile(_.isWhitespace).length - - val startLine = lines.indexWhere(_.contains(start)) - if (startLine == -1){ - throw new Exception("Can't find marker: " + start) - } - val whitespace = indent(lines(startLine)) - val endLine = lines.indexWhere( - line => line.contains(end) || (indent(line) < whitespace && line.trim != ""), - startLine + 1 - ) - val sliced = - if (endLine == -1) lines.drop(startLine) - else lines.slice(startLine, endLine) - - val blob = sliced.map(_.drop(whitespace)).mkString("\n") - - val (prefix, url) = - mappings.iterator - .find{case (prefix, path) => filepath.startsWith(prefix)} - .get - - val hash = - if (endLine == -1) "" - else s"#L$startLine-L$endLine" - - val linkUrl = - s"$url/tree/master/${filepath.drop(prefix.length)}$hash" - pre( - code(cls:=lang + " highlight-me hljs", blob), - a( - cls:="header-link", - i(cls:="fa fa-link "), - position.absolute, - right:="0.5em", - bottom:="0.5em", - display.block, - fontSize:="24px", - href:=linkUrl, - target:="_blank" - ) - ) - } -} \ No newline at end of file diff --git a/book/src/main/scalatex/book/Index.scalatex b/book/src/main/scalatex/book/Index.scalatex index 7a7e2b8..1a10aa0 100644 --- a/book/src/main/scalatex/book/Index.scalatex +++ b/book/src/main/scalatex/book/Index.scalatex @@ -80,4 +80,4 @@ is a set of detailed expositions on various parts of the Scala.js platform. Noth @indepth.DesignSpace() @sect{Java APIs} - @indepth.JavaAPIs() \ No newline at end of file + @indepth.JavaAPIs() diff --git a/build.sbt b/build.sbt index 43d679c..6515388 100644 --- a/build.sbt +++ b/build.sbt @@ -20,13 +20,11 @@ val sharedSettings = Seq( lazy val book = Project( id = "book", base = file("book") -).settings(sharedSettings ++ inConfig(Compile)(scalatex.SbtPlugin.settings):_*).settings( +).settings(sharedSettings ++ scalatex.SbtPlugin.projectSettings:_*).settings( libraryDependencies ++= Seq( - "org.webjars" % "highlightjs" % "8.2-1", - "org.webjars" % "pure" % "0.5.0", - "org.webjars" % "font-awesome" % "4.2.0", "com.scalatags" %% "scalatags" % "0.4.2", - "com.lihaoyi" %%% "upickle" % "0.2.5" + "com.lihaoyi" %%% "upickle" % "0.2.5", + "com.lihaoyi" %% "scalatex-site" % "0.1.0" ), (resources in Compile) += { (fullOptJS in (demos, Compile)).value diff --git a/examples/crossBuilds/clientserver b/examples/crossBuilds/clientserver new file mode 160000 index 0000000..8d19994 --- /dev/null +++ b/examples/crossBuilds/clientserver @@ -0,0 +1 @@ +Subproject commit 8d199942e6ad4c927b825c493c69067d9474a8fb diff --git a/examples/crossBuilds/clientserver/Procfile b/examples/crossBuilds/clientserver/Procfile deleted file mode 100644 index 59ff8a8..0000000 --- a/examples/crossBuilds/clientserver/Procfile +++ /dev/null @@ -1 +0,0 @@ -web: server/target/universal/stage/bin/server diff --git a/examples/crossBuilds/clientserver/build.sbt b/examples/crossBuilds/clientserver/build.sbt deleted file mode 100644 index 3bba3af..0000000 --- a/examples/crossBuilds/clientserver/build.sbt +++ /dev/null @@ -1,38 +0,0 @@ -import NativePackagerKeys._ -import utest.jsrunner.JsCrossBuild -import scala.scalajs.sbtplugin.ScalaJSPlugin._ -import ScalaJSKeys._ -val sharedSettings = Seq( - unmanagedSourceDirectories in Compile += - baseDirectory.value / "shared" / "main" / "scala", - libraryDependencies ++= Seq( - "com.scalatags" %%% "scalatags" % "0.4.2", - "com.lihaoyi" %%% "upickle" % "0.2.5" - ), - scalaVersion := "2.11.4" -) - -lazy val client = project.in(file("client")) - .settings(scalaJSSettings:_*) - .settings(sharedSettings:_*) - .settings( - libraryDependencies ++= Seq( - "org.scala-lang.modules.scalajs" %%% "scalajs-dom" % "0.6" - ) -) - -lazy val server = project.in(file("server")) - .settings(sharedSettings:_*) - .settings(packageArchetype.java_application:_*) - .settings( - libraryDependencies ++= Seq( - "io.spray" %% "spray-can" % "1.3.2", - "io.spray" %% "spray-routing" % "1.3.2", - "com.typesafe.akka" %% "akka-actor" % "2.3.6" - ), - (resources in Compile) += { - (fastOptJS in (client, Compile)).value - (artifactPath in (client, Compile, fastOptJS)).value - } -) - diff --git a/examples/crossBuilds/clientserver/client/shared/main/scala/simple/FileData.scala b/examples/crossBuilds/clientserver/client/shared/main/scala/simple/FileData.scala deleted file mode 100644 index d3d2f91..0000000 --- a/examples/crossBuilds/clientserver/client/shared/main/scala/simple/FileData.scala +++ /dev/null @@ -1,3 +0,0 @@ -package simple - -case class FileData(name: String, size: Long) \ No newline at end of file diff --git a/examples/crossBuilds/clientserver/client/src/main/scala/simple/Client.scala b/examples/crossBuilds/clientserver/client/src/main/scala/simple/Client.scala deleted file mode 100644 index adefe01..0000000 --- a/examples/crossBuilds/clientserver/client/src/main/scala/simple/Client.scala +++ /dev/null @@ -1,36 +0,0 @@ -package simple - -import scalatags.JsDom.all._ -import scala.scalajs.concurrent.JSExecutionContext.Implicits.runNow -import org.scalajs.dom -import dom.extensions.Ajax -import scala.scalajs.js.annotation.JSExport - -@JSExport -object Client extends{ - @JSExport - def main(container: dom.HTMLDivElement) = { - val inputBox = input.render - val outputBox = ul.render - def update() = Ajax.post("/ajax/list", inputBox.value).foreach{ xhr => - val data = upickle.read[Seq[FileData]](xhr.responseText) - outputBox.innerHTML = "" - for(FileData(name, size) <- data){ - outputBox.appendChild( - li( - b(name), " - ", size, " bytes" - ).render - ) - } - } - inputBox.onkeyup = (e: dom.Event) => update() - update() - container.appendChild( - div( - h1("File Search"), - inputBox, - outputBox - ).render - ) - } -} \ No newline at end of file diff --git a/examples/crossBuilds/clientserver/project/build.properties b/examples/crossBuilds/clientserver/project/build.properties deleted file mode 100644 index 748703f..0000000 --- a/examples/crossBuilds/clientserver/project/build.properties +++ /dev/null @@ -1 +0,0 @@ -sbt.version=0.13.7 diff --git a/examples/crossBuilds/clientserver/project/build.sbt b/examples/crossBuilds/clientserver/project/build.sbt deleted file mode 100644 index c24e2b0..0000000 --- a/examples/crossBuilds/clientserver/project/build.sbt +++ /dev/null @@ -1,6 +0,0 @@ -/*project/build.sbt*/ -addSbtPlugin("org.scala-lang.modules.scalajs" % "scalajs-sbt-plugin" % "0.5.5") - -addSbtPlugin("com.lihaoyi" % "utest-js-plugin" % "0.2.4") - -addSbtPlugin("com.typesafe.sbt" % "sbt-native-packager" % "0.7.4") diff --git a/examples/crossBuilds/clientserver/server/shared b/examples/crossBuilds/clientserver/server/shared deleted file mode 120000 index f32be42..0000000 --- a/examples/crossBuilds/clientserver/server/shared +++ /dev/null @@ -1 +0,0 @@ -../client/shared \ No newline at end of file diff --git a/examples/crossBuilds/clientserver/server/src/main/scala/simple/Page.scala b/examples/crossBuilds/clientserver/server/src/main/scala/simple/Page.scala deleted file mode 100644 index d657290..0000000 --- a/examples/crossBuilds/clientserver/server/src/main/scala/simple/Page.scala +++ /dev/null @@ -1,21 +0,0 @@ -package simple -import scalatags.Text.all._ - -object Page{ - val boot = - "Client().main(document.getElementById('contents'))" - val skeleton = - html( - head( - script(src:="/client-fastopt.js"), - link( - rel:="stylesheet", - href:="https://cdnjs.cloudflare.com/ajax/libs/pure/0.5.0/pure-min.css" - ) - ), - body( - onload:=boot, - div(id:="contents") - ) - ) -} diff --git a/examples/crossBuilds/clientserver/server/src/main/scala/simple/Server.scala b/examples/crossBuilds/clientserver/server/src/main/scala/simple/Server.scala deleted file mode 100644 index e9038b5..0000000 --- a/examples/crossBuilds/clientserver/server/src/main/scala/simple/Server.scala +++ /dev/null @@ -1,46 +0,0 @@ -package simple - -import akka.actor.ActorSystem -import spray.http.{HttpEntity, MediaTypes} -import spray.routing.SimpleRoutingApp - -import scala.util.Properties - -object Server extends SimpleRoutingApp{ - def main(args: Array[String]): Unit = { - implicit val system = ActorSystem() - val port = Properties.envOrElse("PORT", "8080").toInt - startServer("0.0.0.0", port = port){ - get{ - pathSingleSlash{ - complete{ - HttpEntity( - MediaTypes.`text/html`, - Page.skeleton.render - ) - } - } ~ - getFromResourceDirectory("") - } ~ - post{ - path("ajax" / "list"){ - extract(_.request.entity.asString) { e => - complete { - upickle.write(list(e)) - } - } - } - } - } - } - def list(path: String) = { - val (dir, last) = path.splitAt(path.lastIndexOf("/") + 1) - val files = - Option(new java.io.File("./" + dir).listFiles()) - .toSeq.flatten - for{ - f <- files - if f.getName.startsWith(last) - } yield FileData(f.getName, f.length()) - } -} \ No newline at end of file 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 @@ - - demo-plugin - scalatex.CompilerPlugin - \ 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 ) } -- cgit v1.2.3