Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 48f0a47

Browse files
committed
a bit more documentation
1 parent 7891a1a commit 48f0a47

File tree

11 files changed

+86
-6
lines changed

11 files changed

+86
-6
lines changed

README.md

Lines changed: 51 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,48 @@
11
# js-scala: JavaScript as an embedded DSL in Scala #
22

3-
### Documentation
3+
js-scala is a Scala library providing composable JavaScript code generators as embedded DSLs. Generate (optimized) JavaScript code from Scala-like code:
4+
5+
```scala
6+
import scala.js.language.JS
7+
trait JavaScriptGreet extends JS {
8+
9+
def greet(name: Rep[String]): Rep[Unit] = {
10+
println("Hello, " + name + "!")
11+
}
12+
13+
}
14+
```
15+
16+
`greet` is a JavaScript program generator that produces a program that prints a message in the console. The JavaScript code can be produced as follows:
17+
18+
```scala
19+
import scala.js.exp.JSExp
20+
import scala.js.gen.js.GenJS
21+
object Generator extends App {
22+
val javaScriptGreet = new JavaScriptGreet with JSExp
23+
val codeGen = new GenJS { val IR: javaScriptGreet.type = javaScriptGreet }
24+
codeGen.emitSource(javaScriptGreet.greet, "greet", new java.io.PrintWriter(System.out))
25+
}
26+
```
27+
28+
Running the above Scala program will print the following on the standard output:
29+
30+
```javascript
31+
function greet(x0) {
32+
var x1 = "Hello, "+x0;
33+
var x2 = x1+"!";
34+
var x3 = console.log(x2);
35+
}
36+
```
37+
38+
## Publications and talks
439

