Skip to content

Commit f51c2c0

Browse files
committed
first migration step to 0.4
1 parent af209fe commit f51c2c0

File tree

9 files changed

+44
-55
lines changed

9 files changed

+44
-55
lines changed

mindmap/aspects/build.sbt

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,15 @@
11
name := "mindmap-aspects"
22

33
libraryDependencies ++= Seq(
4-
"js-scala" %% "forest" % "0.4-SNAPSHOT",
5-
"EPFL" %% "js-scala" % "0.3-SNAPSHOT",
4+
"js-scala" %% "forest" % "0.5-SNAPSHOT",
5+
"EPFL" %% "js-scala" % "0.4-SNAPSHOT",
66
"EPFL" %% "lms" % "0.3-SNAPSHOT"
77
)
88

9-
sourceGenerators in Compile <+= (sourceDirectory in Compile, sourceManaged in Compile) map { (sourceDir, targetDir) =>
10-
forest.compiler.Compiler.compile(
11-
scalax.file.Path(sourceDir / "forest" / "Templates"),
12-
scalax.file.Path(targetDir),
13-
Seq("models._", "scala.xml.Node", "scala.virtualization.lms.common._", "scala.js._"),
14-
Seq("Models", "LiftJsScala")
15-
)
16-
(targetDir / "Templates.scala").get.map(_.getAbsoluteFile)
17-
}
18-
199
scalaOrganization := "org.scala-lang.virtualized"
2010

21-
scalaVersion := "2.10.0"
11+
scalaVersion := "2.10.2-RC1"
12+
13+
resolvers += Resolver.sonatypeRepo("snapshots")
2214

2315
scalacOptions ++= Seq("-deprecation", "-unchecked", "-feature", "-Xexperimental", "-Yvirtualize")

mindmap/aspects/project/build.sbt

Lines changed: 0 additions & 1 deletion
This file was deleted.

mindmap/aspects/src/main/forest/Templates/itemMap.forest

Lines changed: 0 additions & 4 deletions
This file was deleted.

mindmap/aspects/src/main/forest/Templates/listMaps.forest

Lines changed: 0 additions & 11 deletions
This file was deleted.

mindmap/aspects/src/main/scala/CodeGenerator.scala

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,21 @@
11

22
import forest._
33
import virtualization.lms.common._
4-
import js._
4+
import scala.js.exp.{JsScalaExp, JSExp}
5+
import scala.js.gen.js.{GenJsScala => JSGenJsScala, GenJS}
6+
import scala.js.gen.scala.{GenJsScala => ScalaGenJsScala}
57

