summaryrefslogtreecommitdiff
path: root/book/src/main/scala/book/Utils.scala
diff options
context:
space:
mode:
Diffstat (limited to 'book/src/main/scala/book/Utils.scala')
-rw-r--r--book/src/main/scala/book/Utils.scala57
1 files changed, 57 insertions, 0 deletions
diff --git a/book/src/main/scala/book/Utils.scala b/book/src/main/scala/book/Utils.scala
new file mode 100644
index 0000000..0b435a3
--- /dev/null
+++ b/book/src/main/scala/book/Utils.scala
@@ -0,0 +1,57 @@
+package book
+
+
+import scala.collection.mutable
+import scalatags.Text.all._
+
+case class Node(name: String, children: mutable.Buffer[Node])
+object Utils{
+ val autoResources = Seq(
+ "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",
+ "css/pure-min.css",
+ "css/layouts/side-menu.css",
+ "js/ui.js"
+ )
+
+ val manualResources = Seq(
+ "images/javascript-the-good-parts-the-definitive-guide.jpg",
+ "example-fastopt.js"
+ )
+
+ val includes = for(res <- Utils.autoResources) yield {
+ if (res.endsWith(".js"))
+ script(src:=res)
+ else if (res.endsWith(".css"))
+ link(rel:="stylesheet", href:=res)
+ else
+ raw("")
+ }
+ println(includes)
+ var indent = 1
+ val headers = Seq(h1, h2, h3, h4, h5, h6)
+ val structure = Node("Hands-on Scala.js", mutable.Buffer.empty)
+ var current = structure
+ case class sect(name: String){
+ indent += 1
+ val newNode = Node(name, mutable.Buffer.empty)
+ current.children.append(newNode)
+ val prev = current
+ current = newNode
+ def apply(args: Frag*) = {
+ val res = Seq(
+ headers(indent-1)(cls:="content-subhead", id:=munge(name), name) +: args:_*
+ )
+ indent -= 1
+ current = prev
+ res
+ }
+ }
+ def munge(name: String) = {
+ name.replace(" ", "")
+ }
+
+} \ No newline at end of file