opal 0.3.16 → 0.3.17
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/.gitignore +2 -0
- data/CHANGELOG.md +12 -0
- data/Gemfile +8 -7
- data/README.md +21 -13
- data/Rakefile +64 -78
- data/bin/opal +18 -29
- data/core/alpha.rb +2 -9
- data/core/array.rb +106 -50
- data/core/basic_object.rb +10 -8
- data/core/boolean.rb +2 -0
- data/core/class.rb +25 -13
- data/core/comparable.rb +6 -6
- data/core/enumerable.rb +90 -94
- data/core/enumerator.rb +3 -3
- data/core/hash.rb +86 -46
- data/core/kernel.rb +55 -39
- data/core/load_order +2 -5
- data/core/match_data.rb +1 -1
- data/core/module.rb +45 -20
- data/core/nil_class.rb +6 -2
- data/core/numeric.rb +20 -10
- data/core/proc.rb +2 -2
- data/core/range.rb +72 -13
- data/core/regexp.rb +5 -3
- data/core/runtime.js +228 -287
- data/core/string.rb +345 -37
- data/core/top_self.rb +1 -1
- data/lib/opal.rb +13 -91
- data/lib/opal/builder.rb +47 -120
- data/lib/opal/builder_task.rb +74 -0
- data/lib/opal/{parser/grammar.rb → grammar.rb} +1094 -1083
- data/lib/opal/{parser/grammar.y → grammar.y} +7 -0
- data/lib/opal/{parser/lexer.rb → lexer.rb} +32 -11
- data/lib/opal/{parser/parser.rb → parser.rb} +232 -238
- data/lib/opal/{parser/scope.rb → scope.rb} +72 -9
- data/lib/opal/version.rb +2 -3
- data/opal.gemspec +1 -2
- data/{core_spec → spec}/core/array/allocate_spec.rb +1 -3
- data/{core_spec → spec}/core/array/append_spec.rb +1 -4
- data/{core_spec → spec}/core/array/assoc_spec.rb +1 -4
- data/{core_spec → spec}/core/array/at_spec.rb +1 -3
- data/{core_spec → spec}/core/array/clear_spec.rb +1 -3
- data/spec/core/array/clone_spec.rb +15 -0
- data/{core_spec/core/array/shared/collect.rb → spec/core/array/collect_spec.rb} +1 -1
- data/{core_spec → spec}/core/array/compact_spec.rb +1 -3
- data/{core_spec → spec}/core/array/concat_spec.rb +1 -3
- data/{core_spec → spec}/core/array/constructor_spec.rb +9 -3
- data/{core_spec → spec}/core/array/count_spec.rb +1 -3
- data/{core_spec → spec}/core/array/delete_at_spec.rb +1 -4
- data/{core_spec → spec}/core/array/delete_if_spec.rb +1 -4
- data/{core_spec → spec}/core/array/delete_spec.rb +1 -4
- data/{core_spec → spec}/core/array/each_index_spec.rb +1 -4
- data/{core_spec → spec}/core/array/each_spec.rb +1 -4
- data/{core_spec → spec}/core/array/element_reference_spec.rb +74 -4
- data/{core_spec → spec}/core/array/empty_spec.rb +1 -4
- data/{core_spec/core/array/shared/eql.rb → spec/core/array/eql_spec.rb} +1 -1
- data/{core_spec → spec}/core/array/fetch_spec.rb +1 -4
- data/{core_spec → spec}/core/array/first_spec.rb +1 -3
- data/{core_spec → spec}/core/array/flatten_spec.rb +1 -3
- data/{core_spec → spec}/core/array/include_spec.rb +1 -3
- data/{core_spec → spec}/core/array/insert_spec.rb +1 -4
- data/{core_spec → spec}/core/array/last_spec.rb +1 -4
- data/{core_spec/core/array/shared/length.rb → spec/core/array/length_spec.rb} +1 -1
- data/spec/core/array/map_spec.rb +53 -0
- data/{core_spec → spec}/core/array/plus_spec.rb +1 -4
- data/{core_spec → spec}/core/array/pop_spec.rb +1 -4
- data/{core_spec → spec}/core/array/push_spec.rb +1 -4
- data/{core_spec → spec}/core/array/rassoc_spec.rb +1 -4
- data/{core_spec → spec}/core/array/reject_spec.rb +1 -4
- data/{core_spec/core/array/shared/replace.rb → spec/core/array/replace_spec.rb} +1 -1
- data/{core_spec → spec}/core/array/reverse_each_spec.rb +1 -4
- data/{core_spec → spec}/core/array/reverse_spec.rb +1 -4
- data/spec/core/array/size_spec.rb +6 -0
- data/spec/core/array/to_ary_spec.rb +6 -0
- data/spec/core/array/uniq_spec.rb +22 -0
- data/spec/core/array/zip_spec.rb +20 -0
- data/{core_spec → spec}/core/class/new_spec.rb +1 -4
- data/{core_spec → spec}/core/enumerable/all_spec.rb +1 -4
- data/{core_spec → spec}/core/enumerable/any_spec.rb +1 -4
- data/{core_spec/core/enumerable/shared/collect.rb → spec/core/enumerable/collect_spec.rb} +1 -1
- data/{core_spec → spec}/core/enumerable/count_spec.rb +2 -5
- data/{core_spec → spec}/core/enumerable/fixtures/classes.rb +1 -2
- data/{core_spec → spec}/core/false/and_spec.rb +1 -3
- data/{core_spec → spec}/core/false/inspect_spec.rb +1 -3
- data/{core_spec → spec}/core/false/or_spec.rb +1 -3
- data/{core_spec → spec}/core/false/to_s_spec.rb +1 -3
- data/{core_spec → spec}/core/false/xor_spec.rb +1 -3
- data/{core_spec → spec}/core/hash/allocate_spec.rb +1 -3
- data/spec/core/hash/assoc_spec.rb +25 -0
- data/{core_spec → spec}/core/hash/clear_spec.rb +1 -3
- data/{core_spec → spec}/core/hash/clone_spec.rb +1 -3
- data/{core_spec → spec}/core/hash/default_spec.rb +1 -3
- data/{core_spec → spec}/core/hash/delete_if_spec.rb +1 -3
- data/{core_spec → spec}/core/hash/element_reference_spec.rb +1 -3
- data/{core_spec → spec}/core/hash/element_set_spec.rb +1 -3
- data/spec/core/hash/merge_spec.rb +37 -0
- data/{core_spec → spec}/core/hash/new_spec.rb +1 -3
- data/{core_spec → spec}/core/matchdata/to_a_spec.rb +1 -3
- data/{core_spec → spec}/core/nil/and_spec.rb +1 -4
- data/{core_spec → spec}/core/nil/inspect_spec.rb +1 -4
- data/{core_spec → spec}/core/nil/nil_spec.rb +1 -4
- data/{core_spec → spec}/core/nil/or_spec.rb +1 -4
- data/{core_spec → spec}/core/nil/to_a_spec.rb +1 -4
- data/{core_spec → spec}/core/nil/to_f_spec.rb +1 -4
- data/{core_spec → spec}/core/nil/to_i_spec.rb +1 -4
- data/{core_spec → spec}/core/nil/to_s_spec.rb +1 -4
- data/{core_spec → spec}/core/nil/xor_spec.rb +1 -4
- data/{core_spec → spec}/core/numeric/equal_value_spec.rb +1 -3
- data/{core_spec → spec}/core/regexp/match_spec.rb +10 -3
- data/{core_spec → spec}/core/symbol/to_proc_spec.rb +1 -3
- data/{core_spec → spec}/core/true/and_spec.rb +1 -3
- data/{core_spec → spec}/core/true/inspect_spec.rb +1 -3
- data/{core_spec → spec}/core/true/or_spec.rb +1 -3
- data/{core_spec → spec}/core/true/to_s_spec.rb +1 -3
- data/{core_spec → spec}/core/true/xor_spec.rb +1 -3
- data/spec/index.html +11 -0
- data/{core_spec → spec}/language/alias_spec.rb +1 -3
- data/{core_spec → spec}/language/and_spec.rb +1 -4
- data/{core_spec → spec}/language/array_spec.rb +1 -4
- data/{core_spec → spec}/language/block_spec.rb +20 -3
- data/{core_spec → spec}/language/break_spec.rb +40 -3
- data/{core_spec → spec}/language/case_spec.rb +1 -4
- data/{core_spec → spec}/language/defined_spec.rb +9 -3
- data/{core_spec → spec}/language/ensure_spec.rb +38 -3
- data/{core_spec → spec}/language/hash_spec.rb +1 -3
- data/{core_spec → spec}/language/if_spec.rb +1 -4
- data/{core_spec → spec}/language/loop_spec.rb +1 -3
- data/spec/language/metaclass_spec.rb +13 -0
- data/{core_spec → spec}/language/next_spec.rb +47 -3
- data/{core_spec → spec}/language/or_spec.rb +1 -4
- data/{core_spec → spec}/language/predefined_spec.rb +1 -3
- data/{core_spec/language/regexp/interpolation_spec.rb → spec/language/regexp_spec.rb} +6 -3
- data/{core_spec → spec}/language/send_spec.rb +38 -4
- data/spec/language/singleton_class_spec.rb +31 -0
- data/spec/language/super_spec.rb +188 -0
- data/{core_spec → spec}/language/symbol_spec.rb +1 -3
- data/{core_spec → spec}/language/undef_spec.rb +1 -3
- data/{core_spec → spec}/language/unless_spec.rb +1 -4
- data/{core_spec → spec}/language/until_spec.rb +1 -3
- data/{core_spec → spec}/language/variables_spec.rb +1 -3
- data/{core_spec → spec}/language/while_spec.rb +1 -3
- data/{spec → test}/builder/build_source_spec.rb +0 -0
- data/{spec → test}/builder/fixtures/build_source/adam.rb +0 -0
- data/{spec → test}/builder/fixtures/build_source/bar/a.rb +0 -0
- data/{spec → test}/builder/fixtures/build_source/bar/wow/b.rb +0 -0
- data/{spec → test}/builder/fixtures/build_source/bar/wow/cow/c.rb +0 -0
- data/{spec → test}/builder/fixtures/build_source/beynon.rb +0 -0
- data/{spec → test}/builder/fixtures/build_source/charles.js +0 -0
- data/{spec → test}/builder/fixtures/build_source/foo/a.rb +0 -0
- data/{spec → test}/builder/fixtures/build_source/foo/b.rb +0 -0
- data/{spec → test}/builder/fixtures/build_source/foo/x.js +0 -0
- data/{spec → test}/builder/fixtures/build_source/foo/y.js +0 -0
- data/{spec → test}/grammar/alias_spec.rb +0 -0
- data/{spec → test}/grammar/and_spec.rb +0 -0
- data/{spec → test}/grammar/array_spec.rb +0 -0
- data/{spec → test}/grammar/attrasgn_spec.rb +0 -0
- data/{spec → test}/grammar/begin_spec.rb +0 -0
- data/{spec → test}/grammar/block_spec.rb +0 -0
- data/{spec → test}/grammar/break_spec.rb +0 -0
- data/{spec → test}/grammar/call_spec.rb +0 -0
- data/{spec → test}/grammar/class_spec.rb +0 -0
- data/{spec → test}/grammar/const_spec.rb +0 -0
- data/{spec → test}/grammar/cvar_spec.rb +0 -0
- data/{spec → test}/grammar/def_spec.rb +0 -0
- data/{spec → test}/grammar/false_spec.rb +0 -0
- data/{spec → test}/grammar/file_spec.rb +0 -0
- data/{spec → test}/grammar/gvar_spec.rb +0 -0
- data/{spec → test}/grammar/hash_spec.rb +0 -0
- data/{spec → test}/grammar/iasgn_spec.rb +0 -0
- data/{spec → test}/grammar/if_spec.rb +0 -0
- data/{spec → test}/grammar/iter_spec.rb +0 -0
- data/{spec → test}/grammar/ivar_spec.rb +0 -0
- data/{spec → test}/grammar/lasgn_spec.rb +0 -0
- data/{spec → test}/grammar/line_spec.rb +0 -0
- data/{spec → test}/grammar/lvar_spec.rb +0 -0
- data/{spec → test}/grammar/masgn_spec.rb +0 -0
- data/{spec → test}/grammar/module_spec.rb +0 -0
- data/{spec → test}/grammar/nil_spec.rb +0 -0
- data/{spec → test}/grammar/not_spec.rb +0 -0
- data/{spec → test}/grammar/op_asgn1_spec.rb +0 -0
- data/{spec → test}/grammar/op_asgn2_spec.rb +0 -0
- data/{spec → test}/grammar/or_spec.rb +0 -0
- data/{spec → test}/grammar/return_spec.rb +0 -0
- data/{spec → test}/grammar/sclass_spec.rb +0 -0
- data/{spec → test}/grammar/self_spec.rb +0 -0
- data/{spec → test}/grammar/str_spec.rb +0 -0
- data/{spec → test}/grammar/super_spec.rb +0 -0
- data/{spec → test}/grammar/true_spec.rb +0 -0
- data/{spec → test}/grammar/undef_spec.rb +0 -0
- data/{spec → test}/grammar/unless_spec.rb +0 -0
- data/{spec → test}/grammar/while_spec.rb +0 -0
- data/{spec → test}/grammar/xstr_spec.rb +0 -0
- data/{spec → test}/grammar/yield_spec.rb +0 -0
- data/{spec → test}/spec_helper.rb +0 -0
- metadata +330 -264
- data/core/debug.js +0 -59
- data/core/debug.rb +0 -35
- data/core/dir.rb +0 -90
- data/core/file.rb +0 -83
- data/core/gemlib.rb +0 -30
- data/core/io.rb +0 -44
- data/core_spec/README.md +0 -34
- data/core_spec/core/array/collect_spec.rb +0 -3
- data/core_spec/core/array/element_set_spec.rb +0 -7
- data/core_spec/core/array/eql_spec.rb +0 -3
- data/core_spec/core/array/equal_value_spec.rb +0 -3
- data/core_spec/core/array/fixtures/classes.rb +0 -8
- data/core_spec/core/array/length_spec.rb +0 -3
- data/core_spec/core/array/map_spec.rb +0 -3
- data/core_spec/core/array/replace_spec.rb +0 -3
- data/core_spec/core/enumerable/collect_spec.rb +0 -3
- data/core_spec/core/enumerable/detect_spec.rb +0 -3
- data/core_spec/core/enumerable/find_spec.rb +0 -3
- data/core_spec/core/enumerable/first_spec.rb +0 -3
- data/core_spec/core/enumerable/shared/entries.rb +0 -7
- data/core_spec/core/enumerable/shared/find.rb +0 -49
- data/core_spec/core/enumerable/shared/take.rb +0 -31
- data/core_spec/core/enumerable/to_a_spec.rb +0 -7
- data/core_spec/core/hash/assoc_spec.rb +0 -29
- data/core_spec/core/object/is_a_spec.rb +0 -2
- data/core_spec/core/object/shared/kind_of.rb +0 -0
- data/core_spec/core/regexp/shared/match.rb +0 -11
- data/core_spec/language/fixtures/block.rb +0 -19
- data/core_spec/language/fixtures/break.rb +0 -39
- data/core_spec/language/fixtures/defined.rb +0 -9
- data/core_spec/language/fixtures/ensure.rb +0 -37
- data/core_spec/language/fixtures/next.rb +0 -46
- data/core_spec/language/fixtures/send.rb +0 -36
- data/core_spec/language/fixtures/super.rb +0 -43
- data/core_spec/language/regexp_spec.rb +0 -7
- data/core_spec/language/string_spec.rb +0 -4
- data/core_spec/language/super_spec.rb +0 -18
- data/core_spec/language/versions/hash_1.9.rb +0 -20
- data/core_spec/opal/opal/defined_spec.rb +0 -15
- data/core_spec/opal/opal/function_spec.rb +0 -11
- data/core_spec/opal/opal/native_spec.rb +0 -16
- data/core_spec/opal/opal/null_spec.rb +0 -10
- data/core_spec/opal/opal/number_spec.rb +0 -11
- data/core_spec/opal/opal/object_spec.rb +0 -16
- data/core_spec/opal/opal/string_spec.rb +0 -11
- data/core_spec/opal/opal/typeof_spec.rb +0 -9
- data/core_spec/opal/opal/undefined_spec.rb +0 -10
- data/core_spec/opal/true/case_compare_spec.rb +0 -12
- data/core_spec/opal/true/class_spec.rb +0 -10
- data/core_spec/release_runner.html +0 -17
- data/core_spec/runner.html +0 -16
- data/core_spec/spec_helper.rb +0 -23
- data/lib/opal/context.rb +0 -269
- data/lib/opal/dependency_builder.rb +0 -133
- data/lib/opal/environment.rb +0 -87
- data/lib/opal/parser/sexp.rb +0 -17
data/.gitignore
CHANGED
data/CHANGELOG.md
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
## Change Log
|
2
|
+
|
3
|
+
### Edge
|
4
|
+
|
5
|
+
* Added HEREDOCS support in parser
|
6
|
+
* Parser now handles masgn (mass/multi assignments)
|
7
|
+
* More useful DependencyBuilder class to build gems dependencies
|
8
|
+
* Blocks no longer passed as an argument in method calls
|
9
|
+
|
10
|
+
### 0.3.15
|
11
|
+
|
12
|
+
Initial Release.
|
data/Gemfile
CHANGED
@@ -2,15 +2,16 @@ source :rubygems
|
|
2
2
|
|
3
3
|
gemspec
|
4
4
|
|
5
|
-
gem "racc"
|
6
5
|
gem "rake"
|
7
|
-
gem "
|
6
|
+
# gem "racc"
|
8
7
|
|
9
|
-
group :
|
8
|
+
group :browser do
|
9
|
+
gem "opal-racc"
|
10
10
|
gem "opal-spec"
|
11
|
+
gem "opal-strscan"
|
11
12
|
end
|
12
13
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
14
|
+
group :documentation do
|
15
|
+
gem "redcarpet"
|
16
|
+
gem "albino"
|
17
|
+
end
|
data/README.md
CHANGED
@@ -1,17 +1,25 @@
|
|
1
|
-
Opal
|
2
|
-
====
|
1
|
+
# Opal
|
3
2
|
|
4
|
-
Opal is a ruby to javascript compiler
|
5
|
-
efficient javascript that maintains rubys features. Opal will, by default,
|
6
|
-
generate fast and efficient code in preference to keeping all ruby features.
|
3
|
+
Opal is a ruby to javascript compiler and runtime for the browser.
|
7
4
|
|
8
|
-
|
9
|
-
uses a bundled runtime (written in javascript) that tie all the features
|
10
|
-
together. Whenever possible Opal bridges to native javascript features under
|
11
|
-
the hood. The Opal gem includes the compiler used to convert ruby sources
|
12
|
-
into javascript.
|
5
|
+
For docs, visit the website [http://opalrb.org](http://opalrb.org), or visit the [github wiki](http://github.com/adambeynon/opal/wiki).
|
13
6
|
|
14
|
-
|
15
|
-
[http://opalrb.org](http://opalrb.org)
|
7
|
+
There is also a [Google group for opal](https://groups.google.com/forum/#!forum/opalrb), or join the IRC channel on Freenode: `#opal`.
|
16
8
|
|
17
|
-
|
9
|
+
## Installation And Usage
|
10
|
+
|
11
|
+
Install via rubygems:
|
12
|
+
|
13
|
+
gem install opal
|
14
|
+
|
15
|
+
Or using Bundler:
|
16
|
+
|
17
|
+
gem "opal"
|
18
|
+
|
19
|
+
Ruby scripts can be compiled using:
|
20
|
+
|
21
|
+
opal -c foo.rb -o foo.js
|
22
|
+
|
23
|
+
## License
|
24
|
+
|
25
|
+
Opal is released under the MIT license.
|
data/Rakefile
CHANGED
@@ -3,60 +3,68 @@ require 'bundler'
|
|
3
3
|
Bundler.setup
|
4
4
|
|
5
5
|
require 'opal'
|
6
|
+
require 'opal/version'
|
6
7
|
|
7
|
-
|
8
|
-
|
9
|
-
|
8
|
+
desc "Build opal.js runtime into ./build"
|
9
|
+
task :opal do
|
10
|
+
File.open('build/opal.js', 'w+') do |o|
|
11
|
+
o.write Opal::Builder.runtime
|
12
|
+
end
|
10
13
|
end
|
11
14
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
15
|
+
Opal::BuilderTask.new do |t|
|
16
|
+
t.name = 'opal'
|
17
|
+
t.files = []
|
18
|
+
t.dependencies = %w[opal-spec opal-racc opal-strscan]
|
16
19
|
end
|
17
20
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
21
|
+
desc "Check file sizes for opal.js runtime"
|
22
|
+
task :sizes do
|
23
|
+
o = File.read 'build/opal.js'
|
24
|
+
m = uglify o
|
25
|
+
g = gzip m
|
23
26
|
|
24
|
-
|
25
|
-
|
26
|
-
task :test do
|
27
|
-
sh "bundle exec bin/opal build core_spec"
|
28
|
-
end
|
27
|
+
puts "#{opal.js}:"
|
28
|
+
puts "development: #{o.size}, minified: #{m.size}, gzipped: #{g.size}"
|
29
29
|
end
|
30
30
|
|
31
|
-
desc "
|
32
|
-
task :
|
33
|
-
|
31
|
+
desc "Rebuild grammar.rb for opal parser"
|
32
|
+
task :racc do
|
33
|
+
%x(racc -l lib/opal/grammar.y -o lib/opal/grammar.rb)
|
34
34
|
end
|
35
35
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
36
|
+
# Used for uglifying source to minify
|
37
|
+
def uglify(str)
|
38
|
+
IO.popen('uglifyjs -nc', 'r+') do |i|
|
39
|
+
i.puts str
|
40
|
+
i.close_write
|
41
|
+
return i.read
|
42
|
+
end
|
42
43
|
end
|
43
44
|
|
44
|
-
|
45
|
-
|
46
|
-
|
45
|
+
# Gzip code to check file size
|
46
|
+
def gzip(str)
|
47
|
+
IO.popen('gzip -f', 'r+') do |i|
|
48
|
+
i.puts str
|
49
|
+
i.close_write
|
50
|
+
return i.read
|
51
|
+
end
|
47
52
|
end
|
48
53
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
+
# Rubygems
|
55
|
+
namespace :gem do
|
56
|
+
desc "Build opal-#{Opal::VERSION}.gem"
|
57
|
+
task :build do
|
58
|
+
sh "gem build opal.gemspec"
|
59
|
+
end
|
54
60
|
|
55
|
-
desc "
|
56
|
-
task :
|
57
|
-
|
61
|
+
desc "Release opal-#{Opal::VERSION}.gem"
|
62
|
+
task :release do
|
63
|
+
puts "Need to release opal-#{Opal::VERSION}.gem"
|
64
|
+
end
|
58
65
|
end
|
59
66
|
|
67
|
+
# Documentation
|
60
68
|
namespace :docs do
|
61
69
|
task :clone do
|
62
70
|
if File.exists? 'gh-pages'
|
@@ -70,51 +78,29 @@ namespace :docs do
|
|
70
78
|
end
|
71
79
|
end
|
72
80
|
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
FileUtils.cp f, "gh-pages/#{f}"
|
77
|
-
end
|
78
|
-
end
|
79
|
-
|
80
|
-
desc "rocco"
|
81
|
-
task :rocco do
|
82
|
-
FileUtils.mkdir_p 'docs'
|
83
|
-
%w[builder dependency_builder].each do |src|
|
84
|
-
path = "lib/opal/#{src}.rb"
|
85
|
-
out = "docs/#{src}.html"
|
81
|
+
task :index do
|
82
|
+
require 'redcarpet'
|
83
|
+
require 'albino'
|
86
84
|
|
87
|
-
|
85
|
+
klass = Class.new(Redcarpet::Render::HTML) do
|
86
|
+
def block_code(code, language)
|
87
|
+
Albino.new(code, language || :text).colorize
|
88
|
+
end
|
88
89
|
end
|
89
|
-
end
|
90
|
-
end
|
91
90
|
|
92
|
-
|
93
|
-
# minified and once minified + gzipped. Depends on uglifyjs being installed
|
94
|
-
# for node.js
|
95
|
-
def sizes file
|
96
|
-
o = File.read file
|
97
|
-
m = uglify o
|
98
|
-
g = gzip m
|
91
|
+
markdown = Redcarpet::Markdown.new(klass, :fenced_code_blocks => true)
|
99
92
|
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
IO.popen('uglifyjs -nc', 'r+') do |i|
|
107
|
-
i.puts str
|
108
|
-
i.close_write
|
109
|
-
return i.read
|
93
|
+
File.open('gh-pages/index.html', 'w+') do |o|
|
94
|
+
o.write File.read('docs/pre.html')
|
95
|
+
o.write markdown.render(File.read 'docs/index.md')
|
96
|
+
o.write markdown.render(File.read 'CHANGELOG.md')
|
97
|
+
o.write File.read('docs/post.html')
|
98
|
+
end
|
110
99
|
end
|
111
|
-
end
|
112
100
|
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
i.close_write
|
118
|
-
return i.read
|
101
|
+
task :copy do
|
102
|
+
FileUtils.cp 'build/opal.js', 'gh-pages/opal.js'
|
103
|
+
FileUtils.cp 'docs/styles.css', 'gh-pages/styles.css'
|
104
|
+
FileUtils.cp 'docs/syntax.css', 'gh-pages/syntax.css'
|
119
105
|
end
|
120
|
-
end
|
106
|
+
end
|
data/bin/opal
CHANGED
@@ -1,32 +1,21 @@
|
|
1
1
|
#! /usr/bin/env ruby
|
2
2
|
|
3
3
|
require 'optparse'
|
4
|
-
require 'fileutils'
|
5
4
|
require 'opal'
|
6
5
|
|
7
|
-
# Parse command line options/files.
|
8
6
|
options = {}
|
9
7
|
|
10
|
-
case ARGV.first
|
11
|
-
when 'dependencies'
|
12
|
-
options[:dependencies] = true
|
13
|
-
ARGV.shift
|
14
|
-
when 'build'
|
15
|
-
options[:build] = true
|
16
|
-
ARGV.shift
|
17
|
-
end
|
18
|
-
|
19
8
|
OptionParser.new do |opts|
|
20
|
-
opts.on('-c', '--compile', 'Compile ruby') do
|
21
|
-
options[:
|
9
|
+
opts.on('-c', '--compile', 'Compile ruby') do
|
10
|
+
options[:compile] = true
|
22
11
|
end
|
23
12
|
|
24
13
|
opts.on('-o', '--out FILE', 'Output file') do |o|
|
25
14
|
options[:out] = o
|
26
15
|
end
|
27
16
|
|
28
|
-
opts.on('-
|
29
|
-
options[:
|
17
|
+
opts.on('-p', '--print', 'Print result') do
|
18
|
+
options[:print] = true
|
30
19
|
end
|
31
20
|
|
32
21
|
opts.on_tail("-v", "--version", "Show version") do
|
@@ -35,20 +24,20 @@ OptionParser.new do |opts|
|
|
35
24
|
end
|
36
25
|
end.parse! rescue abort("See `opal --help' for usage information.")
|
37
26
|
|
38
|
-
if options[:
|
39
|
-
|
40
|
-
Opal::DependencyBuilder.new(options).build
|
27
|
+
if options[:compile]
|
28
|
+
puts "No sources given" if ARGV.empty?
|
41
29
|
|
42
|
-
|
43
|
-
|
44
|
-
|
30
|
+
ARGV.each do |s|
|
31
|
+
puts "need to compile #{s}"
|
32
|
+
end
|
45
33
|
|
46
|
-
|
47
|
-
if ARGV.empty?
|
48
|
-
|
49
|
-
|
50
|
-
Opal
|
51
|
-
else
|
52
|
-
abort "File does not exist: #{ARGV.first}"
|
34
|
+
elsif options[:print]
|
35
|
+
puts "No sources given" if ARGV.empty?
|
36
|
+
|
37
|
+
ARGV.each do |s|
|
38
|
+
puts Opal.parse s
|
53
39
|
end
|
54
|
-
|
40
|
+
|
41
|
+
else
|
42
|
+
puts "No sources given"
|
43
|
+
end
|
data/core/alpha.rb
CHANGED
@@ -1,15 +1,8 @@
|
|
1
|
-
# load path getters
|
2
|
-
$LOAD_PATH = $: = `LOADER_PATHS`
|
3
|
-
|
4
|
-
# loaded features
|
5
|
-
$LOADED_FEATURES = $" = `FEATURES`
|
6
|
-
|
7
1
|
# regexp matches
|
8
2
|
$~ = nil
|
9
3
|
|
10
4
|
$/ = "\n"
|
11
5
|
|
12
|
-
RUBY_ENGINE = 'opal
|
6
|
+
RUBY_ENGINE = 'opal'
|
13
7
|
RUBY_PLATFORM = 'opal'
|
14
|
-
RUBY_VERSION = '1.9.2'
|
15
|
-
ARGV = []
|
8
|
+
RUBY_VERSION = '1.9.2'
|
data/core/array.rb
CHANGED
@@ -13,8 +13,8 @@ class Array
|
|
13
13
|
|
14
14
|
def self.allocate
|
15
15
|
%x{
|
16
|
-
var array
|
17
|
-
array
|
16
|
+
var array = [];
|
17
|
+
array._klass = this;
|
18
18
|
|
19
19
|
return array;
|
20
20
|
}
|
@@ -99,7 +99,7 @@ class Array
|
|
99
99
|
|
100
100
|
def ==(other)
|
101
101
|
%x{
|
102
|
-
if (this.length !== other.length) {
|
102
|
+
if (!other || (this.length !== other.length)) {
|
103
103
|
return false;
|
104
104
|
}
|
105
105
|
|
@@ -118,6 +118,28 @@ class Array
|
|
118
118
|
%x{
|
119
119
|
var size = this.length;
|
120
120
|
|
121
|
+
if (typeof index !== 'number') {
|
122
|
+
if (index._flags & T_RANGE) {
|
123
|
+
var exclude = index.exclude;
|
124
|
+
length = index.end;
|
125
|
+
index = index.begin;
|
126
|
+
|
127
|
+
if (index > size) {
|
128
|
+
return nil;
|
129
|
+
}
|
130
|
+
|
131
|
+
if (length < 0) {
|
132
|
+
length += size;
|
133
|
+
}
|
134
|
+
|
135
|
+
if (!exclude) length += 1;
|
136
|
+
return this.slice(index, length);
|
137
|
+
}
|
138
|
+
else {
|
139
|
+
throw RubyException.$new('bad arg for Array#[]');
|
140
|
+
}
|
141
|
+
}
|
142
|
+
|
121
143
|
if (index < 0) {
|
122
144
|
index += size;
|
123
145
|
}
|
@@ -185,7 +207,7 @@ class Array
|
|
185
207
|
end
|
186
208
|
|
187
209
|
def clone
|
188
|
-
`this.slice(
|
210
|
+
`this.slice()`
|
189
211
|
end
|
190
212
|
|
191
213
|
def collect(&block)
|
@@ -195,8 +217,8 @@ class Array
|
|
195
217
|
var result = [];
|
196
218
|
|
197
219
|
for (var i = 0, length = this.length, value; i < length; i++) {
|
198
|
-
if ((value =
|
199
|
-
return
|
220
|
+
if ((value = block.call(__context, this[i])) === __breaker) {
|
221
|
+
return __breaker.$v;
|
200
222
|
}
|
201
223
|
|
202
224
|
result.push(value);
|
@@ -211,8 +233,8 @@ class Array
|
|
211
233
|
|
212
234
|
%x{
|
213
235
|
for (var i = 0, length = this.length, val; i < length; i++) {
|
214
|
-
if ((val =
|
215
|
-
return
|
236
|
+
if ((val = block.call(__context, this[i])) === __breaker) {
|
237
|
+
return __breaker.$v;
|
216
238
|
}
|
217
239
|
|
218
240
|
this[i] = val;
|
@@ -321,8 +343,8 @@ class Array
|
|
321
343
|
|
322
344
|
%x{
|
323
345
|
for (var i = 0, length = this.length, value; i < length; i++) {
|
324
|
-
if ((value =
|
325
|
-
return
|
346
|
+
if ((value = block.call(__context, this[i])) === __breaker) {
|
347
|
+
return __breaker.$v;
|
326
348
|
}
|
327
349
|
|
328
350
|
if (value !== false && value !== nil) {
|
@@ -346,7 +368,7 @@ class Array
|
|
346
368
|
|
347
369
|
%x{
|
348
370
|
for (var i = 0, length = this.length, value; i < length; i++) {
|
349
|
-
if ((value =
|
371
|
+
if ((value = block.call(__context, this[i])) === $breaker) {
|
350
372
|
return $breaker.$v;
|
351
373
|
}
|
352
374
|
|
@@ -359,13 +381,15 @@ class Array
|
|
359
381
|
}
|
360
382
|
end
|
361
383
|
|
384
|
+
alias dup clone
|
385
|
+
|
362
386
|
def each(&block)
|
363
387
|
return enum_for :each unless block_given?
|
364
388
|
|
365
389
|
%x{
|
366
390
|
for (var i = 0, length = this.length; i < length; i++) {
|
367
|
-
if (
|
368
|
-
return
|
391
|
+
if (block.call(__context, this[i]) === __breaker) {
|
392
|
+
return __breaker.$v;
|
369
393
|
}
|
370
394
|
}
|
371
395
|
}
|
@@ -378,8 +402,8 @@ class Array
|
|
378
402
|
|
379
403
|
%x{
|
380
404
|
for (var i = 0, length = this.length; i < length; i++) {
|
381
|
-
if (
|
382
|
-
return
|
405
|
+
if (block.call(__context, i) === __breaker) {
|
406
|
+
return __breaker.$v;
|
383
407
|
}
|
384
408
|
}
|
385
409
|
}
|
@@ -392,8 +416,8 @@ class Array
|
|
392
416
|
|
393
417
|
%x{
|
394
418
|
for (var i = 0, length = this.length; i < length; i++) {
|
395
|
-
if (
|
396
|
-
return
|
419
|
+
if (block.call(__context, this[i], i) === __breaker) {
|
420
|
+
return __breaker.$v;
|
397
421
|
}
|
398
422
|
}
|
399
423
|
}
|
@@ -421,11 +445,11 @@ class Array
|
|
421
445
|
return defaults;
|
422
446
|
}
|
423
447
|
|
424
|
-
if (block !==
|
425
|
-
return
|
448
|
+
if (block !== null) {
|
449
|
+
return block.call($context, nil, original);
|
426
450
|
}
|
427
451
|
|
428
|
-
|
452
|
+
throw RubyIndexError.$new('Array#fetch');
|
429
453
|
}
|
430
454
|
end
|
431
455
|
|
@@ -446,7 +470,7 @@ class Array
|
|
446
470
|
for (var i = 0, length = this.length, item; i < length; i++) {
|
447
471
|
item = this[i];
|
448
472
|
|
449
|
-
if (item
|
473
|
+
if (item._flags & T_ARRAY) {
|
450
474
|
if (level === undefined) {
|
451
475
|
result = result.concat(#{`item`.flatten});
|
452
476
|
}
|
@@ -492,7 +516,7 @@ class Array
|
|
492
516
|
end
|
493
517
|
|
494
518
|
def hash
|
495
|
-
`this
|
519
|
+
`this._id || (this._id = unique_id++)`
|
496
520
|
end
|
497
521
|
|
498
522
|
def include?(member)
|
@@ -511,13 +535,13 @@ class Array
|
|
511
535
|
return enum_for :index unless block_given? && object == undefined
|
512
536
|
|
513
537
|
%x{
|
514
|
-
if (block !==
|
538
|
+
if (block !== null) {
|
515
539
|
for (var i = 0, length = this.length, value; i < length; i++) {
|
516
|
-
if ((value =
|
540
|
+
if ((value = block.call($context, null, this[i])) === $breaker) {
|
517
541
|
return $breaker.$v;
|
518
542
|
}
|
519
543
|
|
520
|
-
if (value !== false && value !==
|
544
|
+
if (value !== false && value !== null) {
|
521
545
|
return i;
|
522
546
|
}
|
523
547
|
}
|
@@ -530,7 +554,7 @@ class Array
|
|
530
554
|
}
|
531
555
|
}
|
532
556
|
|
533
|
-
return
|
557
|
+
return null
|
534
558
|
}
|
535
559
|
end
|
536
560
|
|
@@ -550,7 +574,7 @@ class Array
|
|
550
574
|
}
|
551
575
|
|
552
576
|
for (var length = this.length, value; i < length; i++) {
|
553
|
-
if ((value =
|
577
|
+
if ((value = block.call($context, null, result, this[i])) === $breaker) {
|
554
578
|
return $breaker.$v;
|
555
579
|
}
|
556
580
|
|
@@ -568,7 +592,7 @@ class Array
|
|
568
592
|
index += this.length + 1;
|
569
593
|
|
570
594
|
if (index < 0) {
|
571
|
-
|
595
|
+
throw RubyIndexError.$new(index + ' is out of bounds');
|
572
596
|
}
|
573
597
|
}
|
574
598
|
if (index > this.length) {
|
@@ -612,11 +636,11 @@ class Array
|
|
612
636
|
return enum_for :keep_if unless block_given?
|
613
637
|
%x{
|
614
638
|
for (var i = 0, length = this.length, value; i < length; i++) {
|
615
|
-
if ((value =
|
639
|
+
if ((value = block.call($context, null, this[i])) === $breaker) {
|
616
640
|
return $breaker.$v;
|
617
641
|
}
|
618
642
|
|
619
|
-
if (value === false || value ===
|
643
|
+
if (value === false || value === null) {
|
620
644
|
this.splice(i, 1);
|
621
645
|
|
622
646
|
length--;
|
@@ -636,7 +660,7 @@ class Array
|
|
636
660
|
return length === 0 ? nil : this[length - 1];
|
637
661
|
}
|
638
662
|
else if (count < 0) {
|
639
|
-
|
663
|
+
throw RubyArgError.$new('negative count given');
|
640
664
|
}
|
641
665
|
|
642
666
|
if (count > length) {
|
@@ -664,7 +688,7 @@ class Array
|
|
664
688
|
}
|
665
689
|
|
666
690
|
if (count < 0) {
|
667
|
-
|
691
|
+
throw RubyArgError.$new('negative count given');
|
668
692
|
}
|
669
693
|
|
670
694
|
return count > length ? this.splice(0) : this.splice(length - count, length);
|
@@ -704,8 +728,8 @@ class Array
|
|
704
728
|
var result = [];
|
705
729
|
|
706
730
|
for (var i = 0, length = this.length, value; i < length; i++) {
|
707
|
-
if ((value =
|
708
|
-
return
|
731
|
+
if ((value = block.call(__context, this[i])) === __breaker) {
|
732
|
+
return __breaker.$v;
|
709
733
|
}
|
710
734
|
|
711
735
|
if (value === false || value === nil) {
|
@@ -723,8 +747,8 @@ class Array
|
|
723
747
|
var original = this.length;
|
724
748
|
|
725
749
|
for (var i = 0, length = this.length, value; i < length; i++) {
|
726
|
-
if ((value =
|
727
|
-
return
|
750
|
+
if ((value = block.call(__context, this[i])) === __breaker) {
|
751
|
+
return __breaker.$v;
|
728
752
|
}
|
729
753
|
|
730
754
|
if (value !== false && value !== nil) {
|
@@ -771,13 +795,13 @@ class Array
|
|
771
795
|
return enum_for :rindex unless block_given? && object == undefined
|
772
796
|
|
773
797
|
%x{
|
774
|
-
if (block !==
|
798
|
+
if (block !== null) {
|
775
799
|
for (var i = this.length - 1, value; i >= 0; i--) {
|
776
|
-
if ((value =
|
800
|
+
if ((value = block.call($context, null, this[i])) === $breaker) {
|
777
801
|
return $breaker.$v;
|
778
802
|
}
|
779
803
|
|
780
|
-
if (value !== false && value !==
|
804
|
+
if (value !== false && value !== null) {
|
781
805
|
return i;
|
782
806
|
}
|
783
807
|
}
|
@@ -790,7 +814,7 @@ class Array
|
|
790
814
|
}
|
791
815
|
}
|
792
816
|
|
793
|
-
return
|
817
|
+
return null;
|
794
818
|
}
|
795
819
|
end
|
796
820
|
|
@@ -803,11 +827,11 @@ class Array
|
|
803
827
|
for (var i = 0, length = this.length, item, value; i < length; i++) {
|
804
828
|
item = this[i];
|
805
829
|
|
806
|
-
if ((value =
|
830
|
+
if ((value = block.call($context, null, item)) === $breaker) {
|
807
831
|
return $breaker.$v;
|
808
832
|
}
|
809
833
|
|
810
|
-
if (value !== false && value !==
|
834
|
+
if (value !== false && value !== null) {
|
811
835
|
result.push(item);
|
812
836
|
}
|
813
837
|
}
|
@@ -824,11 +848,11 @@ class Array
|
|
824
848
|
for (var i = 0, length = original, item, value; i < length; i++) {
|
825
849
|
item = this[i];
|
826
850
|
|
827
|
-
if ((value =
|
851
|
+
if ((value = block.call($context, null, item)) === $breaker) {
|
828
852
|
return $breaker.$v;
|
829
853
|
}
|
830
854
|
|
831
|
-
if (value === false || value ===
|
855
|
+
if (value === false || value === null) {
|
832
856
|
this.splice(i, 1);
|
833
857
|
|
834
858
|
length--;
|
@@ -836,7 +860,7 @@ class Array
|
|
836
860
|
}
|
837
861
|
}
|
838
862
|
|
839
|
-
return this.length === original ?
|
863
|
+
return this.length === original ? null : this;
|
840
864
|
}
|
841
865
|
end
|
842
866
|
|
@@ -855,7 +879,7 @@ class Array
|
|
855
879
|
}
|
856
880
|
|
857
881
|
if (index < 0 || index >= this.length) {
|
858
|
-
return
|
882
|
+
return null;
|
859
883
|
}
|
860
884
|
|
861
885
|
if (length !== undefined) {
|
@@ -879,11 +903,11 @@ class Array
|
|
879
903
|
for (var i = 0, length = this.length, item, value; i < length; i++) {
|
880
904
|
item = this[i];
|
881
905
|
|
882
|
-
if ((value =
|
906
|
+
if ((value = block.call($context, null, item)) === $breaker) {
|
883
907
|
return $breaker.$v;
|
884
908
|
}
|
885
909
|
|
886
|
-
if (value === false || value ===
|
910
|
+
if (value === false || value === null) {
|
887
911
|
return result;
|
888
912
|
}
|
889
913
|
|
@@ -909,7 +933,7 @@ class Array
|
|
909
933
|
|
910
934
|
for (var i = 0, length = this.length, item, hash; i < length; i++) {
|
911
935
|
item = this[i];
|
912
|
-
hash =
|
936
|
+
hash = item.$hash();
|
913
937
|
|
914
938
|
if (!seen[hash]) {
|
915
939
|
seen[hash] = true;
|
@@ -929,7 +953,7 @@ class Array
|
|
929
953
|
|
930
954
|
for (var i = 0, length = original, item, hash; i < length; i++) {
|
931
955
|
item = this[i];
|
932
|
-
hash =
|
956
|
+
hash = item.$hash();;
|
933
957
|
|
934
958
|
if (!seen[hash]) {
|
935
959
|
seen[hash] = true;
|
@@ -955,4 +979,36 @@ class Array
|
|
955
979
|
return this;
|
956
980
|
}
|
957
981
|
end
|
982
|
+
|
983
|
+
def zip(*others, &block)
|
984
|
+
%x{
|
985
|
+
var result = [], size = this.length, part, o;
|
986
|
+
|
987
|
+
for (var i = 0; i < size; i++) {
|
988
|
+
part = [this[i]];
|
989
|
+
|
990
|
+
for (var j = 0, jj = others.length; j < jj; j++) {
|
991
|
+
o = others[j][i];
|
992
|
+
|
993
|
+
if (o === undefined) {
|
994
|
+
o = nil;
|
995
|
+
}
|
996
|
+
|
997
|
+
part[j + 1] = o;
|
998
|
+
}
|
999
|
+
|
1000
|
+
result[i] = part;
|
1001
|
+
}
|
1002
|
+
|
1003
|
+
if (block) {
|
1004
|
+
for (var i = 0; i < size; i++) {
|
1005
|
+
block.call(__context, result[i]);
|
1006
|
+
}
|
1007
|
+
|
1008
|
+
return nil;
|
1009
|
+
}
|
1010
|
+
|
1011
|
+
return result;
|
1012
|
+
}
|
1013
|
+
end
|
958
1014
|
end
|