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/bin/js2
CHANGED
@@ -1,130 +1,13 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
require
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
options.rails = false
|
12
|
-
options.sleep_time = 1
|
13
|
-
options.rdoc_bin = 'rdoc'
|
14
|
-
|
15
|
-
|
16
|
-
op = OptionParser.new do |opts|
|
17
|
-
opts.banner = "Usage: js2 <daemon|compile|rdoc|help|config> [options]"
|
18
|
-
|
19
|
-
opts.on('-r', '--rails', "Rails (out_dir: ./public/javascript js2_dir: ./app/js2)") do |r|
|
20
|
-
options.rails = true
|
21
|
-
end
|
22
|
-
|
23
|
-
opts.on('-e', '--environment ENV', "Mostly for use with rails or a yml file with multiple configurations.") do |env|
|
24
|
-
options.env = env
|
25
|
-
end
|
26
|
-
|
27
|
-
opts.on('-c', '--config FILE', "Use js2.yml config file (run: js2 config to generate a config file)") do |file|
|
28
|
-
options.yml = YAML.load_file(file)
|
29
|
-
end
|
30
|
-
|
31
|
-
opts.on('-i', '--include-rails', "Mostly for use with rails or a yml file with multiple configurations.") do |env|
|
32
|
-
options.include_rails = true
|
33
|
-
end
|
34
|
-
|
35
|
-
opts.on('-s', '--sleep N', "Defines the wait time in between directory checks. This is only applicable to daemon mode.") do |t|
|
36
|
-
options.sleep_time = t.to_i
|
37
|
-
end
|
38
|
-
|
39
|
-
|
40
|
-
opts.on('-j', '--js2-dir DIR', "Directory where js2 files reside. Defaults to current directory.") do |d|
|
41
|
-
options.js2_dir = d
|
42
|
-
end
|
43
|
-
|
44
|
-
opts.on('-o', '--out-dir DIR', "Output directory where javascript is written to. Defaults to current directory.") do |d|
|
45
|
-
options.out_dir = d
|
46
|
-
end
|
47
|
-
|
48
|
-
opts.on('-h', '--haml-dir DIR', "Directory where js2.haml files reside. Defaults to current directory.") do |d|
|
49
|
-
options.haml_dir = d
|
50
|
-
end
|
51
|
-
|
52
|
-
opts.on('-d', '--rdoc EXECUTABLE', "Rdoc executable to use. Defaults to 'rdoc'") do |d|
|
53
|
-
options.rdoc_bin = d
|
54
|
-
end
|
55
|
-
|
56
|
-
end
|
57
|
-
|
58
|
-
main_action = ARGV.first
|
59
|
-
if [ 'daemon', 'compile', 'rdoc', 'help', 'config' ].include?(main_action)
|
60
|
-
|
3
|
+
dir = File.expand_path('../../lib/', __FILE__)
|
4
|
+
dir = File.directory?(dir) ? (dir + '/') : ''
|
5
|
+
|
6
|
+
require "#{dir}js2"
|
7
|
+
if (ARGV[0] == 'run')
|
8
|
+
file = ARGV[1]
|
9
|
+
c = JS2::Context.new
|
10
|
+
c.eval(File.read(file))
|
61
11
|
else
|
62
|
-
|
63
|
-
end
|
64
|
-
|
65
|
-
if main_action == 'help' || ! main_action
|
66
|
-
puts op
|
67
|
-
exit
|
68
|
-
end
|
69
|
-
|
70
|
-
if ! main_action
|
71
|
-
main_action = 'daemon'
|
72
|
-
end
|
73
|
-
|
74
|
-
op.parse!
|
75
|
-
|
76
|
-
if options.yml && options.env
|
77
|
-
options.yml = options.yml[options.env]
|
78
|
-
end
|
79
|
-
|
80
|
-
if options.yml
|
81
|
-
options.yml.each_pair do |k,v|
|
82
|
-
options.send(k +'=', v) if options.send(k) == nil
|
83
|
-
end
|
84
|
-
end
|
85
|
-
|
86
|
-
puts options.inspect
|
87
|
-
puts options.include_rails.inspect
|
88
|
-
|
89
|
-
if options.include_rails
|
90
|
-
puts "loading rails environment..."
|
91
|
-
ENV['RAILS_ENV'] = options.env if options.env
|
92
|
-
require './config/environment'
|
93
|
-
end
|
94
|
-
|
95
|
-
config = JS2::Util::Config.new
|
96
|
-
|
97
|
-
if options.rails
|
98
|
-
config.rails!
|
99
|
-
end
|
100
|
-
|
101
|
-
config.out_dir = options.out_dir if options.out_dir
|
102
|
-
config.js2_dir = options.js2_dir if options.js2_dir
|
103
|
-
config.haml_dir = options.haml_dir if options.haml_dir
|
104
|
-
config.haml_engine = eval('::' + options.haml_engine_class + '.new') if options.haml_engine_class
|
105
|
-
|
106
|
-
puts config
|
107
|
-
|
108
|
-
if main_action == 'config'
|
109
|
-
puts "# run: js2 config > js2.yml to create a config file"
|
110
|
-
puts config.example_yml
|
111
|
-
exit
|
112
|
-
end
|
113
|
-
|
114
|
-
processor = JS2::Util::Processor.new(config)
|
115
|
-
|
116
|
-
if main_action == 'daemon'
|
117
|
-
puts "running in daemon mode..."
|
118
|
-
while 1
|
119
|
-
res = processor.process!
|
120
|
-
puts "Compiling #{Time.now}..." if res[:changed].any?
|
121
|
-
sleep options.sleep_time
|
122
|
-
end
|
123
|
-
elsif main_action == 'compile'
|
124
|
-
puts "compiling once! use daemon to monitor changes and compile automatically."
|
125
|
-
res = processor.process!
|
126
|
-
puts "Compiling #{Time.now}..." if res[:changed].any?
|
127
|
-
elsif main_action == 'rdoc'
|
128
|
-
res = processor.process!
|
129
|
-
JS2::Util::Rdoc.build(res[:pages], config.file_handler, options.rdoc_bin)
|
12
|
+
JS2::Command.new(ARGV).cli
|
130
13
|
end
|
data/bin/js2-ruby
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
dir = File.expand_path('../../lib/', __FILE__)
|
4
|
+
dir = File.directory?(dir) ? (dir + '/') : ''
|
5
|
+
|
6
|
+
require "#{dir}js2"
|
7
|
+
if (ARGV[0] == 'run')
|
8
|
+
file = ARGV[1]
|
9
|
+
c = JS2::Context.new
|
10
|
+
c.eval(File.read(file))
|
11
|
+
else
|
12
|
+
JS2::Command.new(ARGV).cli
|
13
|
+
end
|
data/lib/js2/command.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'optparse'
|
2
|
+
|
3
|
+
module JS2
|
4
|
+
class Command
|
5
|
+
DEFAULT_INTERVAL = 3
|
6
|
+
def initialize(argv)
|
7
|
+
@ctx = JS2::Context.new
|
8
|
+
@ctx['JS2']['FS'] = JS2::FS.new(@ctx)
|
9
|
+
@ctx['argv'] = argv
|
10
|
+
end
|
11
|
+
|
12
|
+
def cli
|
13
|
+
@ctx.eval("new JS2.Commander(argv).cli()")
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
data/lib/js2/context.rb
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
module JS2
|
2
|
+
class Console
|
3
|
+
def log(*str)
|
4
|
+
puts str.join(',')
|
5
|
+
end
|
6
|
+
end
|
7
|
+
|
8
|
+
class Context
|
9
|
+
def initialize
|
10
|
+
@ctx = JS2::Engine.new
|
11
|
+
@ctx['JS2_RUBY_FILE_ADAPTER'] = FS.new
|
12
|
+
@ctx['console'] = Console.new
|
13
|
+
@ctx.eval(File.read(File.dirname(__FILE__) + '/js2.js'))
|
14
|
+
@js2 = @ctx['JS2']
|
15
|
+
end
|
16
|
+
|
17
|
+
def []= (k,v)
|
18
|
+
@ctx[k] = v
|
19
|
+
end
|
20
|
+
|
21
|
+
def [] (k)
|
22
|
+
@ctx[k]
|
23
|
+
end
|
24
|
+
|
25
|
+
|
26
|
+
def render(str)
|
27
|
+
@js2.render(str)
|
28
|
+
end
|
29
|
+
|
30
|
+
def eval(str)
|
31
|
+
@ctx.eval(render(str))
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
end
|
data/lib/js2/fs.rb
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
class JS2::FS
|
3
|
+
def read(file)
|
4
|
+
File.read(file)
|
5
|
+
end
|
6
|
+
|
7
|
+
def find(dir, ext, recursive)
|
8
|
+
lookup = recursive ? "**" : "."
|
9
|
+
return Dir["#{lookup}/*.#{ext}"].collect { |f| File.expand_path(f) }.reject { |f| f.match(/^\./) }
|
10
|
+
end
|
11
|
+
|
12
|
+
|
13
|
+
def expandPath(file)
|
14
|
+
return File.expand_path(file)
|
15
|
+
end
|
16
|
+
|
17
|
+
def isDirectory(dir)
|
18
|
+
return File.directory?(dir)
|
19
|
+
end
|
20
|
+
|
21
|
+
def dirname(file)
|
22
|
+
return File.dirname(file)
|
23
|
+
end
|
24
|
+
|
25
|
+
def readdir(file)
|
26
|
+
return Dir.entries(file).reject { |f| f.match(/^\.\.?/) }
|
27
|
+
end
|
28
|
+
|
29
|
+
|
30
|
+
def mkdir(file)
|
31
|
+
dir = File.dirname(file)
|
32
|
+
FileUtils.mkdir(dir) unless File.directory?(dir)
|
33
|
+
end
|
34
|
+
|
35
|
+
def isFile(dir)
|
36
|
+
return false unless dir
|
37
|
+
return File.file?(dir)
|
38
|
+
end
|
39
|
+
|
40
|
+
def write(out, data)
|
41
|
+
File.open(out, 'w') { |f| f << data }
|
42
|
+
end
|
43
|
+
|
44
|
+
def mtime(file)
|
45
|
+
File.stat(file).mtime.to_i
|
46
|
+
rescue
|
47
|
+
return 0
|
48
|
+
end
|
49
|
+
|
50
|
+
def setInterval(code, time)
|
51
|
+
while true
|
52
|
+
@ctx.eval(code)
|
53
|
+
sleep(time/1000)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|