68
object CodeGenerator extends App {
79

8-
trait Prog extends ir.Templates with views.Workspace with models.Models
10+
trait Prog extends views.Workspace with models.Models
911
val prog = new Prog with JsScalaExp with ForestExp { context = Nil }
10-
val templates = new prog.Templates {}
11-
val jsProg = new javascripts.BuildMap with models.Models with JSExp with ListOpsExp with StructExp { context = Nil }
12+
val jsProg = new javascripts.BuildMap with models.Models with JSExp with StructExp { context = Nil }
1213
val jsProg2 = new javascripts.Exploration with JSExp with javascripts.ExtraJSExp { context = Nil }
1314

1415
val scalaGen = new ScalaGenJsScala with ScalaGenForest { val IR: prog.type = prog; stream = null }
1516
val scalaOut = new java.io.PrintWriter("../app/MindMap-generated.scala")
1617
scalaOut.println("package generated {")
17-
scalaGen.emitSource(templates.listMaps, "ListMaps", scalaOut)
18+
scalaGen.emitSource(prog.listMaps, "ListMaps", scalaOut)
1819
scalaGen.emitSource(prog.showMap, "ShowMap", scalaOut)
1920
scalaGen.emitSource3(prog.MindMap, "MindMap", scalaOut)
2021
scalaGen.emitSource2(prog.MindMapR, "MindMapR", scalaOut)
@@ -44,17 +45,17 @@ object CodeGenerator extends App {
4445
scalaOut.close()
4546

4647
val jsGen = new JSGenJsScala with JSGenForest { val IR: prog.type = prog; stream = null }
47-
val jsGen2 = new JSGen with JSGenListOps with JSGenStruct {
48+
val jsGen2 = new GenJS {
4849
val IR: jsProg.type = jsProg; stream = null
4950
}
50-
val jsGen3 = new JSGen with javascripts.JSGenExtra { val IR: jsProg2.type = jsProg2; stream = null }
51+
val jsGen3 = new GenJS with javascripts.JSGenExtra { val IR: jsProg2.type = jsProg2; stream = null }
5152
val jsOut = new java.io.PrintWriter("../app/assets/javascripts/mindmap-generated.js")
5253
jsOut.println(";window.MindMap = (function (m) {")
5354
jsOut.print("m['showMap'] = ")
5455
jsGen.emitSource(prog.showMap, "", jsOut)
5556
jsOut.println(";")
5657
jsOut.print("m['listMaps'] = ")
57-
jsGen.emitSource(templates.listMaps, "", jsOut)
58+
jsGen.emitSource(prog.listMaps, "", jsOut)
5859
jsOut.println(";")
5960
jsOut.print("m['buildMap'] = ")
6061
jsGen2.emitSource(jsProg.buildMap, "", jsOut)

mindmap/aspects/src/main/scala/javascripts/BuildMap.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package javascripts
22

33
import models.Models
44
import virtualization.lms.common._
5-
import js._
5+
import scala.js.language.JS
66

77
trait BuildMap extends JS with Structs { this: Models =>
88

mindmap/aspects/src/main/scala/javascripts/CreateMap.scala

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
package javascripts
22

3-
import scala.js._
4-
import models.Models
5-
import ir.Templates
6-
73
/*trait CreateMap extends JS with Models with Templates {
84
val main = fun { () =>
95
val input = document.find(".form input")

mindmap/aspects/src/main/scala/javascripts/Exploration.scala

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
package javascripts
22

33
import virtualization.lms.common._
4-
import js._
4+
import scala.js.language._
5+
import scala.js.language.dom.Dom
6+
import scala.js.exp._
7+
import scala.js.exp.dom.DomExp
8+
import scala.js.gen.js._
9+
import scala.js.gen.js.dom.GenDom
510

611
// Handle exploration of a mind map (zooming and moving)
712
trait Exploration extends JS with ExtraJS {
8-
type ViewState = JSLiteral { val s: Double; val tx: Double; val ty: Double }
13+
type ViewState = Record { val s: Double; val tx: Double; val ty: Double }
914

1015
def setup(ps: Rep[Double], px: Rep[Double], py: Rep[Double], urlUpdate: Rep[((Double, Double, Double)) => String]) = for {
1116
workspace <- document.find(".workspace")
@@ -17,7 +22,7 @@ trait Exploration extends JS with ExtraJS {
1722
// Update url and svg transformation according to the current view state
1823
val updateTransform = fun { (scale: Rep[Double], translateX: Rep[Double], translateY: Rep[Double]) =>
1924
workspace.setAttribute("transform", "scale(" + scale / 100.0 + ") translate(" + translateX + " " + translateY + ")")
20-
history.replaceState(new JSLiteral { val s = scale; val tx = translateX; val ty = translateY }, "", urlUpdate(scale, translateX, translateY))
25+
history.replaceState(new Record { val s = scale; val tx = translateX; val ty = translateY }, "", urlUpdate(scale, translateX, translateY))
2126
}
2227

2328
// History events
@@ -68,30 +73,30 @@ trait Exploration extends JS with ExtraJS {
6873

6974
// --- Helper to integrate external API
7075

71-
trait ExternApi { this: Base with JSProxyBase =>
76+
trait ExternApi { this: Base with Proxy =>
7277
import language.{higherKinds, implicitConversions}
7378
type Extern[A] <: Rep[A]
7479
implicit def externToApi[A <: AnyRef : Manifest](f: Extern[A]): A = repProxy[A](f) // Han, all function calls will be considered effectful…
7580
}
7681

77-
trait ExternApiExp extends ExternApi { this: BaseExp with JSProxyExp =>
82+
trait ExternApiExp extends ExternApi { this: BaseExp with ProxyExp =>
7883
abstract class Extern[A : Manifest] extends Exp[A]
7984
}
8085

8186
// --- Math JavaScript standard API
8287

83-
trait JSMath { this: Base with ExternApi with JSProxyBase =>
88+
trait JSMath { this: Base with ExternApi with Proxy =>
8489
trait Math {
8590
def round(x: Rep[Double]): Rep[Double]
8691
}
8792
val Math: Extern[Math]
8893
}
8994

90-
trait JSMathExp extends JSMath { this: BaseExp with ExternApiExp with JSProxyExp =>
95+
trait JSMathExp extends JSMath { this: BaseExp with ExternApiExp with ProxyExp =>
9196
object Math extends Extern[Math]
9297
}
9398

94-
trait JSGenMath extends JSGenBase {
99+
trait JSGenMath extends GenBase {
95100
val IR: BaseExp with JSMath
96101
import IR._
97102

@@ -101,8 +106,8 @@ trait JSGenMath extends JSGenBase {
101106
}
102107
}
103108

104-
trait ExtraJS extends JSMath with JSDom with OptionOps with ExternApi with JSProxyBase with Casts with LiftVariables with Variables
105-
trait ExtraJSExp extends JSMathExp with JSDomExp with OptionOpsExp with ExternApiExp with JSProxyExp with CastsCheckedExp
106-
trait JSGenExtra extends JSGenMath with JSGenDom with JSGenOptionOps with JSGenProxy with GenCastChecked {
109+
trait ExtraJS extends JSMath with Dom with OptionOps with ExternApi with Proxy with Casts with LiftVariables with Variables
110+
trait ExtraJSExp extends JSMathExp with DomExp with OptionOpsExp with ExternApiExp with ProxyExp with CastsCheckedExp
111+
trait JSGenExtra extends JSGenMath with GenDom with GenOptionOps with GenProxy with GenCastChecked {
107112
val IR: ExtraJSExp
108113
}

mindmap/aspects/src/main/scala/views/Workspace.scala

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,20 @@ import forest._
44
import scala.xml.Node
55
import scala.virtualization.lms.common._
66
import models._
7-
import scala.js._
7+
import scala.js.language.JsScala
88

9-
trait Workspace extends JsScala with Forest with LiftJsScala { this: Models =>
9+
trait Workspace extends JsScala with Forest { this: Models =>
10+
11+
def itemMap(map: Rep[MindMapR]) =
12+
el('li)(
13+
el('a, 'href -> ("/" + map.id))(map.content.name)
14+
)
15+
16+
def listMaps(maps: Rep[List[MindMapR]]) =
17+
el('div, 'class -> "list-maps")(
18+
el('ul)(for (map <- maps) yield itemMap(map)),
19+
el('p)("Create a", el('strong)(" new mind map"), ":", el('input, 'type -> 'text, 'placeholder -> "Name")())
20+
)
1021

1122
def showMap(map: Rep[MindMap]): Rep[List[Node]] = {
1223
val defs = el('defs)(

0 commit comments

Comments
 (0)