opal 0.3.15 → 0.3.16
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -1
- data/Gemfile +8 -2
- data/README.md +1 -1
- data/Rakefile +51 -57
- data/bin/opal +50 -2
- data/{runtime/corelib → core}/alpha.rb +6 -1
- data/{runtime/corelib → core}/array.rb +38 -42
- data/{runtime/corelib → core}/basic_object.rb +6 -17
- data/core/boolean.rb +40 -0
- data/core/class.rb +69 -0
- data/{runtime/corelib → core}/comparable.rb +0 -0
- data/core/debug.js +59 -0
- data/core/debug.rb +35 -0
- data/core/dir.rb +90 -0
- data/core/enumerable.rb +331 -0
- data/core/enumerator.rb +126 -0
- data/core/error.rb +40 -0
- data/{runtime/corelib → core}/file.rb +6 -3
- data/core/gemlib.rb +30 -0
- data/{runtime/corelib → core}/hash.rb +37 -35
- data/{runtime/corelib → core}/io.rb +0 -0
- data/{runtime/corelib → core}/kernel.rb +26 -21
- data/{runtime/corelib → core}/load_order +2 -5
- data/{runtime/corelib → core}/match_data.rb +2 -4
- data/core/module.rb +204 -0
- data/{runtime/corelib → core}/nil_class.rb +1 -7
- data/{runtime/corelib → core}/numeric.rb +9 -13
- data/core/object.rb +17 -0
- data/{runtime/corelib → core}/proc.rb +2 -13
- data/{runtime/corelib → core}/range.rb +19 -7
- data/{runtime/corelib → core}/rational.rb +0 -0
- data/{runtime/corelib → core}/regexp.rb +2 -6
- data/core/runtime.js +672 -0
- data/{runtime/corelib → core}/string.rb +25 -9
- data/{runtime/corelib → core}/struct.rb +0 -0
- data/core/time.rb +111 -0
- data/{runtime/corelib → core}/top_self.rb +0 -0
- data/{runtime/spec → core_spec}/README.md +0 -0
- data/{runtime/spec → core_spec}/core/array/allocate_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/array/append_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/array/assoc_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/array/at_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/array/clear_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/array/collect_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/array/compact_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/array/concat_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/array/constructor_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/array/count_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/array/delete_at_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/array/delete_if_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/array/delete_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/array/each_index_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/array/each_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/array/element_reference_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/array/element_set_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/array/empty_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/array/eql_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/array/equal_value_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/array/fetch_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/array/first_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/array/fixtures/classes.rb +0 -0
- data/{runtime/spec → core_spec}/core/array/flatten_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/array/include_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/array/insert_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/array/last_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/array/length_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/array/map_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/array/plus_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/array/pop_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/array/push_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/array/rassoc_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/array/reject_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/array/replace_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/array/reverse_each_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/array/reverse_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/array/shared/collect.rb +0 -0
- data/{runtime/spec → core_spec}/core/array/shared/eql.rb +0 -0
- data/{runtime/spec → core_spec}/core/array/shared/length.rb +0 -0
- data/{runtime/spec → core_spec}/core/array/shared/replace.rb +0 -0
- data/{runtime/spec → core_spec}/core/class/new_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/enumerable/all_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/enumerable/any_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/enumerable/collect_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/enumerable/count_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/enumerable/detect_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/enumerable/find_spec.rb +0 -0
- data/core_spec/core/enumerable/first_spec.rb +3 -0
- data/{runtime/spec → core_spec}/core/enumerable/fixtures/classes.rb +0 -0
- data/{runtime/spec → core_spec}/core/enumerable/shared/collect.rb +0 -0
- data/{runtime/spec → core_spec}/core/enumerable/shared/entries.rb +0 -0
- data/{runtime/spec → core_spec}/core/enumerable/shared/find.rb +0 -0
- data/core_spec/core/enumerable/shared/take.rb +31 -0
- data/{runtime/spec → core_spec}/core/enumerable/to_a_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/false/and_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/false/inspect_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/false/or_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/false/to_s_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/false/xor_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/hash/allocate_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/hash/assoc_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/hash/clear_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/hash/clone_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/hash/default_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/hash/delete_if_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/hash/element_reference_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/hash/element_set_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/hash/new_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/matchdata/to_a_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/nil/and_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/nil/inspect_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/nil/nil_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/nil/or_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/nil/to_a_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/nil/to_f_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/nil/to_i_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/nil/to_s_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/nil/xor_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/numeric/equal_value_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/object/is_a_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/object/shared/kind_of.rb +0 -0
- data/{runtime/spec → core_spec}/core/regexp/match_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/regexp/shared/match.rb +0 -0
- data/{runtime/spec → core_spec}/core/symbol/to_proc_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/true/and_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/true/inspect_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/true/or_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/true/to_s_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/true/xor_spec.rb +0 -0
- data/{runtime/spec → core_spec}/language/alias_spec.rb +0 -0
- data/{runtime/spec → core_spec}/language/and_spec.rb +0 -0
- data/{runtime/spec → core_spec}/language/array_spec.rb +0 -0
- data/{runtime/spec → core_spec}/language/block_spec.rb +0 -0
- data/{runtime/spec → core_spec}/language/break_spec.rb +0 -0
- data/{runtime/spec → core_spec}/language/case_spec.rb +0 -0
- data/{runtime/spec → core_spec}/language/defined_spec.rb +0 -0
- data/{runtime/spec → core_spec}/language/ensure_spec.rb +0 -0
- data/{runtime/spec → core_spec}/language/fixtures/block.rb +0 -0
- data/{runtime/spec → core_spec}/language/fixtures/break.rb +0 -0
- data/{runtime/spec → core_spec}/language/fixtures/defined.rb +0 -0
- data/{runtime/spec → core_spec}/language/fixtures/ensure.rb +0 -0
- data/{runtime/spec → core_spec}/language/fixtures/next.rb +0 -0
- data/{runtime/spec → core_spec}/language/fixtures/send.rb +0 -0
- data/{runtime/spec → core_spec}/language/fixtures/super.rb +0 -0
- data/{runtime/spec → core_spec}/language/hash_spec.rb +0 -0
- data/{runtime/spec → core_spec}/language/if_spec.rb +0 -0
- data/{runtime/spec → core_spec}/language/loop_spec.rb +0 -0
- data/{runtime/spec → core_spec}/language/next_spec.rb +0 -0
- data/{runtime/spec → core_spec}/language/or_spec.rb +0 -0
- data/{runtime/spec → core_spec}/language/predefined_spec.rb +0 -0
- data/{runtime/spec → core_spec}/language/regexp/interpolation_spec.rb +8 -0
- data/{runtime/spec → core_spec}/language/regexp_spec.rb +0 -0
- data/{runtime/spec → core_spec}/language/send_spec.rb +0 -0
- data/{runtime/spec → core_spec}/language/string_spec.rb +0 -0
- data/{runtime/spec → core_spec}/language/super_spec.rb +0 -0
- data/{runtime/spec → core_spec}/language/symbol_spec.rb +0 -0
- data/{runtime/spec → core_spec}/language/undef_spec.rb +0 -0
- data/{runtime/spec → core_spec}/language/unless_spec.rb +0 -0
- data/{runtime/spec → core_spec}/language/until_spec.rb +0 -0
- data/core_spec/language/variables_spec.rb +112 -0
- data/{runtime/spec → core_spec}/language/versions/hash_1.9.rb +0 -0
- data/{runtime/spec → core_spec}/language/while_spec.rb +0 -0
- data/{runtime/spec → core_spec}/opal/opal/defined_spec.rb +0 -0
- data/{runtime/spec → core_spec}/opal/opal/function_spec.rb +0 -0
- data/{runtime/spec → core_spec}/opal/opal/native_spec.rb +0 -0
- data/{runtime/spec → core_spec}/opal/opal/null_spec.rb +0 -0
- data/{runtime/spec → core_spec}/opal/opal/number_spec.rb +0 -0
- data/{runtime/spec → core_spec}/opal/opal/object_spec.rb +0 -0
- data/{runtime/spec → core_spec}/opal/opal/string_spec.rb +0 -0
- data/{runtime/spec → core_spec}/opal/opal/typeof_spec.rb +0 -0
- data/{runtime/spec → core_spec}/opal/opal/undefined_spec.rb +0 -0
- data/{runtime/spec → core_spec}/opal/true/case_compare_spec.rb +0 -0
- data/{runtime/spec → core_spec}/opal/true/class_spec.rb +0 -0
- data/{docs/spec_runner.html → core_spec/release_runner.html} +4 -3
- data/core_spec/runner.html +16 -0
- data/core_spec/spec_helper.rb +23 -0
- data/lib/opal.rb +85 -2
- data/lib/opal/builder.rb +129 -46
- data/lib/opal/context.rb +47 -26
- data/lib/opal/dependency_builder.rb +113 -14
- data/lib/opal/environment.rb +40 -45
- data/lib/opal/parser/grammar.rb +2296 -2254
- data/lib/opal/parser/grammar.y +27 -8
- data/lib/opal/parser/lexer.rb +12 -3
- data/lib/opal/parser/parser.rb +117 -30
- data/lib/opal/parser/scope.rb +2 -2
- data/lib/opal/version.rb +1 -1
- data/opal.gemspec +3 -8
- data/spec/grammar/masgn_spec.rb +37 -0
- metadata +177 -227
- data/index.html +0 -434
- data/lib/opal/command.rb +0 -73
- data/runtime/README.md +0 -25
- data/runtime/corelib/boolean.rb +0 -44
- data/runtime/corelib/class.rb +0 -43
- data/runtime/corelib/complex.rb +0 -2
- data/runtime/corelib/dir.rb +0 -29
- data/runtime/corelib/enumerable.rb +0 -316
- data/runtime/corelib/enumerator.rb +0 -80
- data/runtime/corelib/error.rb +0 -25
- data/runtime/corelib/module.rb +0 -171
- data/runtime/corelib/native.rb +0 -50
- data/runtime/corelib/object.rb +0 -21
- data/runtime/corelib/time.rb +0 -196
- data/runtime/gemlib/alpha.rb +0 -5
- data/runtime/gemlib/kernel.rb +0 -17
- data/runtime/gemlib/load_order +0 -2
- data/runtime/kernel/class.js +0 -256
- data/runtime/kernel/debug.js +0 -42
- data/runtime/kernel/init.js +0 -114
- data/runtime/kernel/load_order +0 -5
- data/runtime/kernel/loader.js +0 -151
- data/runtime/kernel/runtime.js +0 -414
- data/runtime/spec/language/variables_spec.rb +0 -28
- data/runtime/spec/library/stringscanner/scan_spec.rb +0 -36
- data/runtime/spec/opal/forwardable/def_instance_delegator_spec.rb +0 -49
- data/runtime/spec/spec_helper.rb +0 -25
- data/runtime/stdlib/base64.rb +0 -91
- data/runtime/stdlib/date.rb +0 -4
- data/runtime/stdlib/dev.rb +0 -171
- data/runtime/stdlib/forwardable.rb +0 -33
- data/runtime/stdlib/optparse.rb +0 -0
- data/runtime/stdlib/pp.rb +0 -6
- data/runtime/stdlib/racc/parser.rb +0 -159
- data/runtime/stdlib/rbconfig.rb +0 -0
- data/runtime/stdlib/si.rb +0 -17
- data/runtime/stdlib/strscan.rb +0 -53
- data/runtime/stdlib/uri.rb +0 -111
- data/runtime/stdlib/uri/common.rb +0 -1014
- data/runtime/stdlib/uri/ftp.rb +0 -261
- data/runtime/stdlib/uri/generic.rb +0 -1599
- data/runtime/stdlib/uri/http.rb +0 -106
- data/runtime/stdlib/uri/https.rb +0 -22
- data/runtime/stdlib/uri/ldap.rb +0 -260
- data/runtime/stdlib/uri/ldaps.rb +0 -20
- data/runtime/stdlib/uri/mailto.rb +0 -280
- data/spec/builder/output_path_spec.rb +0 -50
@@ -1,28 +0,0 @@
|
|
1
|
-
require File.expand_path('../../spec_helper', __FILE__)
|
2
|
-
|
3
|
-
describe "Basic assignment" do
|
4
|
-
it "allows the rhs to be assigned to the lhs" do
|
5
|
-
a = nil
|
6
|
-
a.should == nil
|
7
|
-
end
|
8
|
-
|
9
|
-
it "assigns nil to lhs when rhs is an empty expression" do
|
10
|
-
a = ()
|
11
|
-
a.should be_nil
|
12
|
-
end
|
13
|
-
|
14
|
-
it "assigns [] to lhs when rhs is an empty splat expression" do
|
15
|
-
a = *()
|
16
|
-
a.should == []
|
17
|
-
end
|
18
|
-
|
19
|
-
it "allows the assignment of the rhs to the lhs using the rhs splat operator" do
|
20
|
-
a = *nil; a.should == []
|
21
|
-
a = *1; a.should == [1]
|
22
|
-
a = *[]; a.should == []
|
23
|
-
a = *[1]; a.should == [1]
|
24
|
-
a = *[nil]; a.should == [nil]
|
25
|
-
a = *[[]]; a.should == [[]]
|
26
|
-
a = *[1,2]; a.should == [1,2]
|
27
|
-
end
|
28
|
-
end
|
@@ -1,36 +0,0 @@
|
|
1
|
-
require File.expand_path('../../../spec_helper', __FILE__)
|
2
|
-
#require 'strscan'
|
3
|
-
|
4
|
-
describe "StringScanner#scan" do
|
5
|
-
before :each do
|
6
|
-
@s = StringScanner.new("This is a test")
|
7
|
-
end
|
8
|
-
|
9
|
-
it "returns the matched string" do
|
10
|
-
@s.scan(/\w+/).should == "This"
|
11
|
-
@s.scan(/.../).should == " is"
|
12
|
-
@s.scan(//).should == ""
|
13
|
-
@s.scan(/\s+/).should == " "
|
14
|
-
end
|
15
|
-
|
16
|
-
it "treats ^ as matching from the beginning of the current position" do
|
17
|
-
@s.scan(/\w+/).should == "This"
|
18
|
-
@s.scan(/^\d/).should be_nil
|
19
|
-
@s.scan(/^\s/).should == " "
|
20
|
-
end
|
21
|
-
|
22
|
-
it "returns nil if there's no match" do
|
23
|
-
@s.scan(/\d/).should == nil
|
24
|
-
end
|
25
|
-
|
26
|
-
it "returns nil when there is no more to scan" do
|
27
|
-
@s.scan(/[\w\s]+/).should == "This is a test"
|
28
|
-
@s.scan(/\w+/).should be_nil
|
29
|
-
end
|
30
|
-
|
31
|
-
it "returns an empty string when the pattern matches empty" do
|
32
|
-
@s.scan(/.*/).should == "This is a test"
|
33
|
-
@s.scan(/.*/).should == ""
|
34
|
-
@s.scan(/./).should be_nil
|
35
|
-
end
|
36
|
-
end
|
@@ -1,49 +0,0 @@
|
|
1
|
-
require File.expand_path('../../../spec_helper', __FILE__)
|
2
|
-
#require 'forwardable'
|
3
|
-
|
4
|
-
#class ForwardableTest
|
5
|
-
#extend Forwardable
|
6
|
-
|
7
|
-
#def initialize
|
8
|
-
#@some_ivar = ['a', 'b', 'c']
|
9
|
-
#@blah = [1, 2, 3, 4, 5, 6]
|
10
|
-
#end
|
11
|
-
|
12
|
-
#def foo
|
13
|
-
#@some_ivar
|
14
|
-
#end
|
15
|
-
|
16
|
-
#def wizz
|
17
|
-
#@blah
|
18
|
-
#end
|
19
|
-
|
20
|
-
#def_instance_delegator :@some_ivar, :length
|
21
|
-
#def_instance_delegator :@blah, :length, :blah
|
22
|
-
|
23
|
-
#def_instance_delegator :foo, :reverse
|
24
|
-
#def_instance_delegator :wizz, :reverse, :fizz
|
25
|
-
#end
|
26
|
-
|
27
|
-
describe "Forwardable#def_instance_delegator" do
|
28
|
-
before do
|
29
|
-
@tester = ForwardableTest.new
|
30
|
-
end
|
31
|
-
|
32
|
-
it "should define new instance methods" do
|
33
|
-
@tester.respond_to?(:length).should be_true
|
34
|
-
@tester.respond_to?(:blah).should be_true
|
35
|
-
|
36
|
-
@tester.respond_to?(:reverse).should be_true
|
37
|
-
@tester.respond_to?(:fizz).should be_true
|
38
|
-
end
|
39
|
-
|
40
|
-
it "should forward method calls to given ivars" do
|
41
|
-
@tester.length.should == 3
|
42
|
-
@tester.blah.should == 6
|
43
|
-
end
|
44
|
-
|
45
|
-
it "should forward method calls to given accessors" do
|
46
|
-
@tester.reverse.should == ['c', 'b', 'a']
|
47
|
-
@tester.fizz.should == [6, 5, 4, 3, 2, 1]
|
48
|
-
end
|
49
|
-
end
|
data/runtime/spec/spec_helper.rb
DELETED
@@ -1,25 +0,0 @@
|
|
1
|
-
# make sure these tests are indeed running inside opal, not any other
|
2
|
-
# ruby engine.
|
3
|
-
#unless RUBY_ENGINE =~ /opal/
|
4
|
-
# abort <<-EOS
|
5
|
-
#Opal Tests
|
6
|
-
#==========
|
7
|
-
#
|
8
|
-
#These tests MUST be run inside opal, not `#{RUBY_ENGINE}' engine
|
9
|
-
#
|
10
|
-
#To run Array#first tests, for example:
|
11
|
-
#
|
12
|
-
# opal spec/core/array/first_spec.rb
|
13
|
-
#
|
14
|
-
#EOS
|
15
|
-
#end
|
16
|
-
|
17
|
-
require 'opal/spec/autorun'
|
18
|
-
|
19
|
-
##
|
20
|
-
# Spec runner - if in browser, and spec_helper.rb is the main file then
|
21
|
-
# just run the spec files immediately.
|
22
|
-
if $0 == __FILE__
|
23
|
-
Dir['runtime/spec/**/*.rb'].each { |spec| require spec }
|
24
|
-
end
|
25
|
-
|
data/runtime/stdlib/base64.rb
DELETED
@@ -1,91 +0,0 @@
|
|
1
|
-
#
|
2
|
-
# = base64.rb: methods for base64-encoding and -decoding strings
|
3
|
-
#
|
4
|
-
|
5
|
-
# The Base64 module provides for the encoding (#encode64, #strict_encode64,
|
6
|
-
# #urlsafe_encode64) and decoding (#decode64, #strict_decode64,
|
7
|
-
# #urlsafe_decode64) of binary data using a Base64 representation.
|
8
|
-
#
|
9
|
-
# == Example
|
10
|
-
#
|
11
|
-
# A simple encoding and decoding.
|
12
|
-
#
|
13
|
-
# require "base64"
|
14
|
-
#
|
15
|
-
# enc = Base64.encode64('Send reinforcements')
|
16
|
-
# # -> "U2VuZCByZWluZm9yY2VtZW50cw==\n"
|
17
|
-
# plain = Base64.decode64(enc)
|
18
|
-
# # -> "Send reinforcements"
|
19
|
-
#
|
20
|
-
# The purpose of using base64 to encode data is that it translates any
|
21
|
-
# binary data into purely printable characters.
|
22
|
-
|
23
|
-
module Base64
|
24
|
-
module_function
|
25
|
-
|
26
|
-
# Returns the Base64-encoded version of +bin+.
|
27
|
-
# This method complies with RFC 2045.
|
28
|
-
# Line feeds are added to every 60 encoded charactors.
|
29
|
-
#
|
30
|
-
# require 'base64'
|
31
|
-
# Base64.encode64("Now is the time for all good coders\nto learn Ruby")
|
32
|
-
#
|
33
|
-
# <i>Generates:</i>
|
34
|
-
#
|
35
|
-
# Tm93IGlzIHRoZSB0aW1lIGZvciBhbGwgZ29vZCBjb2RlcnMKdG8gbGVhcm4g
|
36
|
-
# UnVieQ==
|
37
|
-
def encode64(bin)
|
38
|
-
[bin].pack("m")
|
39
|
-
end
|
40
|
-
|
41
|
-
# Returns the Base64-decoded version of +str+.
|
42
|
-
# This method complies with RFC 2045.
|
43
|
-
# Characters outside the base alphabet are ignored.
|
44
|
-
#
|
45
|
-
# require 'base64'
|
46
|
-
# str = 'VGhpcyBpcyBsaW5lIG9uZQpUaGlzIG' +
|
47
|
-
# 'lzIGxpbmUgdHdvClRoaXMgaXMgbGlu' +
|
48
|
-
# 'ZSB0aHJlZQpBbmQgc28gb24uLi4K'
|
49
|
-
# puts Base64.decode64(str)
|
50
|
-
#
|
51
|
-
# <i>Generates:</i>
|
52
|
-
#
|
53
|
-
# This is line one
|
54
|
-
# This is line two
|
55
|
-
# This is line three
|
56
|
-
# And so on...
|
57
|
-
def decode64(str)
|
58
|
-
str.unpack("m").first
|
59
|
-
end
|
60
|
-
|
61
|
-
# Returns the Base64-encoded version of +bin+.
|
62
|
-
# This method complies with RFC 4648.
|
63
|
-
# No line feeds are added.
|
64
|
-
def strict_encode64(bin)
|
65
|
-
[bin].pack("m0")
|
66
|
-
end
|
67
|
-
|
68
|
-
# Returns the Base64-decoded version of +str+.
|
69
|
-
# This method complies with RFC 4648.
|
70
|
-
# ArgumentError is raised if +str+ is incorrectly padded or contains
|
71
|
-
# non-alphabet characters. Note that CR or LF are also rejected.
|
72
|
-
def strict_decode64(str)
|
73
|
-
str.unpack("m0").first
|
74
|
-
end
|
75
|
-
|
76
|
-
# Returns the Base64-encoded version of +bin+.
|
77
|
-
# This method complies with ``Base 64 Encoding with URL and Filename Safe
|
78
|
-
# Alphabet'' in RFC 4648.
|
79
|
-
# The alphabet uses '-' instead of '+' and '_' instead of '/'.
|
80
|
-
def urlsafe_encode64(bin)
|
81
|
-
strict_encode64(bin).tr("+/", "-_")
|
82
|
-
end
|
83
|
-
|
84
|
-
# Returns the Base64-decoded version of +str+.
|
85
|
-
# This method complies with ``Base 64 Encoding with URL and Filename Safe
|
86
|
-
# Alphabet'' in RFC 4648.
|
87
|
-
# The alphabet uses '-' instead of '+' and '_' instead of '/'.
|
88
|
-
def urlsafe_decode64(str)
|
89
|
-
strict_decode64(str.tr("-_", "+/"))
|
90
|
-
end
|
91
|
-
end
|
data/runtime/stdlib/date.rb
DELETED
data/runtime/stdlib/dev.rb
DELETED
@@ -1,171 +0,0 @@
|
|
1
|
-
require 'opal/lexer'
|
2
|
-
|
3
|
-
module Opal
|
4
|
-
|
5
|
-
def self.compile(source)
|
6
|
-
res = Parser.new.parse source, :method_missing => true
|
7
|
-
res
|
8
|
-
end
|
9
|
-
|
10
|
-
def self.run_ruby_content(source, filename = "(opal)")
|
11
|
-
js = compile source
|
12
|
-
`opal.run(new Function("(" + js +
|
13
|
-
")(opal.runtime, opal.runtime.top, '')"));`
|
14
|
-
|
15
|
-
nil
|
16
|
-
end
|
17
|
-
|
18
|
-
# Load the ruby code at the remote url, parse and run it. This is typically
|
19
|
-
# used when loading a script tag of type text/ruby. The filename given in the
|
20
|
-
# tag is used as the actual filename
|
21
|
-
#
|
22
|
-
# @param [String] filename
|
23
|
-
def self.run_remote_content(filename)
|
24
|
-
`var xhr;
|
25
|
-
|
26
|
-
if (window.ActiveXObject)
|
27
|
-
xhr = new window.ActiveXObject('Microsoft.XMLHTTP');
|
28
|
-
else
|
29
|
-
xhr = new XMLHttpRequest();
|
30
|
-
|
31
|
-
xhr.open('GET', filename, true);
|
32
|
-
xhr.onreadystatechange = function() {
|
33
|
-
if (xhr.readyState == 4) {
|
34
|
-
opal.run(function() {
|
35
|
-
if (xhr.status == 0 || xhr.status == 200) {
|
36
|
-
#{ run_ruby_content `xhr.responseText`, filename };
|
37
|
-
} else {
|
38
|
-
#{ raise "LoadError: Cannot load: #{filename}" };
|
39
|
-
}
|
40
|
-
});
|
41
|
-
}
|
42
|
-
};
|
43
|
-
xhr.send(null);`
|
44
|
-
nil
|
45
|
-
end
|
46
|
-
|
47
|
-
def self.run_script_tags
|
48
|
-
`var scripts = document.getElementsByTagName('script');
|
49
|
-
|
50
|
-
for (var i = 0, ii = scripts.length; i < ii; i++) {
|
51
|
-
var script = scripts[i];
|
52
|
-
|
53
|
-
if (script.type == "text/ruby") {
|
54
|
-
if (script.src) {
|
55
|
-
#{ run_remote_content `script.getAttribute('src', 2)` };
|
56
|
-
} else {
|
57
|
-
opal.run(function() {
|
58
|
-
#{ run_ruby_content `script.innerHTML`, "(script-tag)" };
|
59
|
-
});
|
60
|
-
}
|
61
|
-
}
|
62
|
-
}`
|
63
|
-
|
64
|
-
nil
|
65
|
-
end
|
66
|
-
end
|
67
|
-
|
68
|
-
`opal.compile = function(source, options) {
|
69
|
-
console.log("need to compile some code");
|
70
|
-
return #{ Opal.compile `source` };
|
71
|
-
};`
|
72
|
-
|
73
|
-
`if (typeof window !== 'undefined') {
|
74
|
-
var runner = function() { #{ Opal.run_script_tags }; };
|
75
|
-
|
76
|
-
if (window.addEventListener) {
|
77
|
-
window.addEventListener('DOMContentLoaded', runner, false);
|
78
|
-
} else {
|
79
|
-
window.attachEvent('onload', runner);
|
80
|
-
}
|
81
|
-
}`
|
82
|
-
|
83
|
-
`var repl_running = false;
|
84
|
-
|
85
|
-
opal.browser_repl = function() {
|
86
|
-
if (repl_running) return;
|
87
|
-
repl_running = true;
|
88
|
-
|
89
|
-
var html = '<div id="opal-repl" style="position: fixed; width: 100%; height: '
|
90
|
-
+ '230px; bottom: 0px; overflow: scroll; border-top: 4px solid'
|
91
|
-
+ '#A5A5A5; left: 0px; padding: 4px; background-color: #E5E5E5;">'
|
92
|
-
|
93
|
-
+ '<div id="opal-stdout" style="font-family: \'Bitstream Vera Sans'
|
94
|
-
+ 'Mono\', \'Courier\', monospace; font-size: 12px"></div>'
|
95
|
-
|
96
|
-
+ '<span style="float: left; display: block; font-family: \'Bitst'
|
97
|
-
+ 'ream Vera Sans Mono\', \'Courier\', monospace; font-size: '
|
98
|
-
+ '12px">>> </span>'
|
99
|
-
|
100
|
-
+ '<input id="opal-stdin" type="text" style="position: relative;'
|
101
|
-
+ 'float: left; right: 0px; width: 500px; font-family: \'Bit'
|
102
|
-
+ 'stream Vera Sans Mono\', \'Courier\', monospace;'
|
103
|
-
+ 'font-size: 12px; outline-width: 0; outline: none; border:'
|
104
|
-
+ '0px; padding: 0px; margin: 0px; background: none" />'
|
105
|
-
|
106
|
-
+ '</div>';
|
107
|
-
|
108
|
-
var host = document.createElement('div');
|
109
|
-
host.innerHTML = html;
|
110
|
-
document.body.appendChild(host);
|
111
|
-
var opal_repl = document.getElementById('opal-repl');
|
112
|
-
|
113
|
-
var stdout = document.getElementById('opal-stdout');
|
114
|
-
var stdin = document.getElementById('opal-stdin');
|
115
|
-
var history = [], history_idx = 0;
|
116
|
-
setTimeout(function() { stdin.focus(); }, 0);
|
117
|
-
|
118
|
-
var puts_content = function(str) {
|
119
|
-
var elem = document.createElement('pre');
|
120
|
-
elem.textContent == null ? elem.innerText = str : elem.textContent = str;
|
121
|
-
elem.style.margin = "0px";
|
122
|
-
stdout.appendChild(elem);
|
123
|
-
};
|
124
|
-
|
125
|
-
var stdin_keydown = function(evt) {
|
126
|
-
if (evt.keyCode == 13) {
|
127
|
-
var ruby = stdin.value;
|
128
|
-
|
129
|
-
history.push(stdin.value);
|
130
|
-
history_idx = history.length;
|
131
|
-
stdin.value = '';
|
132
|
-
puts_content(">> " + ruby);
|
133
|
-
|
134
|
-
opal.run(function() {
|
135
|
-
puts_content("=> " + #{Opal.run_ruby_content(`ruby`, '(irb)').inspect}.toString());
|
136
|
-
});
|
137
|
-
|
138
|
-
opal_repl.scrollTop = opal_repl.scrollHeight;
|
139
|
-
}
|
140
|
-
else if (evt.keyCode == 38) {
|
141
|
-
if (history_idx > 0) {
|
142
|
-
history_idx -= 1;
|
143
|
-
stdin.value = history[history_idx];
|
144
|
-
}
|
145
|
-
}
|
146
|
-
else if (evt.keyCode == 40) {
|
147
|
-
if (history_idx < history.length - 1) {
|
148
|
-
history_idx += 1;
|
149
|
-
stdin.value = history[history_idx];
|
150
|
-
}
|
151
|
-
}
|
152
|
-
};
|
153
|
-
|
154
|
-
if (stdin.addEventListener) {
|
155
|
-
stdin.addEventListener('keydown', stdin_keydown, false);
|
156
|
-
} else {
|
157
|
-
stdin.attachEvent('onkeydown', stdin_keydown);
|
158
|
-
}
|
159
|
-
|
160
|
-
#{
|
161
|
-
def $stdout.puts(*a)
|
162
|
-
`for (var i = 0, ii = a.length; i < ii; i ++) {
|
163
|
-
puts_content(#{`a[i]`.to_s}.toString());
|
164
|
-
}`
|
165
|
-
nil
|
166
|
-
end
|
167
|
-
};
|
168
|
-
|
169
|
-
puts_content("opal REPL! Type command then <enter>.");
|
170
|
-
};`
|
171
|
-
|
@@ -1,33 +0,0 @@
|
|
1
|
-
module Forwardable
|
2
|
-
def instance_delegate(hash)
|
3
|
-
hash.each do |methods, accessor|
|
4
|
-
methods = [methods] unless methods.respond_to?(:each)
|
5
|
-
methods.each do |method|
|
6
|
-
def_instance_delegator(accessor, method)
|
7
|
-
end
|
8
|
-
end
|
9
|
-
end
|
10
|
-
|
11
|
-
def def_instance_delegators(accessor, *methods)
|
12
|
-
methods.each { |m| def_instance_delegator accessor, m }
|
13
|
-
end
|
14
|
-
|
15
|
-
def def_instance_delegator(accessor, method, ali = method)
|
16
|
-
accessor = accessor.to_s
|
17
|
-
if accessor.start_with? '@'
|
18
|
-
define_method ali do |args|
|
19
|
-
`args = $slice.call(arguments, 1);`
|
20
|
-
instance_variable_get(accessor).__send__(method, *args)
|
21
|
-
end
|
22
|
-
else
|
23
|
-
define_method ali do |args|
|
24
|
-
`args = $slice.call(arguments, 1);`
|
25
|
-
__send__(accessor).__send__(method, *args)
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
alias delegate instance_delegate
|
31
|
-
alias def_delegators def_instance_delegators
|
32
|
-
alias def_delegator def_instance_delegator
|
33
|
-
end
|