js2 0.1.8 → 0.3.0.pre5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/bin/js2 +9 -126
- data/bin/js2-ruby +13 -0
- data/lib/js2/command.rb +16 -0
- data/lib/js2/context.rb +35 -0
- data/lib/js2/fs.rb +56 -0
- data/lib/js2/js2.js +1265 -0
- data/lib/js2/rack.rb +35 -0
- data/lib/js2.rb +19 -30
- metadata +28 -91
- data/CHANGELOG +0 -17
- data/Manifest +0 -45
- data/README.md +0 -75
- data/Rakefile +0 -28
- data/config/js2.yml +0 -2
- data/js2.gemspec +0 -36
- data/lib/js2/parser/haml.rb +0 -145
- data/lib/js2/parser/haml_engine.rb +0 -19
- data/lib/js2/parser/lexer.rb +0 -37
- data/lib/js2/parser/tokenizer.rb +0 -3551
- data/lib/js2/ragel/helper.rb +0 -117
- data/lib/js2/ragel/tokenizer.rl +0 -561
- data/lib/js2/ragel/tokenizer.rl.erb +0 -347
- data/lib/js2/standard/class_node.rb +0 -0
- data/lib/js2/standard/factory.rb +0 -289
- data/lib/js2/standard/node.rb +0 -75
- data/lib/js2/util/compilation.rb +0 -77
- data/lib/js2/util/config.rb +0 -84
- data/lib/js2/util/exec.rb +0 -34
- data/lib/js2/util/file_handler.rb +0 -73
- data/lib/js2/util/haml_filter.rb +0 -13
- data/lib/js2/util/jamis.rb +0 -600
- data/lib/js2/util/js2bootstrap.js2 +0 -448
- data/lib/js2/util/processor.rb +0 -88
- data/lib/js2/util/rdoc.rb +0 -37
- data/lib/js2/util/sel_decorator.rb +0 -155
- data/test/compiled/bar.js +0 -3
- data/test/compiled/basic.comp.js +0 -31
- data/test/compiled/basic.js +0 -27
- data/test/compiled/foo.js +0 -3
- data/test/fixtures/bar.js2 +0 -3
- data/test/fixtures/basic.js2 +0 -27
- data/test/fixtures/basic.js2.haml +0 -4
- data/test/fixtures/basic.js2.yml +0 -5
- data/test/fixtures/curry.js2 +0 -5
- data/test/fixtures/foo.js2 +0 -3
- data/test/fixtures/member.js2 +0 -14
- data/test/fixtures/private.js2 +0 -5
- data/test/fixtures/property.js2 +0 -4
- data/test/test_helper.rb +0 -25
- data/test/test_js2.rb +0 -43
- data/wiki/features.md +0 -73
- data/wiki/installation.md +0 -13
data/test/compiled/bar.js
DELETED
data/test/compiled/basic.comp.js
DELETED
@@ -1,31 +0,0 @@
|
|
1
|
-
|
2
|
-
/*
|
3
|
-
* Comments
|
4
|
-
* This is a comment
|
5
|
-
*/
|
6
|
-
JS2.OO.createClass("Test.Foo"); (function (K,Package) {var self=K; var _super=JS2.OO['super'];
|
7
|
-
K.oo('accessor', [ 'testAcc' ]);
|
8
|
-
K.oo('property', [ 'testProp' ]);
|
9
|
-
|
10
|
-
/*
|
11
|
-
* hello
|
12
|
-
*/
|
13
|
-
|
14
|
-
K.oo('method', "testFunct", function () {
|
15
|
-
|
16
|
-
});
|
17
|
-
|
18
|
-
K.oo('method', "testForeach", function () {
|
19
|
-
for (var i=0,ele,i__arr=elements,i__len=i__arr.length; (ele=i__arr[i]) || i<i__len; i++){
|
20
|
-
for (var i=0,yo,i__arr=yos,i__len=i__arr.length; (yo=i__arr[i]) || i<i__len; i++){
|
21
|
-
|
22
|
-
}
|
23
|
-
|
24
|
-
}
|
25
|
-
});
|
26
|
-
|
27
|
-
})(Test.Foo, Test);Test.Foo.oo('setHTMLCache', {"main":function(){return "<div class='hello'>world</div>"}});JS2.OO.createClass("Bar"); (function (K,Package) {var self=K; var _super=JS2.OO['super'];
|
28
|
-
|
29
|
-
})(Bar, null);JS2.OO.createClass("Foo"); (function (K,Package) {var self=K; var _super=JS2.OO['super'];
|
30
|
-
|
31
|
-
})(Foo, null);
|
data/test/compiled/basic.js
DELETED
@@ -1,27 +0,0 @@
|
|
1
|
-
|
2
|
-
/*
|
3
|
-
* Comments
|
4
|
-
* This is a comment
|
5
|
-
*/
|
6
|
-
JS2.OO.createClass("Test.Foo"); (function (K,Package) {var self=K; var _super=JS2.OO['super'];
|
7
|
-
K.oo('accessor', [ 'testAcc' ]);
|
8
|
-
K.oo('property', [ 'testProp' ]);
|
9
|
-
|
10
|
-
/*
|
11
|
-
* hello
|
12
|
-
*/
|
13
|
-
|
14
|
-
K.oo('method', "testFunct", function () {
|
15
|
-
|
16
|
-
});
|
17
|
-
|
18
|
-
K.oo('method', "testForeach", function () {
|
19
|
-
for (var i=0,ele,i__arr=elements,i__len=i__arr.length; (ele=i__arr[i]) || i<i__len; i++){
|
20
|
-
for (var i=0,yo,i__arr=yos,i__len=i__arr.length; (yo=i__arr[i]) || i<i__len; i++){
|
21
|
-
|
22
|
-
}
|
23
|
-
|
24
|
-
}
|
25
|
-
});
|
26
|
-
|
27
|
-
})(Test.Foo, Test);Test.Foo.oo('setHTMLCache', {"main":function(){return "<div class='hello'>world</div>"}});
|
data/test/compiled/foo.js
DELETED
data/test/fixtures/bar.js2
DELETED
data/test/fixtures/basic.js2
DELETED
@@ -1,27 +0,0 @@
|
|
1
|
-
|
2
|
-
/*
|
3
|
-
* Comments
|
4
|
-
* This is a comment
|
5
|
-
*/
|
6
|
-
class Test.Foo {
|
7
|
-
accessor testAcc;
|
8
|
-
property testProp;
|
9
|
-
|
10
|
-
/*
|
11
|
-
* hello
|
12
|
-
*/
|
13
|
-
|
14
|
-
function testFunct () {
|
15
|
-
|
16
|
-
}
|
17
|
-
|
18
|
-
function testForeach () {
|
19
|
-
foreach (var ele:i in elements) {
|
20
|
-
foreach (var yo:i in yos) {
|
21
|
-
|
22
|
-
}
|
23
|
-
|
24
|
-
}
|
25
|
-
}
|
26
|
-
|
27
|
-
}
|
data/test/fixtures/basic.js2.yml
DELETED
data/test/fixtures/curry.js2
DELETED
data/test/fixtures/foo.js2
DELETED
data/test/fixtures/member.js2
DELETED
@@ -1,14 +0,0 @@
|
|
1
|
-
class TestMember {
|
2
|
-
|
3
|
-
var WIDTH = 84;
|
4
|
-
var MENU_ACTIONS = [ 'sortData', 'sortData', 'hideColumn' ];
|
5
|
-
|
6
|
-
var arr = [ 'hello', 'world' ];
|
7
|
-
var one, two, three;
|
8
|
-
var foo = {};
|
9
|
-
var bar;
|
10
|
-
var foo1 = 'hello';
|
11
|
-
var bar1 = {
|
12
|
-
hello: "world"
|
13
|
-
};
|
14
|
-
}
|
data/test/fixtures/private.js2
DELETED
data/test/fixtures/property.js2
DELETED
data/test/test_helper.rb
DELETED
@@ -1,25 +0,0 @@
|
|
1
|
-
require 'stringio'
|
2
|
-
require 'test/unit'
|
3
|
-
require File.dirname(__FILE__) + '/../lib/js2'
|
4
|
-
JS2_TEST_DIR = File.dirname(__FILE__)
|
5
|
-
|
6
|
-
class Test::Unit::TestCase
|
7
|
-
def js2_fixture (name)
|
8
|
-
return JS2_TEST_DIR + "/fixtures/#{name}.js2"
|
9
|
-
end
|
10
|
-
|
11
|
-
def js_read_fixture (name)
|
12
|
-
return File.read(JS2_TEST_DIR + "/fixtures/#{name}.js").chomp
|
13
|
-
end
|
14
|
-
|
15
|
-
def compare_dir (dir1, dir2)
|
16
|
-
files1 = Dir["#{dir1}/*.js"]
|
17
|
-
|
18
|
-
files1.each do |file|
|
19
|
-
content1 = File.read(file)
|
20
|
-
file2 = file.sub(/^#{dir1}/, dir2)
|
21
|
-
content2 = File.read(file2)
|
22
|
-
assert_equal(content1.chomp, content2.chomp, "Comparing #{file} and #{file2}")
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
data/test/test_js2.rb
DELETED
@@ -1,43 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/test_helper.rb'
|
2
|
-
|
3
|
-
class TestJs2 < Test::Unit::TestCase
|
4
|
-
|
5
|
-
def setup
|
6
|
-
@lexer = JS2::Parser::Lexer.new
|
7
|
-
@factory = JS2::Standard::Factory.new
|
8
|
-
end
|
9
|
-
|
10
|
-
def test_processor
|
11
|
-
|
12
|
-
config = JS2::Util::Config.new
|
13
|
-
fh = config.file_handler
|
14
|
-
fh.js2_dir = './test/fixtures'
|
15
|
-
fh.out_dir = './test/out'
|
16
|
-
fh.haml_dir = './test/fixtures'
|
17
|
-
|
18
|
-
system("rm -rf #{fh.out_dir}")
|
19
|
-
|
20
|
-
processor = JS2::Util::Processor.new(config)
|
21
|
-
ret1 = processor.process!
|
22
|
-
ret2 = processor.process!
|
23
|
-
assert_equal(ret2[:changed].any?, false)
|
24
|
-
|
25
|
-
compare_dir(fh.out_dir, './test/compiled')
|
26
|
-
end
|
27
|
-
|
28
|
-
def test_rdoc
|
29
|
-
|
30
|
-
config = JS2::Util::Config.new
|
31
|
-
fh = config.file_handler
|
32
|
-
fh.js2_dir = './test/fixtures'
|
33
|
-
fh.out_dir = './test/out'
|
34
|
-
fh.haml_dir = './test/fixtures'
|
35
|
-
fh.doc_dir = './test/doc'
|
36
|
-
system("rm -rf #{fh.out_dir}")
|
37
|
-
|
38
|
-
processor = JS2::Util::Processor.new(config)
|
39
|
-
ret = processor.process!
|
40
|
-
JS2::Util::Rdoc.build(ret[:pages], fh)
|
41
|
-
end
|
42
|
-
|
43
|
-
end
|
data/wiki/features.md
DELETED
@@ -1,73 +0,0 @@
|
|
1
|
-
[JS2](http://github.com/jeffsu/js2) - Friendly Cross Browser Object Oriented Javascript
|
2
|
-
=======================================================================================
|
3
|
-
|
4
|
-
Classes and Methods
|
5
|
-
--------------------
|
6
|
-
To create a class, use the "class" keyword followed by matching curly braces. If the class
|
7
|
-
has an "initialize" method defined, it will run that right after an instance is created.
|
8
|
-
Getters and setters can be created by using the "property" keyword.
|
9
|
-
|
10
|
-
|
11
|
-
Here is an example of a class:
|
12
|
-
|
13
|
-
class Person {
|
14
|
-
// creates getName() and setName(name) methods
|
15
|
-
property name;
|
16
|
-
|
17
|
-
// creates getAge() and setAge(age) methods
|
18
|
-
property age;
|
19
|
-
|
20
|
-
// called after new Person(age) is called
|
21
|
-
function initialize(age) {
|
22
|
-
this.age = age;
|
23
|
-
}
|
24
|
-
}
|
25
|
-
|
26
|
-
var p = new Person(14);
|
27
|
-
p.setName("Jeff");
|
28
|
-
var age = p.getAge(); // 14
|
29
|
-
|
30
|
-
Modules/Mixins/Multiple Inheritance
|
31
|
-
-----------------------------------
|
32
|
-
JS2 uses a Ruby-inspired methodology for multiple inheritance. Here is an example
|
33
|
-
of how it works:
|
34
|
-
|
35
|
-
module Flyable {
|
36
|
-
function fly() {
|
37
|
-
alert("I believe I can fly!");
|
38
|
-
}
|
39
|
-
}
|
40
|
-
|
41
|
-
class Duck {
|
42
|
-
include Flyable;
|
43
|
-
}
|
44
|
-
|
45
|
-
var duck = new Duck();
|
46
|
-
duck.fly();
|
47
|
-
|
48
|
-
Syntactic Sugar
|
49
|
-
---------------
|
50
|
-
|
51
|
-
*Foreach*: iterating through an array without having to manually create temp variables:
|
52
|
-
|
53
|
-
var items = [ 'foo', 'bar', 'baz' ]
|
54
|
-
foreach (var item in items) {
|
55
|
-
alert(item);
|
56
|
-
}
|
57
|
-
|
58
|
-
// with index
|
59
|
-
foreach (var item:i in items) {
|
60
|
-
alert(i + ':' + item);
|
61
|
-
}
|
62
|
-
|
63
|
-
*Currying*: tightly scoped anonymous functions to prevent memory leaks
|
64
|
-
|
65
|
-
var bigData = getBigData();
|
66
|
-
var inScope = getSmallData();
|
67
|
-
|
68
|
-
element.onClick = curry (evt) with (inScope, this) {
|
69
|
-
alert("curry" + inScope);
|
70
|
-
// variable "self" is available as the "this" in the outer scope
|
71
|
-
}
|
72
|
-
|
73
|
-
|
data/wiki/installation.md
DELETED
@@ -1,13 +0,0 @@
|
|
1
|
-
[JS2](http://github.com/jeffsu/js2) - Installation
|
2
|
-
=======================================================================================
|
3
|
-
|
4
|
-
1. Install Ruby Gems
|
5
|
-
2. Install js2
|
6
|
-
gem install js2
|
7
|
-
|
8
|
-
You should now have the js2 executable in your path. Running this command should bring up the
|
9
|
-
help page.
|
10
|
-
|
11
|
-
js2
|
12
|
-
|
13
|
-
|