js2 0.1.8 → 0.3.0.pre5
Sign up to get free protection for your applications and to get access to all the features.
- 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/lib/js2/rack.rb
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
|
3
|
+
module JS2
|
4
|
+
# this is a hack for now until I can get v8 stable
|
5
|
+
class Rack
|
6
|
+
ROOT = File.expand_path(Dir.getwd)
|
7
|
+
|
8
|
+
DEFAULT_CONFIG = {
|
9
|
+
'in_dir' => "#{ROOT}/app/js2",
|
10
|
+
'out_dir' => "#{ROOT}/public/javascripts",
|
11
|
+
'bin' => (`which js2`.chomp rescue nil)
|
12
|
+
}
|
13
|
+
|
14
|
+
def initialize(app)
|
15
|
+
@app = app
|
16
|
+
|
17
|
+
@config = YAML.read_file(ROOT + '/config/js2.yml') rescue DEFAULT_CONFIG
|
18
|
+
|
19
|
+
@in_dir = @config['in_dir']
|
20
|
+
@out_dir = @config['out_dir']
|
21
|
+
@bin = @config['bin']
|
22
|
+
|
23
|
+
@valid = @in_dir && @out_dir && !@bin.blank?
|
24
|
+
|
25
|
+
unless @valid
|
26
|
+
puts "JS2 is not configured properly"
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def call(env)
|
31
|
+
`#{@bin} compile -r #{@in_dir} #{@out_dir}` if @valid
|
32
|
+
@app.call(env)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
data/lib/js2.rb
CHANGED
@@ -1,36 +1,25 @@
|
|
1
|
-
|
1
|
+
begin
|
2
|
+
require 'v8'
|
3
|
+
JSVM = :v8
|
4
|
+
rescue
|
5
|
+
begin
|
6
|
+
require 'rhino'
|
7
|
+
JSVM = :rhino
|
8
|
+
rescue
|
9
|
+
raise "Please install a javascript engine gem: rubyracer or rubyrhino"
|
10
|
+
end
|
2
11
|
end
|
3
12
|
|
4
|
-
module JS2::Parser
|
5
|
-
end
|
6
13
|
|
7
|
-
module JS2
|
8
|
-
|
9
|
-
|
10
|
-
|
14
|
+
module JS2
|
15
|
+
Engine = JSVM == :v8 ? V8::Context : Rhino::Context
|
16
|
+
def self.init_rails
|
17
|
+
dirname = File.dirname(File.expand_path('', __FILE__))
|
18
|
+
require "#{dirname}/js2/rails"
|
19
|
+
end
|
11
20
|
end
|
12
21
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
# compiling stuff
|
17
|
-
require "#{dir}/js2/parser/lexer"
|
18
|
-
require "#{dir}/js2/parser/tokenizer"
|
19
|
-
require "#{dir}/js2/parser/haml_engine"
|
20
|
-
require "#{dir}/js2/parser/haml"
|
21
|
-
|
22
|
-
# standard suite
|
23
|
-
require "#{dir}/js2/standard/node"
|
24
|
-
require "#{dir}/js2/standard/class_node"
|
25
|
-
require "#{dir}/js2/standard/factory"
|
26
|
-
|
27
|
-
# util stuff
|
28
|
-
require "#{dir}/js2/util/processor"
|
29
|
-
require "#{dir}/js2/util/file_handler"
|
30
|
-
require "#{dir}/js2/util/config"
|
31
|
-
require "#{dir}/js2/util/compilation"
|
32
|
-
require "#{dir}/js2/util/rdoc"
|
33
|
-
|
34
|
-
if defined?(Haml)
|
35
|
-
require "#{dir}/js2/util/haml_filter"
|
22
|
+
dirname = File.dirname(File.expand_path('', __FILE__))
|
23
|
+
%W{ context fs command rack }.each do |f|
|
24
|
+
require "#{dirname}/js2/#{f}"
|
36
25
|
end
|
metadata
CHANGED
@@ -1,12 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: js2
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
prerelease:
|
4
|
+
prerelease: true
|
5
5
|
segments:
|
6
6
|
- 0
|
7
|
-
-
|
8
|
-
-
|
9
|
-
|
7
|
+
- 3
|
8
|
+
- 0
|
9
|
+
- pre5
|
10
|
+
version: 0.3.0.pre5
|
10
11
|
platform: ruby
|
11
12
|
authors:
|
12
13
|
- Jeff Su
|
@@ -14,11 +15,11 @@ autorequire:
|
|
14
15
|
bindir: bin
|
15
16
|
cert_chain: []
|
16
17
|
|
17
|
-
date:
|
18
|
+
date: 2011-03-05 00:00:00 -08:00
|
18
19
|
default_executable:
|
19
20
|
dependencies:
|
20
21
|
- !ruby/object:Gem::Dependency
|
21
|
-
name:
|
22
|
+
name: therubyracer
|
22
23
|
prerelease: false
|
23
24
|
requirement: &id001 !ruby/object:Gem::Requirement
|
24
25
|
none: false
|
@@ -30,95 +31,31 @@ dependencies:
|
|
30
31
|
version: "0"
|
31
32
|
type: :runtime
|
32
33
|
version_requirements: *id001
|
33
|
-
description:
|
34
|
+
description: A superset of the Javascript language to make development easier.
|
34
35
|
email: me@jeffsu.com
|
35
36
|
executables:
|
37
|
+
- js2-ruby
|
36
38
|
- js2
|
37
39
|
extensions: []
|
38
40
|
|
39
|
-
extra_rdoc_files:
|
40
|
-
|
41
|
-
- CHANGELOG
|
42
|
-
- bin/js2
|
43
|
-
- lib/js2.rb
|
44
|
-
- lib/js2/parser/haml.rb
|
45
|
-
- lib/js2/parser/haml_engine.rb
|
46
|
-
- lib/js2/parser/lexer.rb
|
47
|
-
- lib/js2/parser/tokenizer.rb
|
48
|
-
- lib/js2/ragel/helper.rb
|
49
|
-
- lib/js2/ragel/tokenizer.rl
|
50
|
-
- lib/js2/ragel/tokenizer.rl.erb
|
51
|
-
- lib/js2/standard/class_node.rb
|
52
|
-
- lib/js2/standard/factory.rb
|
53
|
-
- lib/js2/standard/node.rb
|
54
|
-
- lib/js2/util/compilation.rb
|
55
|
-
- lib/js2/util/config.rb
|
56
|
-
- lib/js2/util/exec.rb
|
57
|
-
- lib/js2/util/file_handler.rb
|
58
|
-
- lib/js2/util/js2bootstrap.js2
|
59
|
-
- lib/js2/util/processor.rb
|
60
|
-
- lib/js2/util/rdoc.rb
|
61
|
-
- lib/js2/util/sel_decorator.rb
|
62
|
-
- lib/js2/util/haml_filter.rb
|
63
|
-
- lib/js2/util/jamis.rb
|
41
|
+
extra_rdoc_files: []
|
42
|
+
|
64
43
|
files:
|
65
|
-
- Manifest
|
66
|
-
- README.md
|
67
|
-
- Rakefile
|
68
|
-
- CHANGELOG
|
69
44
|
- bin/js2
|
70
|
-
-
|
71
|
-
- js2.
|
45
|
+
- bin/js2-ruby
|
46
|
+
- lib/js2/command.rb
|
47
|
+
- lib/js2/context.rb
|
48
|
+
- lib/js2/fs.rb
|
49
|
+
- lib/js2/rack.rb
|
72
50
|
- lib/js2.rb
|
73
|
-
- lib/js2/
|
74
|
-
- lib/js2/parser/haml_engine.rb
|
75
|
-
- lib/js2/parser/lexer.rb
|
76
|
-
- lib/js2/parser/tokenizer.rb
|
77
|
-
- lib/js2/ragel/helper.rb
|
78
|
-
- lib/js2/ragel/tokenizer.rl
|
79
|
-
- lib/js2/ragel/tokenizer.rl.erb
|
80
|
-
- lib/js2/standard/class_node.rb
|
81
|
-
- lib/js2/standard/factory.rb
|
82
|
-
- lib/js2/standard/node.rb
|
83
|
-
- lib/js2/util/compilation.rb
|
84
|
-
- lib/js2/util/config.rb
|
85
|
-
- lib/js2/util/exec.rb
|
86
|
-
- lib/js2/util/file_handler.rb
|
87
|
-
- lib/js2/util/js2bootstrap.js2
|
88
|
-
- lib/js2/util/processor.rb
|
89
|
-
- lib/js2/util/rdoc.rb
|
90
|
-
- lib/js2/util/sel_decorator.rb
|
91
|
-
- lib/js2/util/haml_filter.rb
|
92
|
-
- lib/js2/util/jamis.rb
|
93
|
-
- test/compiled/bar.js
|
94
|
-
- test/compiled/basic.comp.js
|
95
|
-
- test/compiled/basic.js
|
96
|
-
- test/compiled/foo.js
|
97
|
-
- test/fixtures/bar.js2
|
98
|
-
- test/fixtures/basic.js2
|
99
|
-
- test/fixtures/basic.js2.haml
|
100
|
-
- test/fixtures/basic.js2.yml
|
101
|
-
- test/fixtures/curry.js2
|
102
|
-
- test/fixtures/foo.js2
|
103
|
-
- test/fixtures/member.js2
|
104
|
-
- test/fixtures/private.js2
|
105
|
-
- test/fixtures/property.js2
|
106
|
-
- test/test_helper.rb
|
107
|
-
- test/test_js2.rb
|
108
|
-
- wiki/features.md
|
109
|
-
- wiki/installation.md
|
51
|
+
- lib/js2/js2.js
|
110
52
|
has_rdoc: true
|
111
|
-
homepage: http://github.com
|
53
|
+
homepage: http://jeffsu.github.com
|
112
54
|
licenses: []
|
113
55
|
|
114
56
|
post_install_message:
|
115
|
-
rdoc_options:
|
116
|
-
|
117
|
-
- --inline-source
|
118
|
-
- --title
|
119
|
-
- Js2
|
120
|
-
- --main
|
121
|
-
- README.md
|
57
|
+
rdoc_options: []
|
58
|
+
|
122
59
|
require_paths:
|
123
60
|
- lib
|
124
61
|
required_ruby_version: !ruby/object:Gem::Requirement
|
@@ -132,19 +69,19 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
132
69
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
133
70
|
none: false
|
134
71
|
requirements:
|
135
|
-
- - "
|
72
|
+
- - ">"
|
136
73
|
- !ruby/object:Gem::Version
|
137
74
|
segments:
|
138
75
|
- 1
|
139
|
-
-
|
140
|
-
|
76
|
+
- 3
|
77
|
+
- 1
|
78
|
+
version: 1.3.1
|
141
79
|
requirements: []
|
142
80
|
|
143
|
-
rubyforge_project:
|
81
|
+
rubyforge_project:
|
144
82
|
rubygems_version: 1.3.7
|
145
83
|
signing_key:
|
146
84
|
specification_version: 3
|
147
|
-
summary:
|
148
|
-
test_files:
|
149
|
-
|
150
|
-
- test/test_helper.rb
|
85
|
+
summary: Javascript Syntactic Sugar
|
86
|
+
test_files: []
|
87
|
+
|
data/CHANGELOG
DELETED
@@ -1,17 +0,0 @@
|
|
1
|
-
## Version 0.1.8
|
2
|
-
* Adding JS2.Observable module to boostrap
|
3
|
-
* Fixed "STR2CSTR" bug when used in Ruby 1.9.x
|
4
|
-
|
5
|
-
## Version 0.1.7
|
6
|
-
* Support for Ruby 1.9.x
|
7
|
-
|
8
|
-
## Version 0.1.6
|
9
|
-
* Fixed RubyInline dependency
|
10
|
-
|
11
|
-
## Version 0.1.4
|
12
|
-
* Minor fix in doc directory
|
13
|
-
|
14
|
-
## Version 0.1.3
|
15
|
-
* Fixed "js2 rdoc" command
|
16
|
-
* Added jamis.rb to the Manifest
|
17
|
-
* Added javascript to rewrite rdoc to look more like javascript
|
data/Manifest
DELETED
@@ -1,45 +0,0 @@
|
|
1
|
-
Manifest
|
2
|
-
README.md
|
3
|
-
Rakefile
|
4
|
-
CHANGELOG
|
5
|
-
bin/js2
|
6
|
-
config/js2.yml
|
7
|
-
js2.gemspec
|
8
|
-
lib/js2.rb
|
9
|
-
lib/js2/parser/haml.rb
|
10
|
-
lib/js2/parser/haml_engine.rb
|
11
|
-
lib/js2/parser/lexer.rb
|
12
|
-
lib/js2/parser/tokenizer.rb
|
13
|
-
lib/js2/ragel/helper.rb
|
14
|
-
lib/js2/ragel/tokenizer.rl
|
15
|
-
lib/js2/ragel/tokenizer.rl.erb
|
16
|
-
lib/js2/standard/class_node.rb
|
17
|
-
lib/js2/standard/factory.rb
|
18
|
-
lib/js2/standard/node.rb
|
19
|
-
lib/js2/util/compilation.rb
|
20
|
-
lib/js2/util/config.rb
|
21
|
-
lib/js2/util/exec.rb
|
22
|
-
lib/js2/util/file_handler.rb
|
23
|
-
lib/js2/util/js2bootstrap.js2
|
24
|
-
lib/js2/util/processor.rb
|
25
|
-
lib/js2/util/rdoc.rb
|
26
|
-
lib/js2/util/sel_decorator.rb
|
27
|
-
lib/js2/util/haml_filter.rb
|
28
|
-
lib/js2/util/jamis.rb
|
29
|
-
test/compiled/bar.js
|
30
|
-
test/compiled/basic.comp.js
|
31
|
-
test/compiled/basic.js
|
32
|
-
test/compiled/foo.js
|
33
|
-
test/fixtures/bar.js2
|
34
|
-
test/fixtures/basic.js2
|
35
|
-
test/fixtures/basic.js2.haml
|
36
|
-
test/fixtures/basic.js2.yml
|
37
|
-
test/fixtures/curry.js2
|
38
|
-
test/fixtures/foo.js2
|
39
|
-
test/fixtures/member.js2
|
40
|
-
test/fixtures/private.js2
|
41
|
-
test/fixtures/property.js2
|
42
|
-
test/test_helper.rb
|
43
|
-
test/test_js2.rb
|
44
|
-
wiki/features.md
|
45
|
-
wiki/installation.md
|
data/README.md
DELETED
@@ -1,75 +0,0 @@
|
|
1
|
-
[JS2](http://github.com/jeffsu/js2) - Friendly Cross Browser Object Oriented Javascript
|
2
|
-
=======================================================================================
|
3
|
-
|
4
|
-
JS2 is a way to write classes in a more familiar way for programmers who are used to syntax in languages such as: Java, Ruby, C++, etc...
|
5
|
-
The main motivation is to provide a clean and a less verbose syntax for creating classes, inheritance and modules in Javascript. JS2 plays
|
6
|
-
nicely with most of the popular frameworks including: jQuery and prototype. It also provides some syntactic sugar on the repetative aspects
|
7
|
-
of Javascript.
|
8
|
-
|
9
|
-
Sample Syntax:
|
10
|
-
class Rectangle {
|
11
|
-
property height;
|
12
|
-
property width;
|
13
|
-
|
14
|
-
function area () {
|
15
|
-
return this.height * this.width;
|
16
|
-
}
|
17
|
-
}
|
18
|
-
|
19
|
-
class Square extends Rectangle {
|
20
|
-
function area () {
|
21
|
-
return this.width * this.width;
|
22
|
-
}
|
23
|
-
}
|
24
|
-
|
25
|
-
var s = new Square();
|
26
|
-
|
27
|
-
* [Installation](http://github.com/jeffsu/js2/blob/master/wiki/installation.md)
|
28
|
-
* [Language Features and Examples](http://github.com/jeffsu/js2/blob/master/wiki/features.md)
|
29
|
-
* [Compiler Features](http://github.com/jeffsu/js2/blob/master/wiki/compiler.md)
|
30
|
-
* [Source](http://github.com/jeffsu/js2)
|
31
|
-
|
32
|
-
Things You need to run JS2
|
33
|
-
--------------------------
|
34
|
-
* Ruby - language used to parse js2 and generate javascript
|
35
|
-
* Ruby Gems - ruby package manager
|
36
|
-
* js2
|
37
|
-
* RubyInline
|
38
|
-
* haml (optional)
|
39
|
-
|
40
|
-
Quick Start Guide
|
41
|
-
-----------------
|
42
|
-
Create a js2 file (foo.js2):
|
43
|
-
class Person {
|
44
|
-
function speak() {
|
45
|
-
alert("Hello! I'm a person!");
|
46
|
-
}
|
47
|
-
|
48
|
-
function walk() {
|
49
|
-
alert("Walking!");
|
50
|
-
}
|
51
|
-
}
|
52
|
-
|
53
|
-
class Student extends Person {
|
54
|
-
function speak() {
|
55
|
-
alert("Hello, I'm a student!");
|
56
|
-
}
|
57
|
-
}
|
58
|
-
|
59
|
-
var person = new Person();
|
60
|
-
var student = new Student();
|
61
|
-
|
62
|
-
person.speak();
|
63
|
-
student.speak();
|
64
|
-
person.walk();
|
65
|
-
student.walk();
|
66
|
-
|
67
|
-
Run js2 in the same directory
|
68
|
-
js2 compile
|
69
|
-
|
70
|
-
You should now see these files in that directory:
|
71
|
-
* foo.js2
|
72
|
-
* foo.js
|
73
|
-
* js2bootstrap.js
|
74
|
-
|
75
|
-
Include these js2bootstrap.js and foo.js (make sure js2bootstrap.js is included first) in your html page.
|
data/Rakefile
DELETED
@@ -1,28 +0,0 @@
|
|
1
|
-
require 'rubygems'
|
2
|
-
require 'rake'
|
3
|
-
require 'echoe'
|
4
|
-
|
5
|
-
JS2_VERSION = '0.1.8'
|
6
|
-
Echoe.new('js2', JS2_VERSION) do |p|
|
7
|
-
p.summary = "Cross-Browser Object Oriented Javascript Compiler"
|
8
|
-
p.description = "Cross-Browser Object Oriented Javascript Compiler"
|
9
|
-
p.url = "http://github.com/jeffsu/js2"
|
10
|
-
p.author = "Jeff Su"
|
11
|
-
p.email = "me@jeffsu.com"
|
12
|
-
p.ignore_pattern = ["tmp/*", "script/*", "test/out" ]
|
13
|
-
p.development_dependencies = []
|
14
|
-
|
15
|
-
p.runtime_dependencies = ["RubyInline"]
|
16
|
-
end
|
17
|
-
|
18
|
-
namespace :js2 do
|
19
|
-
task :compile do
|
20
|
-
system("cd ./lib/js2/ragel/; ruby helper.rb; ragel -C tokenizer.rl; mv tokenizer.c ../parser/tokenizer.rb")
|
21
|
-
end
|
22
|
-
|
23
|
-
task :install do
|
24
|
-
Rake::Task['gem'].invoke
|
25
|
-
system("sudo gem install ./pkg/js2-#{JS2_VERSION}.gem")
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
data/config/js2.yml
DELETED
data/js2.gemspec
DELETED
@@ -1,36 +0,0 @@
|
|
1
|
-
# -*- encoding: utf-8 -*-
|
2
|
-
|
3
|
-
Gem::Specification.new do |s|
|
4
|
-
s.name = %q{js2}
|
5
|
-
s.version = "0.1.8"
|
6
|
-
|
7
|
-
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
|
8
|
-
s.authors = ["Jeff Su"]
|
9
|
-
s.date = %q{2010-10-21}
|
10
|
-
s.default_executable = %q{js2}
|
11
|
-
s.description = %q{Cross-Browser Object Oriented Javascript Compiler}
|
12
|
-
s.email = %q{me@jeffsu.com}
|
13
|
-
s.executables = ["js2"]
|
14
|
-
s.extra_rdoc_files = ["README.md", "CHANGELOG", "bin/js2", "lib/js2.rb", "lib/js2/parser/haml.rb", "lib/js2/parser/haml_engine.rb", "lib/js2/parser/lexer.rb", "lib/js2/parser/tokenizer.rb", "lib/js2/ragel/helper.rb", "lib/js2/ragel/tokenizer.rl", "lib/js2/ragel/tokenizer.rl.erb", "lib/js2/standard/class_node.rb", "lib/js2/standard/factory.rb", "lib/js2/standard/node.rb", "lib/js2/util/compilation.rb", "lib/js2/util/config.rb", "lib/js2/util/exec.rb", "lib/js2/util/file_handler.rb", "lib/js2/util/js2bootstrap.js2", "lib/js2/util/processor.rb", "lib/js2/util/rdoc.rb", "lib/js2/util/sel_decorator.rb", "lib/js2/util/haml_filter.rb", "lib/js2/util/jamis.rb"]
|
15
|
-
s.files = ["Manifest", "README.md", "Rakefile", "CHANGELOG", "bin/js2", "config/js2.yml", "js2.gemspec", "lib/js2.rb", "lib/js2/parser/haml.rb", "lib/js2/parser/haml_engine.rb", "lib/js2/parser/lexer.rb", "lib/js2/parser/tokenizer.rb", "lib/js2/ragel/helper.rb", "lib/js2/ragel/tokenizer.rl", "lib/js2/ragel/tokenizer.rl.erb", "lib/js2/standard/class_node.rb", "lib/js2/standard/factory.rb", "lib/js2/standard/node.rb", "lib/js2/util/compilation.rb", "lib/js2/util/config.rb", "lib/js2/util/exec.rb", "lib/js2/util/file_handler.rb", "lib/js2/util/js2bootstrap.js2", "lib/js2/util/processor.rb", "lib/js2/util/rdoc.rb", "lib/js2/util/sel_decorator.rb", "lib/js2/util/haml_filter.rb", "lib/js2/util/jamis.rb", "test/compiled/bar.js", "test/compiled/basic.comp.js", "test/compiled/basic.js", "test/compiled/foo.js", "test/fixtures/bar.js2", "test/fixtures/basic.js2", "test/fixtures/basic.js2.haml", "test/fixtures/basic.js2.yml", "test/fixtures/curry.js2", "test/fixtures/foo.js2", "test/fixtures/member.js2", "test/fixtures/private.js2", "test/fixtures/property.js2", "test/test_helper.rb", "test/test_js2.rb", "wiki/features.md", "wiki/installation.md"]
|
16
|
-
s.homepage = %q{http://github.com/jeffsu/js2}
|
17
|
-
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Js2", "--main", "README.md"]
|
18
|
-
s.require_paths = ["lib"]
|
19
|
-
s.rubyforge_project = %q{js2}
|
20
|
-
s.rubygems_version = %q{1.3.7}
|
21
|
-
s.summary = %q{Cross-Browser Object Oriented Javascript Compiler}
|
22
|
-
s.test_files = ["test/test_js2.rb", "test/test_helper.rb"]
|
23
|
-
|
24
|
-
if s.respond_to? :specification_version then
|
25
|
-
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
26
|
-
s.specification_version = 3
|
27
|
-
|
28
|
-
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
29
|
-
s.add_runtime_dependency(%q<RubyInline>, [">= 0"])
|
30
|
-
else
|
31
|
-
s.add_dependency(%q<RubyInline>, [">= 0"])
|
32
|
-
end
|
33
|
-
else
|
34
|
-
s.add_dependency(%q<RubyInline>, [">= 0"])
|
35
|
-
end
|
36
|
-
end
|
data/lib/js2/parser/haml.rb
DELETED
@@ -1,145 +0,0 @@
|
|
1
|
-
begin
|
2
|
-
require 'rubygems'
|
3
|
-
require 'haml'
|
4
|
-
require 'erb'
|
5
|
-
require 'json'
|
6
|
-
|
7
|
-
class JS2::Parser::Haml
|
8
|
-
attr_accessor :vars
|
9
|
-
|
10
|
-
def initialize (haml_engine = nil, vars = nil)
|
11
|
-
@haml_engine = haml_engine || JS2::Parser::HamlEngine.new
|
12
|
-
@vars = vars || Hash.new
|
13
|
-
end
|
14
|
-
|
15
|
-
def parse_out_js (file)
|
16
|
-
padding = nil
|
17
|
-
js = []
|
18
|
-
|
19
|
-
File.read(file).split(/\r?\n/).each do |line|
|
20
|
-
if m = line.match(/^(\s*):js2/)
|
21
|
-
padding = m[1]
|
22
|
-
elsif padding
|
23
|
-
if m = line.match(/^#{padding}/)
|
24
|
-
js << line
|
25
|
-
elsif ! line.match(/^\s*$/)
|
26
|
-
padding = nil
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
return js.join("\n")
|
32
|
-
end
|
33
|
-
|
34
|
-
def parse (file)
|
35
|
-
erb = ERB.new(File.read(file))
|
36
|
-
str = erb.result(binding)
|
37
|
-
|
38
|
-
lines = str.split(/\r?\n/)
|
39
|
-
result = Hash.new
|
40
|
-
|
41
|
-
klass = Hash.new
|
42
|
-
key = nil
|
43
|
-
|
44
|
-
until lines.empty?
|
45
|
-
line = lines.shift()
|
46
|
-
|
47
|
-
if m = line.match(/^\.?([\w\.]+)/)
|
48
|
-
klass = Hash.new
|
49
|
-
result[m[1]] = klass
|
50
|
-
|
51
|
-
elsif m = line.match(/^ sass(.*)/)
|
52
|
-
key = 'sass'
|
53
|
-
klass[key] = [ [ ], '', true ]
|
54
|
-
|
55
|
-
elsif m = line.match(/^ \.?([\w]+)(\(([^)]+)\))?/)
|
56
|
-
key = m[1]
|
57
|
-
klass[key] = [ [], m[3] ]
|
58
|
-
elsif key
|
59
|
-
if key == 'sass' && ! klass[key][2]
|
60
|
-
klass[key][0] << line.sub(/^ /, '')
|
61
|
-
else
|
62
|
-
klass[key][0] << line.sub(/^ /, '')
|
63
|
-
end
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
67
|
-
result.keys.each do |class_name|
|
68
|
-
klass = result[class_name]
|
69
|
-
klass.each_pair do |key, array|
|
70
|
-
if key == 'sass'
|
71
|
-
unless array[2]
|
72
|
-
array[0].unshift ".#{class_name.sub(/\.\w+$/, '').sub(/\./, '')}"
|
73
|
-
end
|
74
|
-
|
75
|
-
klass[key] = sassify(array[0].join("\n"))
|
76
|
-
else
|
77
|
-
klass[key] = functionize(array[0].join("\n"), array[1])
|
78
|
-
end
|
79
|
-
end
|
80
|
-
end
|
81
|
-
|
82
|
-
return result
|
83
|
-
rescue Exception => e
|
84
|
-
puts file
|
85
|
-
raise e
|
86
|
-
end
|
87
|
-
|
88
|
-
private
|
89
|
-
|
90
|
-
def sassify (string)
|
91
|
-
begin
|
92
|
-
css = @haml_engine.sassify(string)
|
93
|
-
rescue Exception => e
|
94
|
-
puts "Error Processing SASS:"
|
95
|
-
puts string
|
96
|
-
puts e.backtrace.join("\n")
|
97
|
-
raise e
|
98
|
-
end
|
99
|
-
return css.gsub(/\n/, '').to_json
|
100
|
-
end
|
101
|
-
|
102
|
-
def functionize (string, params)
|
103
|
-
begin
|
104
|
-
html = @haml_engine.hamlize(string)
|
105
|
-
rescue Exception => e
|
106
|
-
puts "Error Processing HAML:"
|
107
|
-
puts string
|
108
|
-
puts e.backtrace.join("\n")
|
109
|
-
raise e
|
110
|
-
end
|
111
|
-
|
112
|
-
if params
|
113
|
-
return functionize_with_params(html, params)
|
114
|
-
end
|
115
|
-
|
116
|
-
counter = 0
|
117
|
-
segments = html.split(%r|#\w+#|).collect { |seg| seg.to_json }
|
118
|
-
ret = Array.new
|
119
|
-
segments.each_with_index do |seg, i|
|
120
|
-
ret.push(seg)
|
121
|
-
ret.push(%{arguments[#{i}]}) if (segments.length-1) > i
|
122
|
-
end
|
123
|
-
return %{function(){return #{ret.join('+')}}}
|
124
|
-
end
|
125
|
-
|
126
|
-
|
127
|
-
def functionize_with_params (string, params)
|
128
|
-
args = []
|
129
|
-
string.gsub!(/#([^#]+)#/) do |m|
|
130
|
-
args << m.gsub(/#/, '')
|
131
|
-
'###'
|
132
|
-
end
|
133
|
-
|
134
|
-
segments = string.split(%r|###|).collect { |seg| seg.to_json }
|
135
|
-
ret = segments.zip(args).flatten.reject { |a| a.nil? }.join('+');
|
136
|
-
return %{function(#{params}){return #{ret}}}
|
137
|
-
end
|
138
|
-
|
139
|
-
|
140
|
-
end
|
141
|
-
rescue Exception
|
142
|
-
puts "HAML is not supported"
|
143
|
-
|
144
|
-
|
145
|
-
end
|
@@ -1,19 +0,0 @@
|
|
1
|
-
begin
|
2
|
-
require 'rubygems'
|
3
|
-
require 'haml'
|
4
|
-
require 'sass'
|
5
|
-
require 'json'
|
6
|
-
rescue Exception
|
7
|
-
puts "HAML is not supported"
|
8
|
-
end
|
9
|
-
|
10
|
-
|
11
|
-
class JS2::Parser::HamlEngine
|
12
|
-
def hamlize (string)
|
13
|
-
return Haml::Engine.new(string, { :ugly => true }).render(self).gsub(/\n/, '')
|
14
|
-
end
|
15
|
-
|
16
|
-
def sassify (string)
|
17
|
-
return Sass::Engine.new(string, { :ugly => true }).render
|
18
|
-
end
|
19
|
-
end
|
data/lib/js2/parser/lexer.rb
DELETED
@@ -1,37 +0,0 @@
|
|
1
|
-
class JS2::Parser::Lexer
|
2
|
-
def initialize
|
3
|
-
@tokenizer = JS2::Parser::Tokenizer.new
|
4
|
-
end
|
5
|
-
|
6
|
-
def start_node (type, idx, is_static = false)
|
7
|
-
child = @stack.last.add_child(type, idx)
|
8
|
-
@stack.push(child)
|
9
|
-
end
|
10
|
-
|
11
|
-
def stop_node (idx)
|
12
|
-
@last_idx = idx
|
13
|
-
last = @stack.pop()
|
14
|
-
last.stop(idx)
|
15
|
-
end
|
16
|
-
|
17
|
-
def parse (string, factory, file = nil)
|
18
|
-
@string = string
|
19
|
-
@page = factory.page_node(string, file)
|
20
|
-
@stack = [ @page ]
|
21
|
-
@last_idx = 0
|
22
|
-
|
23
|
-
@tokenizer.tokenize!(@string, self)
|
24
|
-
|
25
|
-
@page.children.each do |c|
|
26
|
-
c.stop(@last_idx) unless c.stop_idx
|
27
|
-
end
|
28
|
-
|
29
|
-
@page.stop(@last_idx)
|
30
|
-
end
|
31
|
-
|
32
|
-
def parse_file (file, factory)
|
33
|
-
parse(File.read(file), factory, file)
|
34
|
-
return @page
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|