diff options
author | Li Haoyi <haoyi@dropbox.com> | 2014-11-01 00:56:12 -0700 |
---|---|---|
committer | Li Haoyi <haoyi@dropbox.com> | 2014-11-01 00:56:12 -0700 |
commit | 3d73267c4b3ecf3cdca54ded8dfd8a2caeeb3ca9 (patch) | |
tree | 9f1846359c784a6e4bfc4682fddc8b6c884bf811 /book/src/main/scala | |
parent | 058e9bac2dd8166051bafa16d51f27ee5856929a (diff) | |
download | hands-on-scala-js-3d73267c4b3ecf3cdca54ded8dfd8a2caeeb3ca9.tar.gz hands-on-scala-js-3d73267c4b3ecf3cdca54ded8dfd8a2caeeb3ca9.tar.bz2 hands-on-scala-js-3d73267c4b3ecf3cdca54ded8dfd8a2caeeb3ca9.zip |
works, with a compiler-plugin based architecture supporting incremental compilation
Diffstat (limited to 'book/src/main/scala')
-rw-r--r-- | book/src/main/scala/book/Book.scala | 55 | ||||
-rw-r--r-- | book/src/main/scala/book/Utils.scala | 2 |
2 files changed, 10 insertions, 47 deletions
diff --git a/book/src/main/scala/book/Book.scala b/book/src/main/scala/book/Book.scala index 10116fe..37857db 100644 --- a/book/src/main/scala/book/Book.scala +++ b/book/src/main/scala/book/Book.scala @@ -1,6 +1,6 @@ package book -import twist._ +import scalatex._ import scalatags.Text.tags2 import scala.collection.mutable @@ -12,11 +12,7 @@ import scalatags.Text.all._ object Book { import Utils.sect - lazy val intro = sect("Intro to Scala.js")(twf("book/intro.tw")) - lazy val gettingStarted = sect("Getting Started")(twf("book/getting-started.tw")) - lazy val canvasApp = sect("Canvas App")(twf("book/canvas-app.tw")) - lazy val webPage = sect("Interactive Web Pages")(twf("book/web-page.tw")) - val txt = twf("book/index.tw") + val txt = Index.template val contentBar = { def rec(current: Node, depth: Int): Seq[Frag] = { println("\t"*depth + current.name) @@ -69,19 +65,11 @@ object Book { ) ).render - object hli{ - def javascript(code: String*) = hl.highlight(code, "javascript", inline=true) - def scala(code: String*) = hl.highlight(code, "scala", inline=true) - def bash(code: String*) = hl.highlight(code, "bash", inline=true) - def diff(code: String*) = hl.highlight(code, "diff", inline=true) - def html(code: String*) = hl.highlight(code, "xml", inline=true) - } - object hl{ - def highlight(snippet: Seq[String], lang: String, inline: Boolean) = { + def highlight(snippet: Seq[String], lang: String) = { val string = snippet.mkString val lines = string.split("\n", -1) - if (inline){ + if (lines.length == 1){ code(cls:=lang + " highlight-me", lines(0), padding:=0, display:="inline") }else{ val minIndent = lines.map(_.takeWhile(_ == ' ').length) @@ -95,34 +83,11 @@ object Book { } } - def javascript(code: String*) = highlight(code, "javascript", inline=false) - def scala(code: String*) = highlight(code, "scala", inline=false) - def bash(code: String*) = highlight(code, "bash", inline=false) - def diff(code: String*) = highlight(code, "diff", inline=false) - def html(code: String*) = highlight(code, "xml", inline=false) - - /** - * Kinds of refs: - * - * Rule: Starting from a line, keep consuming until - * the identation drops below the start - * - * def main = { - * /*example*/ - * i am a cow - * hear me moo - * } - * - * Rule: Starting from a line, keep consuming until - * the indentation becomes equivalent to the current. If - * it's a cosing brace, keep it. - * val x = omg - * val y = zzz - * - * class C{ - * - * } - */ + 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") = { @@ -140,8 +105,6 @@ object Book { val lines = io.Source.fromFile(filepath).getLines().toVector def indent(line: String) = line.takeWhile(_.isWhitespace).length - println(lines) - println(start) val startLine = lines.indexWhere(_.contains(start)) if (startLine == -1){ diff --git a/book/src/main/scala/book/Utils.scala b/book/src/main/scala/book/Utils.scala index 54c9231..a991ca4 100644 --- a/book/src/main/scala/book/Utils.scala +++ b/book/src/main/scala/book/Utils.scala @@ -39,7 +39,7 @@ object Utils{ else raw("") } - println(includes) + var indent = 0 |