540
* ECOOP 2012 paper ([PDF](http://infoscience.epfl.ch/record/179888/files/js-scala-ecoop.pdf)) and slides ([PDF](http://pldi12.cs.purdue.edu/sites/default/files/slides_ecoop_gkossakowski.pdf))
641
* [Scala Days 2012 talk](http://skillsmatter.com/podcast/scala/javascript-embedded-dsl-scala)
42+
* mloc-js'13 talk ([slides](http://prezi.com/l23gghh7c27t/?utm_campaign=share&utm_medium=copy&rc=ex0share))
43+
* GPCE'13 paper ([PDF](https://github.com/js-scala/js-scala/raw/master/papers/gpce2013/gpce19c-foy.pdf)) and [slides](https://docs.google.com/presentation/d/1ErPjZMTheuKwp428QpxWibZlyjK3PKijwKtYEaXWoxQ/pub?start=false&loop=false&delayms=3000)
744

8-
### Setup
45+
## Setup
946

1047
1. Setup [virtualization-lms-core](http://github.com/TiarkRompf/virtualization-lms-core):
1148
- `$ git clone [email protected]:TiarkRompf/virtualization-lms-core.git`
@@ -20,11 +57,14 @@
2057
- `> test`
2158
4. Publish it (if you want to use it in your project):
2259
- `> publish-local`
23-
5. Run the examples:
60+
5. Generate the API documentation:
61+
- `> doc`
62+
- The documentation is generated in the `core/target/scala-2.10/api/` directory.
63+
6. Run the examples:
2464
- `> project examples`
2565
- `> run`
2666

27-
### Use it in your project
67+
## Use it in your project
2868

2969
1. Add a dependency on js-scala 0.4-SNAPSHOT
3070
- `libraryDependencies += "EPFL" %% "js-scala" % "0.4-SNAPSHOT"`
@@ -34,8 +74,14 @@
3474
3. Set the `-Yvirtualize` compiler option
3575
- `scalacOptions += "-Yvirtualize"`
3676

37-
### Further projects
77+
## Further projects
3878

3979
* [play-js-validation](http://github.com/js-scala/play-js-validation) uses this DSL to enable form validation code in Play 2.0 to be written once and checked on both client and server sides.
4080

4181
* [forest](http://github.com/js-scala/forest) uses this DSL to enable HTML templates to be written once and shared between client and server sides, both for initial rendering and automatic updating.
82+
83+
## Quick start
84+
85+
First, be sure to be familiar with [LMS tutorials](http://scala-lms.github.io/tutorials).
86+
87+
(More to come!)

core/src/main/scala/scala/js/language/JS.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,7 @@ package scala.js.language
55
*/
66
trait JSBase extends JsScalaBase with Dynamics with Arrays with RegExps with OptionOps
77

8+
/**
9+
* Same as [[scala.js.language.JSBase]] but with implicit conversions automatically lifting values to `Rep` values when needed.
10+
*/
811
trait JS extends JSBase with JsScala

core/src/main/scala/scala/js/language/JsScala.scala

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,15 @@ import scala.virtualization.lms.common._
55
/**
66
* Trait aggregating several DSLs providing a base language for Web programming with the ability to share code
77
* between server and client sides.
8+
*
9+
* Integrates most of the language units defined by LMS.
810
*/
911
trait JsScalaBase extends Base with NumericOps with OrderingOps with Equal with IfThenElse
1012
with While with BooleanOps with StringOps with Variables with ListOps with ObjectOps
1113
with TupledFunctions with Structs with PrimitiveOps with MiscOps with TupleOps with ListOps2
1214

15+
/**
16+
* Same as [[scala.js.language.JsScala]] but with implicit conversions automatically lifting values to `Rep` values when needed.
17+
*/
1318
trait JsScala extends JsScalaBase with LiftVariables with LiftEquals with LiftNumeric with LiftString with LiftBoolean
1419
with LiftPrimitives

core/src/main/scala/scala/js/language/ListOps2.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ package scala.js.language
22

33
import scala.virtualization.lms.common.Base
44

5+
/**
6+
* Add more operations on lists than those provided by LMS.
7+
*/
58
trait ListOps2 extends Base {
69
implicit class ListOps2[A](l: Rep[List[A]]) {
710
def mkString2(sep: Rep[String]) = list_mkString2(l, sep)

core/src/main/scala/scala/js/language/OptionOps.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ package scala.js.language
22

33
import scala.virtualization.lms.common.Base
44

5+
/**
6+
* Language unit for optional values manipulation (similar to [[scala.Option]] type).
7+
*/
58
trait OptionOps extends Base {
69

710
val none: Rep[None.type]

core/src/main/scala/scala/js/language/dom/Browser.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ package scala.js.language.dom
22

33
import scala.virtualization.lms.common.Base
44

5+
/**
6+
* Web browser related API.
7+
*/
58
trait Browser extends Base with SelectorOps with EventOps with ElementOps {
69

710
trait Window extends EventTarget
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
package scala.js.language.dom
22

3+
/**
4+
* Aggregates all the DOM API.
5+
*/
36
trait Dom extends Core with ElementOps with EventOps with NodeListOps with Browser with SelectorOps

core/src/main/scala/scala/js/language/dom/ElementOps.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ package scala.js.language.dom
22

33
import scala.virtualization.lms.common.Base
44

5+
/**
6+
* [[org.w3c.dom.Element]] manipulation.
7+
*/
58
trait ElementOps extends Base with EventOps with SelectorOps with Core {
69

710
trait CSSStyleDeclaration

core/src/main/scala/scala/js/language/dom/EventOps.scala

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
package scala.js.language.dom
22

33
import scala.virtualization.lms.common.Base
4-
4+
5+
/**
6+
* [[org.w3c.dom.events.Event]] manipulation.
7+
*/
58
trait EventOps extends Base {
69

710
trait EventTarget

core/src/main/scala/scala/js/language/dom/NodeListOps.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ package scala.js.language.dom
22

33
import scala.virtualization.lms.common.Base
44

5+
/**
6+
* [[org.w3c.dom.NodeList]] manipulation.
7+
*/
58
trait NodeListOps extends Base {
69

710
class NodeList[A]

0 commit comments

Comments
 (0)