opal 0.0.1 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +10 -1
- data/.gitmodules +0 -0
- data/Opalfile +371 -0
- data/README.md +45 -0
- data/Rakefile +237 -34
- data/VERSION +1 -1
- data/bin/opal +13 -0
- data/demos/apps/browser_demo/index.html +11 -0
- data/demos/apps/browser_demo/lib/browser_demo.rb +31 -0
- data/demos/apps/simple_opal/Opalfile +13 -0
- data/demos/apps/simple_opal/index.html +11 -0
- data/demos/apps/simple_opal/lib/app_controller.rb +62 -0
- data/demos/apps/simple_opal/lib/main_window.rb +146 -0
- data/demos/browser/request/index.html +52 -0
- data/demos/browser/request/request.rb +48 -0
- data/gen/browser/__PROJECT_NAME__/index.html +10 -0
- data/gen/browser/__PROJECT_NAME__/lib/__PROJECT_NAME__.rb +1 -0
- data/lib/opal.rb +48 -3
- data/lib/opal/builders/base.rb +50 -0
- data/lib/opal/builders/css.rb +46 -0
- data/lib/opal/builders/javascript.rb +44 -0
- data/lib/opal/builders/opal.rb +79 -0
- data/lib/opal/builders/ruby.rb +50 -0
- data/lib/opal/builders/ruby/generate.rb +1851 -0
- data/lib/opal/builders/ruby/nodes.rb +210 -0
- data/lib/opal/builders/ruby/ruby.rb +916 -0
- data/lib/opal/builders/ruby/ruby_parser.rb +6008 -0
- data/lib/opal/builders/ruby/ruby_parser.rb.y +1451 -0
- data/lib/opal/models/build_item.rb +104 -0
- data/lib/opal/models/hash_struct.rb +40 -0
- data/lib/opal/models/project.rb +215 -0
- data/lib/opal/models/struct_accessors.rb +58 -0
- data/lib/opal/models/target.rb +176 -0
- data/lib/opal/opal/env/console.rb +66 -0
- data/lib/opal/opal/env/fs.rb +98 -0
- data/lib/opal/opal/env/object.rb +48 -0
- data/lib/opal/opal/environment.rb +139 -0
- data/lib/opal/opal/gen.rb +62 -0
- data/lib/opal/opal/opal.rb +68 -0
- data/lib/opal/opal/repl.rb +38 -0
- data/lib/opal/opalfile/dsl.rb +62 -0
- data/lib/opal/opalfile/opalfile.rb +133 -0
- data/lib/opal/opalfile/task.rb +96 -0
- data/lib/opal/opalfile/task_manager.rb +63 -0
- data/lib/opal/opalfile/task_scope.rb +52 -0
- data/lib/opal/rack/app_server.rb +119 -0
- data/opals/aristo/README.md +16 -0
- data/opals/browser/Opalfile +11 -0
- data/opals/browser/README.md +146 -0
- data/opals/browser/SIZZLE_LICESNSE.txt +148 -0
- data/opals/browser/lib/browser.rb +118 -0
- data/opals/browser/lib/browser/builder.rb +41 -0
- data/opals/browser/lib/browser/canvas_context.rb +115 -0
- data/opals/browser/lib/browser/dimensions.rb +50 -0
- data/opals/browser/lib/browser/document.rb +146 -0
- data/opals/browser/lib/browser/element.rb +487 -0
- data/opals/browser/lib/browser/element/attributes.rb +88 -0
- data/opals/browser/lib/browser/element/css.rb +290 -0
- data/opals/browser/lib/browser/element/form.rb +146 -0
- data/opals/browser/lib/browser/event/dom_events.rb +81 -0
- data/opals/browser/lib/browser/event/event.rb +177 -0
- data/opals/browser/lib/browser/event/trigger_events.rb +53 -0
- data/opals/browser/lib/browser/geometry.rb +97 -0
- data/opals/browser/lib/browser/json.rb +32 -0
- data/opals/browser/lib/browser/json_parse.js +321 -0
- data/opals/browser/lib/browser/request/request.rb +201 -0
- data/opals/browser/lib/browser/sizzle.js +1068 -0
- data/opals/browser/lib/browser/string.rb +42 -0
- data/opals/browser/lib/browser/touch.rb +37 -0
- data/{runtime/yaml.js → opals/browser/lib/browser/vml_context.js} +8 -8
- data/opals/browser/lib/browser/window.rb +36 -0
- data/opals/browser/spec/browser/browser_detection_spec.rb +7 -0
- data/opals/browser/spec/document/aref_spec.rb +110 -0
- data/opals/browser/spec/document/ready_spec.rb +16 -0
- data/opals/browser/spec/element/body_spec.rb +11 -0
- data/opals/browser/spec/element/clear_spec.rb +26 -0
- data/opals/browser/spec/element/empty_spec.rb +29 -0
- data/opals/browser/spec/element/has_class_spec.rb +40 -0
- data/opals/browser/spec/element/hidden_spec.rb +23 -0
- data/opals/browser/spec/element/hide_spec.rb +31 -0
- data/opals/browser/spec/element/remove_spec.rb +25 -0
- data/opals/browser/spec/element/show_spec.rb +31 -0
- data/opals/browser/spec/element/style_spec.rb +69 -0
- data/opals/browser/spec/element/toggle_spec.rb +31 -0
- data/opals/browser/spec/element/visible_spec.rb +23 -0
- data/opals/browser/spec/spec_helper.rb +1 -0
- data/opals/cherry_kit/Opalfile +6 -0
- data/opals/cherry_kit/bin/cherry_kit.rb +11 -0
- data/opals/cherry_kit/lib/cherry_kit.rb +29 -0
- data/opals/foundation/Opalfile +11 -0
- data/opals/foundation/bin/foundation.rb +12 -0
- data/opals/foundation/lib/foundation.rb +32 -0
- data/opals/foundation/lib/foundation/__table_view_desktop/outline_view.rb +57 -0
- data/opals/foundation/lib/foundation/__table_view_desktop/table_column.rb +59 -0
- data/opals/foundation/lib/foundation/__table_view_desktop/table_header_view.rb +34 -0
- data/opals/foundation/lib/foundation/__table_view_desktop/table_view.rb +304 -0
- data/opals/foundation/lib/foundation/controllers/array_controller.rb +54 -0
- data/opals/foundation/lib/foundation/controllers/controller.rb +74 -0
- data/opals/foundation/lib/foundation/controllers/controller_selection_proxy.rb +67 -0
- data/opals/foundation/lib/foundation/controllers/object_controller.rb +145 -0
- data/opals/foundation/lib/foundation/controllers/view.rb +40 -0
- data/opals/foundation/lib/foundation/core/application.rb +476 -0
- data/opals/foundation/lib/foundation/core/attributes.rb +146 -0
- data/opals/foundation/lib/foundation/core/bindings.rb +125 -0
- data/opals/foundation/lib/foundation/core/builder.rb +101 -0
- data/opals/foundation/lib/foundation/core/event.rb +112 -0
- data/opals/foundation/lib/foundation/core/index_path.rb +49 -0
- data/opals/foundation/lib/foundation/core/index_set.rb +97 -0
- data/opals/foundation/lib/foundation/core/notification.rb +113 -0
- data/opals/foundation/lib/foundation/core/observable.rb +275 -0
- data/opals/foundation/lib/foundation/core/observable_array.rb +30 -0
- data/opals/foundation/lib/foundation/core/responder.rb +85 -0
- data/opals/foundation/lib/foundation/core/run_loop.rb +89 -0
- data/opals/foundation/lib/foundation/core/touch.rb +95 -0
- data/opals/foundation/lib/foundation/gestures/gesture_recognizer.rb +35 -0
- data/opals/foundation/lib/foundation/rendering/render_context.rb +100 -0
- data/opals/foundation/lib/foundation/rendering/renderer.rb +137 -0
- data/opals/foundation/lib/foundation/rendering/root_theme.rb +77 -0
- data/opals/foundation/lib/foundation/rendering/root_theme/button.rb +62 -0
- data/opals/foundation/lib/foundation/rendering/root_theme/control.rb +72 -0
- data/opals/foundation/lib/foundation/rendering/root_theme/label.rb +54 -0
- data/opals/foundation/lib/foundation/rendering/root_theme/scroller.rb +58 -0
- data/opals/foundation/lib/foundation/rendering/root_theme/slider.rb +72 -0
- data/opals/foundation/lib/foundation/rendering/root_theme/table_view.rb +97 -0
- data/opals/foundation/lib/foundation/rendering/root_theme/text_field.rb +55 -0
- data/opals/foundation/lib/foundation/rendering/root_theme/view.rb +81 -0
- data/opals/foundation/lib/foundation/rendering/theme.rb +38 -0
- data/opals/foundation/lib/foundation/table_view/cell.rb +39 -0
- data/opals/foundation/lib/foundation/table_view/table.rb +171 -0
- data/opals/foundation/lib/foundation/views/button.rb +63 -0
- data/opals/foundation/lib/foundation/views/checkbox.rb +28 -0
- data/opals/foundation/lib/foundation/views/clip.rb +47 -0
- data/opals/foundation/lib/foundation/views/control.rb +199 -0
- data/opals/foundation/lib/foundation/views/label.rb +54 -0
- data/opals/foundation/lib/foundation/views/scroll.rb +294 -0
- data/opals/foundation/lib/foundation/views/scroll_view_desktop.rb +152 -0
- data/opals/foundation/lib/foundation/views/scroller.rb +54 -0
- data/opals/foundation/lib/foundation/views/slider.rb +93 -0
- data/opals/foundation/lib/foundation/views/text_field.rb +83 -0
- data/opals/foundation/lib/foundation/views/view.rb +426 -0
- data/opals/foundation/lib/foundation/windows/window.rb +191 -0
- data/opals/foundation/resources/button/button.css +23 -0
- data/{runtime/init.js → opals/foundation/resources/foundation.css} +27 -33
- data/opals/foundation/resources/scroll/scroll.css +22 -0
- data/opals/foundation/resources/scroll_view/scroll_view.css +3 -0
- data/opals/foundation/resources/scroll_view/scroller.css +3 -0
- data/opals/foundation/resources/slider/regular/slider.css +3 -0
- data/opals/foundation/resources/slider/slider.css +27 -0
- data/opals/foundation/resources/table_view/outline_view.css +3 -0
- data/opals/foundation/resources/table_view/table_view.css +15 -0
- data/opals/foundation/resources/text_field/text_field.css +71 -0
- data/opals/foundation/spec/spec_helper.rb +1 -0
- data/opals/foundation/spec/system/attributes/get_attribute_spec.rb +69 -0
- data/opals/foundation/spec/system/attributes/get_path_spec.rb +44 -0
- data/opals/foundation/spec/system/attributes/set_path_spec.rb +24 -0
- data/opals/foundation/spec/system/attributes/set_spec.rb +58 -0
- data/opals/foundation/spec/system/bindings/bindings.rb +85 -0
- data/opals/foundation/spec/system/key_value_binding/bind_spec.rb +43 -0
- data/opals/foundation/spec/system/observable/dependant_keys_spec.rb +74 -0
- data/opals/foundation/spec/system/observable/observe_spec.rb +292 -0
- data/opals/foundation/spec/system/observable/remove_observer_spec.rb +60 -0
- data/opals/opal/Opalfile +14 -0
- data/opals/opal/spec/core/array/append_spec.rb +30 -0
- data/opals/opal/spec/core/array/assoc_spec.rb +29 -0
- data/opals/opal/spec/core/array/at_spec.rb +37 -0
- data/opals/opal/spec/core/array/clear_spec.rb +22 -0
- data/opals/opal/spec/core/array/collect_bang_spec.rb +27 -0
- data/opals/opal/spec/core/array/collect_spec.rb +27 -0
- data/opals/opal/spec/core/array/compact_spec.rb +15 -0
- data/opals/opal/spec/core/array/concat_spec.rb +15 -0
- data/opals/opal/spec/core/array/constructor_spec.rb +14 -0
- data/opals/opal/spec/core/array/each_spec.rb +9 -0
- data/opals/opal/spec/core/array/element_reference_spec.rb +4 -0
- data/opals/opal/spec/core/array/first_spec.rb +35 -0
- data/opals/opal/spec/core/array/include_spec.rb +9 -0
- data/opals/opal/spec/core/array/map_spec.rb +31 -0
- data/opals/opal/spec/core/builtin_constants/builtin_constants_spec.rb +7 -0
- data/opals/opal/spec/core/false/and_spec.rb +10 -0
- data/opals/opal/spec/core/false/inspect_spec.rb +6 -0
- data/opals/opal/spec/core/false/or_spec.rb +10 -0
- data/opals/opal/spec/core/false/to_s_spec.rb +6 -0
- data/opals/opal/spec/core/false/xor_spec.rb +10 -0
- data/opals/opal/spec/core/file/join_spec.rb +19 -0
- data/opals/opal/spec/core/kernel/instance_eval_spec.rb +0 -0
- data/opals/opal/spec/core/kernel/loop_spec.rb +24 -0
- data/opals/opal/spec/core/kernel/raise_spec.rb +0 -0
- data/opals/opal/spec/core/module/attr_accessor_spec.rb +28 -0
- data/opals/opal/spec/core/number/lt_spec.rb +12 -0
- data/opals/opal/spec/core/true/and_spec.rb +10 -0
- data/opals/opal/spec/core/true/inspect_spec.rb +6 -0
- data/opals/opal/spec/core/true/or_spec.rb +10 -0
- data/opals/opal/spec/core/true/to_s_spec.rb +6 -0
- data/opals/opal/spec/core/true/xor_spec.rb +10 -0
- data/opals/opal/spec/fixtures/super.rb +70 -0
- data/opals/opal/spec/language/____temp_remove_this.rb +12 -0
- data/opals/opal/spec/language/and_spec.rb +62 -0
- data/opals/opal/spec/language/array_spec.rb +52 -0
- data/opals/opal/spec/language/block_spec.rb +18 -0
- data/opals/opal/spec/language/break_spec.rb +36 -0
- data/opals/opal/spec/language/case_spec.rb +103 -0
- data/opals/opal/spec/language/def_spec.rb +11 -0
- data/opals/opal/spec/language/eigenclass_spec.rb +60 -0
- data/opals/opal/spec/language/hash_spec.rb +29 -0
- data/opals/opal/spec/language/if_spec.rb +54 -0
- data/opals/opal/spec/language/loop_spec.rb +11 -0
- data/opals/opal/spec/language/metaclass_spec.rb +21 -0
- data/opals/opal/spec/language/method_spec.rb +64 -0
- data/opals/opal/spec/language/next_spec.rb +25 -0
- data/opals/opal/spec/language/or_spec.rb +34 -0
- data/opals/opal/spec/language/redo_spec.rb +24 -0
- data/opals/opal/spec/language/rescue_spec.rb +20 -0
- data/opals/opal/spec/language/return_spec.rb +47 -0
- data/opals/opal/spec/language/string_spec.rb +25 -0
- data/opals/opal/spec/language/super_spec.rb +26 -0
- data/opals/opal/spec/language/until_spec.rb +157 -0
- data/opals/opal/spec/language/while_spec.rb +163 -0
- data/opals/opal/spec/spec_helper.rb +5 -0
- data/opals/runtime/Opalfile +68 -0
- data/opals/runtime/README.md +12 -0
- data/opals/runtime/docs/debugging.md +51 -0
- data/opals/runtime/lib/array.rb +1516 -0
- data/opals/runtime/lib/basic_object.rb +49 -0
- data/opals/runtime/lib/class.rb +54 -0
- data/opals/runtime/lib/dir.rb +36 -0
- data/opals/runtime/lib/error.rb +49 -0
- data/opals/runtime/lib/false_class.rb +52 -0
- data/opals/runtime/lib/file.rb +79 -0
- data/opals/runtime/lib/hash.rb +791 -0
- data/opals/runtime/lib/io.rb +39 -0
- data/opals/runtime/lib/kernel.rb +288 -0
- data/opals/runtime/lib/match_data.rb +36 -0
- data/opals/runtime/lib/module.rb +109 -0
- data/opals/runtime/lib/nil_class.rb +69 -0
- data/opals/runtime/lib/number.rb +398 -0
- data/opals/runtime/lib/proc.rb +77 -0
- data/opals/runtime/lib/range.rb +63 -0
- data/opals/runtime/lib/regexp.rb +111 -0
- data/opals/runtime/lib/ruby.rb +30 -0
- data/opals/runtime/lib/string.rb +328 -0
- data/opals/runtime/lib/symbol.rb +40 -0
- data/opals/runtime/lib/top_self.rb +33 -0
- data/opals/runtime/lib/true_class.rb +45 -0
- data/opals/runtime/runtime/browser.js +287 -0
- data/opals/runtime/runtime/debug.js +182 -0
- data/opals/runtime/runtime/opal.js +1010 -0
- data/opals/runtime/runtime/post_opal.js +1 -0
- data/opals/runtime/runtime/pre_opal.js +2 -0
- data/opals/runtime/runtime/server_side.js +50 -0
- data/opals/spec/LICENSE.txt +26 -0
- data/opals/spec/Opalfile +5 -0
- data/opals/spec/bin/spec.rb +43 -0
- data/opals/spec/lib/spec.rb +33 -0
- data/opals/spec/lib/spec/dsl.rb +41 -0
- data/opals/spec/lib/spec/example.rb +35 -0
- data/opals/spec/lib/spec/example/before_and_after_hooks.rb +81 -0
- data/opals/spec/lib/spec/example/errors.rb +42 -0
- data/opals/spec/lib/spec/example/example_group.rb +37 -0
- data/opals/spec/lib/spec/example/example_group_factory.rb +43 -0
- data/opals/spec/lib/spec/example/example_group_hierarchy.rb +45 -0
- data/opals/spec/lib/spec/example/example_group_methods.rb +142 -0
- data/opals/spec/lib/spec/example/example_group_proxy.rb +41 -0
- data/opals/spec/lib/spec/example/example_methods.rb +73 -0
- data/opals/spec/lib/spec/example/example_proxy.rb +48 -0
- data/opals/spec/lib/spec/expectations.rb +46 -0
- data/opals/spec/lib/spec/expectations/errors.rb +35 -0
- data/opals/spec/lib/spec/expectations/fail_with.rb +37 -0
- data/opals/spec/lib/spec/expectations/handler.rb +48 -0
- data/opals/spec/lib/spec/matchers.rb +50 -0
- data/opals/spec/lib/spec/matchers/be.rb +26 -0
- data/opals/spec/lib/spec/matchers/generated_descriptions.rb +47 -0
- data/opals/spec/lib/spec/matchers/operator_matcher.rb +66 -0
- data/opals/spec/lib/spec/runner.rb +48 -0
- data/opals/spec/lib/spec/runner/example_group_runner.rb +71 -0
- data/opals/spec/lib/spec/runner/formatter/html_formatter.rb +100 -0
- data/opals/spec/lib/spec/runner/formatter/terminal_formatter.rb +82 -0
- data/opals/spec/lib/spec/runner/options.rb +63 -0
- data/opals/spec/lib/spec/runner/reporter.rb +123 -0
- data/opals/spec/resources/index.html +25 -0
- data/opals/spec/resources/spec.css +132 -0
- data/spec/cherry_kit/iseq_spec.rb +38 -0
- data/spec/spec_helper.rb +16 -0
- data/spec/vienna_spec.rb +7 -0
- data/yard/index.html +43 -0
- data/yard/style.css +765 -0
- metadata +312 -49
- data/docs/jarv.rdoc +0 -27
- data/runtime/array.js +0 -153
- data/runtime/class.js +0 -469
- data/runtime/compar.js +0 -73
- data/runtime/dir.js +0 -115
- data/runtime/enum.js +0 -74
- data/runtime/file.js +0 -165
- data/runtime/gem.js +0 -241
- data/runtime/hash.js +0 -181
- data/runtime/load.js +0 -251
- data/runtime/module.js +0 -98
- data/runtime/number.js +0 -148
- data/runtime/object.js +0 -522
- data/runtime/opal.js +0 -200
- data/runtime/parse.js +0 -2218
- data/runtime/range.js +0 -56
- data/runtime/re.js +0 -91
- data/runtime/string.js +0 -199
- data/runtime/variable.js +0 -184
- data/runtime/vm.js +0 -1150
- data/tasks/build.rb +0 -16
@@ -0,0 +1,77 @@
|
|
1
|
+
#
|
2
|
+
# proc.rb
|
3
|
+
# vienna
|
4
|
+
#
|
5
|
+
# Created by Adam Beynon.
|
6
|
+
# Copyright 2010 Adam Beynon.
|
7
|
+
#
|
8
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
9
|
+
# of this software and associated documentation files (the "Software"), to deal
|
10
|
+
# in the Software without restriction, including without limitation the rights
|
11
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
12
|
+
# copies of the Software, and to permit persons to whom the Software is
|
13
|
+
# furnished to do so, subject to the following conditions:
|
14
|
+
#
|
15
|
+
# The above copyright notice and this permission notice shall be included in
|
16
|
+
# all copies or substantial portions of the Software.
|
17
|
+
#
|
18
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
19
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
20
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
21
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
22
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
23
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
24
|
+
# THE SOFTWARE.
|
25
|
+
#
|
26
|
+
|
27
|
+
class Proc
|
28
|
+
|
29
|
+
def to_proc
|
30
|
+
self
|
31
|
+
end
|
32
|
+
|
33
|
+
def call
|
34
|
+
`if (#{self}.__lambda__) {
|
35
|
+
try {
|
36
|
+
return #{self}.apply(#{self}.__self__, []);
|
37
|
+
}
|
38
|
+
catch (e) {
|
39
|
+
// first try and catch a break (from the lambda proc)
|
40
|
+
if (e.__keyword__ == 'break') {
|
41
|
+
//console.log("break!");
|
42
|
+
return e.opal_value;
|
43
|
+
}
|
44
|
+
|
45
|
+
// look for next statements
|
46
|
+
if (e.__keyword__ == 'next') {
|
47
|
+
return e.opal_value;
|
48
|
+
}
|
49
|
+
|
50
|
+
// next try and catch return error statement (simply return it)
|
51
|
+
if (e.__keyword__ == 'return') {
|
52
|
+
return e.opal_value;
|
53
|
+
}
|
54
|
+
|
55
|
+
// redo - simply recall block?
|
56
|
+
if (e.__keyword__ == 'redo') {
|
57
|
+
return arguments.callee.apply(#{self});
|
58
|
+
}
|
59
|
+
|
60
|
+
// worst case, rethrow error
|
61
|
+
throw e;
|
62
|
+
}
|
63
|
+
}
|
64
|
+
else {
|
65
|
+
//throw "cannot .call for non lambda block.. yet"
|
66
|
+
return #{self}.apply(#{self}.__self__);
|
67
|
+
}`
|
68
|
+
end
|
69
|
+
|
70
|
+
def to_s
|
71
|
+
`return "#<" + #{self}.class_name + ":" + #{self}.id + ">";`
|
72
|
+
end
|
73
|
+
|
74
|
+
def inspect
|
75
|
+
to_s
|
76
|
+
end
|
77
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
#
|
2
|
+
# range.rb
|
3
|
+
# vienna
|
4
|
+
#
|
5
|
+
# Created by Adam Beynon.
|
6
|
+
# Copyright 2010 Adam Beynon.
|
7
|
+
#
|
8
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
9
|
+
# of this software and associated documentation files (the "Software"), to deal
|
10
|
+
# in the Software without restriction, including without limitation the rights
|
11
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
12
|
+
# copies of the Software, and to permit persons to whom the Software is
|
13
|
+
# furnished to do so, subject to the following conditions:
|
14
|
+
#
|
15
|
+
# The above copyright notice and this permission notice shall be included in
|
16
|
+
# all copies or substantial portions of the Software.
|
17
|
+
#
|
18
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
19
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
20
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
21
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
22
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
23
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
24
|
+
# THE SOFTWARE.
|
25
|
+
#
|
26
|
+
|
27
|
+
class Range
|
28
|
+
|
29
|
+
def self.new(start, ending, exclusive)
|
30
|
+
`if (!#{exclusive}) {
|
31
|
+
#{exclusive} = #{false};
|
32
|
+
}`
|
33
|
+
`return #{self}.R(#{start}, #{ending}, #{exclusive}.r);`
|
34
|
+
end
|
35
|
+
|
36
|
+
def length
|
37
|
+
`return #{self}.__end__ - #{self}.__start__;`
|
38
|
+
end
|
39
|
+
|
40
|
+
def begin
|
41
|
+
`return #{self}.__start__;`
|
42
|
+
end
|
43
|
+
|
44
|
+
def end
|
45
|
+
`return #{self}.__end__;`
|
46
|
+
end
|
47
|
+
|
48
|
+
def ===(val)
|
49
|
+
include? val
|
50
|
+
end
|
51
|
+
|
52
|
+
def cover?(val)
|
53
|
+
include? val
|
54
|
+
end
|
55
|
+
|
56
|
+
def include?(val)
|
57
|
+
`return (#{self}.__start__ <= #{val} && #{val} <= #{self}.__real_end__) ? #{true} : #{false};`
|
58
|
+
end
|
59
|
+
|
60
|
+
def exclude_end?
|
61
|
+
`return #{self}.__exclusive__ ? #{true} : #{false};`
|
62
|
+
end
|
63
|
+
end
|
@@ -0,0 +1,111 @@
|
|
1
|
+
#
|
2
|
+
# regexp.rb
|
3
|
+
# vienna
|
4
|
+
#
|
5
|
+
# Created by Adam Beynon.
|
6
|
+
# Copyright 2010 Adam Beynon.
|
7
|
+
#
|
8
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
9
|
+
# of this software and associated documentation files (the "Software"), to deal
|
10
|
+
# in the Software without restriction, including without limitation the rights
|
11
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
12
|
+
# copies of the Software, and to permit persons to whom the Software is
|
13
|
+
# furnished to do so, subject to the following conditions:
|
14
|
+
#
|
15
|
+
# The above copyright notice and this permission notice shall be included in
|
16
|
+
# all copies or substantial portions of the Software.
|
17
|
+
#
|
18
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
19
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
20
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
21
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
22
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
23
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
24
|
+
# THE SOFTWARE.
|
25
|
+
#
|
26
|
+
|
27
|
+
# A Regexp holds a regular expression, used to match a pattern against strings.
|
28
|
+
# Regexps are created using the `/.../` and `%r{...}` literals, and by the
|
29
|
+
# {Regexp.new} constructor.
|
30
|
+
#
|
31
|
+
# ## Implementation
|
32
|
+
#
|
33
|
+
# Toll free bridged with native regexp object.
|
34
|
+
#
|
35
|
+
class Regexp
|
36
|
+
|
37
|
+
# Produce a nicely formatted string-version of `self`.
|
38
|
+
#
|
39
|
+
# @example
|
40
|
+
# /^abc/.inspect
|
41
|
+
# # => "/^abc/"
|
42
|
+
#
|
43
|
+
# @return [String] string
|
44
|
+
def inspect
|
45
|
+
`return #{self}.toString();`
|
46
|
+
end
|
47
|
+
|
48
|
+
# Equality - Two regexps are equal if their patterns are identical, they have
|
49
|
+
# the same character set code, and their {#casefold?} values are the same.
|
50
|
+
#
|
51
|
+
# @example
|
52
|
+
# /abc/ == /abc/x # => false
|
53
|
+
# /abc/ == /abc/i # => false
|
54
|
+
# /abc/ == /abc/n # => false
|
55
|
+
# /abc/u == /abc/n # => false
|
56
|
+
#
|
57
|
+
# @param [Regexp] other_regexp another regexp to comapre
|
58
|
+
# @return [Boolean]
|
59
|
+
def ==(other_regexp)
|
60
|
+
`return #{self}.toString() === #{other_regexp}.toString() ? #{true} : #{false};`
|
61
|
+
end
|
62
|
+
|
63
|
+
# Case equality - Synonym for {Regexp#=~} used in case statements.
|
64
|
+
#
|
65
|
+
# @example
|
66
|
+
# a = "HELLO"
|
67
|
+
# case a
|
68
|
+
# when /^[a-z]*$/; puts "Lower case"
|
69
|
+
# when /^[A-Z]*$/; puts "Upper case"
|
70
|
+
# else puts "Mixed case"
|
71
|
+
# end
|
72
|
+
#
|
73
|
+
# # => "Upper case"
|
74
|
+
#
|
75
|
+
# @param [String] str string to test
|
76
|
+
# @return [Boolean]
|
77
|
+
def ===(str)
|
78
|
+
`if (#{self}.exec(#{str})) {
|
79
|
+
return #{true};
|
80
|
+
} else {
|
81
|
+
return #{false};
|
82
|
+
}`
|
83
|
+
end
|
84
|
+
|
85
|
+
alias_method :eql?, :==
|
86
|
+
|
87
|
+
# Returns a {MatchData} object describing the match, or `nil` if there was no
|
88
|
+
# match. This is equivalent to retrieving the value of the special variable
|
89
|
+
# $~ following a normal match. If the second parameter is present, it
|
90
|
+
# specifies the position in the string to begin the search.
|
91
|
+
#
|
92
|
+
# @example
|
93
|
+
# /(.)(.)(.)/.match("abc")[2]
|
94
|
+
# # => "b"
|
95
|
+
# /(.)(.)/.match("abc")[2]
|
96
|
+
# # => "c"
|
97
|
+
#
|
98
|
+
# @todo Passing a block is not yet supported.
|
99
|
+
#
|
100
|
+
# @param [Sring] string to match against
|
101
|
+
# @return [MatchData, nil] result or nil
|
102
|
+
def match(string)
|
103
|
+
m = nil
|
104
|
+
`if (#{m} = #{self}.exec(#{string})) {
|
105
|
+
return #{MatchData.new m};
|
106
|
+
} else {
|
107
|
+
return #{nil};
|
108
|
+
}`
|
109
|
+
end
|
110
|
+
|
111
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
#
|
2
|
+
# ruby.rb
|
3
|
+
# vienna
|
4
|
+
#
|
5
|
+
# Created by Adam Beynon.
|
6
|
+
# Copyright 2010 Adam Beynon.
|
7
|
+
#
|
8
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
9
|
+
# of this software and associated documentation files (the "Software"), to deal
|
10
|
+
# in the Software without restriction, including without limitation the rights
|
11
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
12
|
+
# copies of the Software, and to permit persons to whom the Software is
|
13
|
+
# furnished to do so, subject to the following conditions:
|
14
|
+
#
|
15
|
+
# The above copyright notice and this permission notice shall be included in
|
16
|
+
# all copies or substantial portions of the Software.
|
17
|
+
#
|
18
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
19
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
20
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
21
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
22
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
23
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
24
|
+
# THE SOFTWARE.
|
25
|
+
#
|
26
|
+
|
27
|
+
# This file simply maintains "everything" else.. runtime constants etc.
|
28
|
+
|
29
|
+
# This depends on the platform.
|
30
|
+
RUBY_PLATFORM = `opal.ruby_platform`
|
@@ -0,0 +1,328 @@
|
|
1
|
+
#
|
2
|
+
# string.rb
|
3
|
+
# vienna
|
4
|
+
#
|
5
|
+
# Created by Adam Beynon.
|
6
|
+
# Copyright 2010 Adam Beynon.
|
7
|
+
#
|
8
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
9
|
+
# of this software and associated documentation files (the "Software"), to deal
|
10
|
+
# in the Software without restriction, including without limitation the rights
|
11
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
12
|
+
# copies of the Software, and to permit persons to whom the Software is
|
13
|
+
# furnished to do so, subject to the following conditions:
|
14
|
+
#
|
15
|
+
# The above copyright notice and this permission notice shall be included in
|
16
|
+
# all copies or substantial portions of the Software.
|
17
|
+
#
|
18
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
19
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
20
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
21
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
22
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
23
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
24
|
+
# THE SOFTWARE.
|
25
|
+
#
|
26
|
+
|
27
|
+
# A {String} object holds a sequence of bytes, typically representing
|
28
|
+
# characters.
|
29
|
+
#
|
30
|
+
# ## Implementation Details.
|
31
|
+
#
|
32
|
+
# For performance, strings in Opal are built directly on top of native
|
33
|
+
# javascript strings, so that they are in fact the same object. This has the
|
34
|
+
# side effect that all strings are immutable, that is, they cannot be changed.
|
35
|
+
# Most of the string methods that end in '!' for example are not implemented,
|
36
|
+
# but their counterparts are: {#upcase} exists, but {#upcase!} does not, for
|
37
|
+
# example.
|
38
|
+
class String
|
39
|
+
|
40
|
+
# Returns a new string object containing a copy of `str`.
|
41
|
+
#
|
42
|
+
# @param [String] str string to copy
|
43
|
+
# @return [String] result
|
44
|
+
def self.new(str = "")
|
45
|
+
`return new String(#{str});`
|
46
|
+
end
|
47
|
+
|
48
|
+
# Copy - Returns a new {String} constaining `num` copies of the receiver.
|
49
|
+
#
|
50
|
+
# @example
|
51
|
+
# "Ho! " * 3
|
52
|
+
# # => "Ho! Ho! Ho! "
|
53
|
+
#
|
54
|
+
# @param [Number] num number of copies
|
55
|
+
# @return [String] result
|
56
|
+
def *(num)
|
57
|
+
`var res = [];
|
58
|
+
for (var i = 0; i < #{num}; i++) {
|
59
|
+
res.push(#{self});
|
60
|
+
}
|
61
|
+
return res.join('');`
|
62
|
+
end
|
63
|
+
|
64
|
+
# Concatenation - Returns a new {String} containing `other_str` concatenated
|
65
|
+
# to `self`.
|
66
|
+
#
|
67
|
+
# @example
|
68
|
+
# "Hello from " + self.to_s
|
69
|
+
# # => "Hello from main"
|
70
|
+
#
|
71
|
+
# @param [String] other_str string to concatenate
|
72
|
+
# @return [String] result
|
73
|
+
def +(other_str)
|
74
|
+
`return #{self} + #{other_str};`
|
75
|
+
end
|
76
|
+
|
77
|
+
# Comparison - returns -1 if `other_str` is greater than, 0 if `other_str` is
|
78
|
+
# equal to, and 1 if `other_str` is less than `self`.
|
79
|
+
#
|
80
|
+
# @example
|
81
|
+
# "abcdef" <=> "abcde"
|
82
|
+
# # => 1
|
83
|
+
# "abcdef" <=> "abcdef"
|
84
|
+
# # => 0
|
85
|
+
# "abcdef" <=> "abcdefg"
|
86
|
+
# # => -1
|
87
|
+
# "abcdef" <=> "ABCDEF"
|
88
|
+
# # => 1
|
89
|
+
#
|
90
|
+
# @param [String] other_str string to compare
|
91
|
+
# @return [-1, 0, 1, nil] result
|
92
|
+
def <=>(other_str)
|
93
|
+
`if (!(#{other_str}.info & #{self}.TS)) return #{nil};
|
94
|
+
else if (#{self} > #{other_str}) return 1;
|
95
|
+
else if (#{self} < #{other_str}) return -1;
|
96
|
+
return 0;`
|
97
|
+
end
|
98
|
+
|
99
|
+
# Equality - if `other` is not a {String} return `false`. Otherwise, returns
|
100
|
+
# `true` if `self` <=> `other` returns zero.
|
101
|
+
#
|
102
|
+
# @param [String] other string to compare
|
103
|
+
# @return [Boolean] result
|
104
|
+
def ==(other)
|
105
|
+
`return (#{self}.valueOf() === #{other}.valueOf()) ? #{true} : #{false};`
|
106
|
+
end
|
107
|
+
|
108
|
+
# Returns a copy of `self` with the first character converted to uppercase and
|
109
|
+
# the remainder to lowercase.
|
110
|
+
#
|
111
|
+
# @example
|
112
|
+
# "hello".capitalize
|
113
|
+
# # => "Hello"
|
114
|
+
# "HELLO".capitalize
|
115
|
+
# # => "Hello"
|
116
|
+
# "123ABC".capitalize
|
117
|
+
# # => "123abc"
|
118
|
+
#
|
119
|
+
# @return [String]
|
120
|
+
def capitalize
|
121
|
+
`return #{self}[0].toUpperCase() + #{self}.substr(1).toLowerCase();`
|
122
|
+
end
|
123
|
+
|
124
|
+
# Case-inseneitive version of {String#<=>}.
|
125
|
+
#
|
126
|
+
# @example
|
127
|
+
# "abcdef".casecmp("abcde")
|
128
|
+
# # => 1
|
129
|
+
# "aBcDeF".casecmp("abcdef")
|
130
|
+
# # => 0
|
131
|
+
# "abcdef".casecmp("abcdefg")
|
132
|
+
# # => -1
|
133
|
+
# "abcdef".casecmp("ABCDEF")
|
134
|
+
# # => 0
|
135
|
+
#
|
136
|
+
# @param [String] other_str string to compare
|
137
|
+
# @return [-1, 0, 1, nil] result
|
138
|
+
def casecmp(other_str)
|
139
|
+
`var a = #{self}.toLowerCase(), b = #{other_str}.toLowerCase();
|
140
|
+
if (!(b.info & a.TS)) return #{nil};
|
141
|
+
else if (a > b) return 1;
|
142
|
+
else if (a < b) return -1;
|
143
|
+
return 0;`
|
144
|
+
end
|
145
|
+
|
146
|
+
# Returns a copy of `self` with all uppercase letters replaced with their
|
147
|
+
# lowercase counterparts.
|
148
|
+
#
|
149
|
+
# @example
|
150
|
+
# "hEllO".downcase
|
151
|
+
# # => "hello"
|
152
|
+
#
|
153
|
+
# @return [String] result
|
154
|
+
def downcase
|
155
|
+
`return #{self}.toLowerCase();`
|
156
|
+
end
|
157
|
+
|
158
|
+
# Returns `true` if `self` has a length of zero.
|
159
|
+
#
|
160
|
+
# @example
|
161
|
+
# "hello".empty?
|
162
|
+
# # => false
|
163
|
+
# "".empty?
|
164
|
+
# # => true
|
165
|
+
#
|
166
|
+
# @return [Boolean]
|
167
|
+
def empty?
|
168
|
+
`return #{self} == '' ? #{true} : #{false};`
|
169
|
+
end
|
170
|
+
|
171
|
+
# Returns `true` if `self` ends with a `suffix` given.
|
172
|
+
#
|
173
|
+
# @example
|
174
|
+
# "hello".end_with? "lo"
|
175
|
+
# # => true
|
176
|
+
#
|
177
|
+
# @param [String] suffix suffix to check
|
178
|
+
# @return [Boolean]
|
179
|
+
def end_with?(suffix = "")
|
180
|
+
`return (#{suffix} != '' && #{self}.lastIndexOf(#{suffix}) == (#{self}.length - #{suffix}.length)) ? #{true} : #{false};`
|
181
|
+
end
|
182
|
+
|
183
|
+
# Two strings are equal if they have the same length and content.
|
184
|
+
#
|
185
|
+
# @param [String] other string to comapre
|
186
|
+
# @return [Boolean]
|
187
|
+
def eql?(other)
|
188
|
+
`return (#{self} == #{other}) ? #{true} : #{false};`
|
189
|
+
end
|
190
|
+
|
191
|
+
# Returns true if `self` contains the given `other_str`.
|
192
|
+
#
|
193
|
+
# @example
|
194
|
+
# "hello".include? "lo"
|
195
|
+
# # => true
|
196
|
+
# "hello".include? "ol"
|
197
|
+
# # => false
|
198
|
+
# "hello".include? "h"
|
199
|
+
# # => true
|
200
|
+
#
|
201
|
+
# @param [String] other_str string to check for
|
202
|
+
# @return [Boolean]
|
203
|
+
def include?(other_str)
|
204
|
+
`var res = #{self}.indexOf(#{other_str});
|
205
|
+
if (res != -1) {
|
206
|
+
return #{true};
|
207
|
+
}
|
208
|
+
return #{false};`
|
209
|
+
end
|
210
|
+
|
211
|
+
# Returns the index of the first occurrence of the given `substring` or
|
212
|
+
# pattern (regexp) in `self`. Returns `nil` if not found. If the second
|
213
|
+
# parameter is present, it specifies the position in the string to begin the
|
214
|
+
# search.
|
215
|
+
#
|
216
|
+
# @todo Use of Regexp or offsets not yet implemented.
|
217
|
+
#
|
218
|
+
# @example
|
219
|
+
# "hello".index "e"
|
220
|
+
# # => 1
|
221
|
+
# "hello".index "lo"
|
222
|
+
# # => 3
|
223
|
+
# "hello".index "a"
|
224
|
+
# # => nil
|
225
|
+
#
|
226
|
+
# @param [String] substring string to look for
|
227
|
+
# @return [Number, nil] result
|
228
|
+
def index(substring)
|
229
|
+
`var res = #{self}.indexOf(#{substring});
|
230
|
+
if (res != -1) {
|
231
|
+
return res;
|
232
|
+
}
|
233
|
+
return #{nil};`
|
234
|
+
end
|
235
|
+
|
236
|
+
# Returns a printable version of `self`, surrounded by quote marks, with
|
237
|
+
# special characters escaped.
|
238
|
+
#
|
239
|
+
# @todo Does not yet escape special characters
|
240
|
+
#
|
241
|
+
# @example
|
242
|
+
# str = "hello"
|
243
|
+
# str.inspect
|
244
|
+
# # => "\"hello\""
|
245
|
+
#
|
246
|
+
# @return [String]
|
247
|
+
def inspect
|
248
|
+
`return '"' + #{self} + '"';`
|
249
|
+
end
|
250
|
+
|
251
|
+
# Returns the {Symbol} corresponding to `self`, creating the symbol if it did
|
252
|
+
# not previously exist.
|
253
|
+
#
|
254
|
+
# @example
|
255
|
+
# "Koala".to_sym
|
256
|
+
# # => :Koala
|
257
|
+
# s = 'cat'.to_sym
|
258
|
+
# # => :cat
|
259
|
+
# s == :cat
|
260
|
+
# # => true
|
261
|
+
# s = '@cat'.to_sym
|
262
|
+
# # => :@cat
|
263
|
+
# s == :@cat
|
264
|
+
# # => true
|
265
|
+
#
|
266
|
+
# This can also be used to create symbols that cannot be represented using the
|
267
|
+
# :xxxx notation.
|
268
|
+
#
|
269
|
+
# @example
|
270
|
+
# 'cat and dog'.to_sym
|
271
|
+
# # => :"cat and dog"
|
272
|
+
#
|
273
|
+
# @return [Symbol]
|
274
|
+
def intern
|
275
|
+
`return #{self}.Y(#{self});`
|
276
|
+
end
|
277
|
+
|
278
|
+
alias_method :to_sym, :intern
|
279
|
+
|
280
|
+
# Returns the character length of `str`.
|
281
|
+
#
|
282
|
+
# @return [Number] length of string
|
283
|
+
def length
|
284
|
+
`return #{self}.length;`
|
285
|
+
end
|
286
|
+
|
287
|
+
alias_method :size, :length
|
288
|
+
|
289
|
+
# Returns a copy of `self` with leading whitespace removed. See also
|
290
|
+
# {String#rstrip} and {String#strip}.
|
291
|
+
#
|
292
|
+
# @example
|
293
|
+
# " hello ".lstrip
|
294
|
+
# # => "hello "
|
295
|
+
# "hello".lstrip
|
296
|
+
# # => "hello"
|
297
|
+
#
|
298
|
+
# @return [String]
|
299
|
+
def lstrip
|
300
|
+
`return #{self}.replace(/^\s*/, "");`
|
301
|
+
end
|
302
|
+
|
303
|
+
# Returns a new string with the characters from `self` in reverse order.
|
304
|
+
#
|
305
|
+
# @example
|
306
|
+
# "stressed".reverse
|
307
|
+
# # => "desserts"
|
308
|
+
#
|
309
|
+
# @return [String]
|
310
|
+
def reverse
|
311
|
+
`return #{self}.split('').reverse().join('');`
|
312
|
+
end
|
313
|
+
|
314
|
+
|
315
|
+
|
316
|
+
def slice(start, finish)
|
317
|
+
`return #{self}.substr(#{start}, #{finish});`
|
318
|
+
end
|
319
|
+
|
320
|
+
def to_s
|
321
|
+
self
|
322
|
+
end
|
323
|
+
|
324
|
+
def split(str)
|
325
|
+
`return #{self}.split(#{str});`
|
326
|
+
end
|
327
|
+
|
328
|
+
end
|