opal 0.2.2 → 0.3.0
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 +5 -10
- data/LICENSE +75 -0
- data/README.md +55 -3
- data/Rakefile +62 -139
- data/bin/opal +7 -10
- data/gems/core/README.md +5 -0
- data/gems/core/Rakefile +7 -0
- data/gems/core/core.gemspec +13 -0
- data/gems/core/lib/core.rb +33 -0
- data/gems/core/lib/core/array.rb +1470 -0
- data/gems/core/lib/core/basic_object.rb +15 -0
- data/gems/core/lib/core/class.rb +31 -0
- data/gems/core/lib/core/dir.rb +26 -0
- data/gems/core/lib/core/error.rb +43 -0
- data/gems/core/lib/core/false_class.rb +21 -0
- data/gems/core/lib/core/file.rb +54 -0
- data/gems/core/lib/core/hash.rb +725 -0
- data/gems/core/lib/core/kernel.rb +240 -0
- data/gems/core/lib/core/module.rb +98 -0
- data/gems/core/lib/core/nil_class.rb +41 -0
- data/gems/core/lib/core/numeric.rb +370 -0
- data/gems/core/lib/core/proc.rb +11 -0
- data/gems/core/lib/core/range.rb +17 -0
- data/gems/core/lib/core/regexp.rb +18 -0
- data/gems/core/lib/core/string.rb +328 -0
- data/gems/core/lib/core/symbol.rb +15 -0
- data/gems/core/lib/core/top_self.rb +8 -0
- data/gems/core/lib/core/true_class.rb +20 -0
- data/gems/core/lib/core/vm.rb +16 -0
- data/{opals/opal/opal → gems/core}/spec/core/array/append_spec.rb +0 -0
- data/{opals/opal/opal → gems/core}/spec/core/array/assoc_spec.rb +0 -0
- data/{opals/opal/opal → gems/core}/spec/core/array/at_spec.rb +0 -0
- data/{opals/opal/opal → gems/core}/spec/core/array/clear_spec.rb +1 -1
- data/{opals/opal/opal → gems/core}/spec/core/array/collect_bang_spec.rb +0 -0
- data/{opals/opal/opal → gems/core}/spec/core/array/collect_spec.rb +0 -0
- data/gems/core/spec/core/array/compact_spec.rb +41 -0
- data/{opals/opal/opal → gems/core}/spec/core/array/concat_spec.rb +0 -0
- data/{opals/opal/opal → gems/core}/spec/core/array/constructor_spec.rb +0 -0
- data/{opals/opal/opal → gems/core}/spec/core/array/each_spec.rb +0 -0
- data/{opals/opal/opal → gems/core}/spec/core/array/element_reference_spec.rb +0 -0
- data/{opals/opal/opal → gems/core}/spec/core/array/first_spec.rb +1 -1
- data/{opals/opal/opal → gems/core}/spec/core/array/include_spec.rb +0 -0
- data/gems/core/spec/core/array/join_spec.rb +6 -0
- data/gems/core/spec/core/array/last_spec.rb +51 -0
- data/gems/core/spec/core/array/length_spec.rb +6 -0
- data/{opals/opal/opal → gems/core}/spec/core/array/map_spec.rb +2 -0
- data/gems/core/spec/core/array/reverse_spec.rb +6 -0
- data/{opals/opal/opal → gems/core}/spec/core/builtin_constants/builtin_constants_spec.rb +0 -0
- data/{opals/opal/opal → gems/core}/spec/core/false/and_spec.rb +0 -0
- data/{opals/opal/opal → gems/core}/spec/core/false/inspect_spec.rb +0 -0
- data/{opals/opal/opal → gems/core}/spec/core/false/or_spec.rb +0 -0
- data/{opals/opal/opal → gems/core}/spec/core/false/to_s_spec.rb +0 -0
- data/{opals/opal/opal → gems/core}/spec/core/false/xor_spec.rb +0 -0
- data/{opals/opal/opal → gems/core}/spec/core/file/join_spec.rb +1 -1
- data/gems/core/spec/core/hash/assoc_spec.rb +32 -0
- data/{opals/opal/opal → gems/core}/spec/core/kernel/instance_eval_spec.rb +0 -0
- data/{opals/opal/opal → gems/core}/spec/core/kernel/loop_spec.rb +0 -0
- data/{opals/opal/opal → gems/core}/spec/core/kernel/raise_spec.rb +0 -0
- data/{opals/opal/opal → gems/core}/spec/core/module/attr_accessor_spec.rb +0 -0
- data/{opals/opal/opal → gems/core}/spec/core/number/lt_spec.rb +0 -0
- data/gems/core/spec/core/string/sub_spec.rb +24 -0
- data/{opals/opal/opal → gems/core}/spec/core/true/and_spec.rb +0 -0
- data/{opals/opal/opal → gems/core}/spec/core/true/inspect_spec.rb +0 -0
- data/{opals/opal/opal → gems/core}/spec/core/true/or_spec.rb +0 -0
- data/{opals/opal/opal → gems/core}/spec/core/true/to_s_spec.rb +0 -0
- data/{opals/opal/opal → gems/core}/spec/core/true/xor_spec.rb +0 -0
- data/{opals/opal/opal → gems/core}/spec/language/and_spec.rb +2 -3
- data/{opals/opal/opal → gems/core}/spec/language/array_spec.rb +21 -5
- data/gems/core/spec/language/block_spec.rb +38 -0
- data/{opals/opal/opal → gems/core}/spec/language/break_spec.rb +0 -0
- data/gems/core/spec/language/case_spec.rb +103 -0
- data/{opals/opal/opal → gems/core}/spec/language/def_spec.rb +11 -1
- data/{opals/opal/opal → gems/core}/spec/language/eigenclass_spec.rb +0 -0
- data/gems/core/spec/language/file_spec.rb +13 -0
- data/gems/core/spec/language/fixtures/block.rb +21 -0
- data/gems/core/spec/language/fixtures/super.rb +293 -0
- data/{opals/opal/opal → gems/core}/spec/language/hash_spec.rb +0 -0
- data/{opals/opal/opal → gems/core}/spec/language/if_spec.rb +0 -0
- data/{opals/opal/opal → gems/core}/spec/language/loop_spec.rb +0 -0
- data/gems/core/spec/language/metaclass_spec.rb +21 -0
- data/{opals/opal/opal → gems/core}/spec/language/method_spec.rb +60 -0
- data/{opals/opal/opal → gems/core}/spec/language/next_spec.rb +0 -0
- data/{opals/opal/opal → gems/core}/spec/language/or_spec.rb +0 -0
- data/{opals/opal/opal → gems/core}/spec/language/redo_spec.rb +0 -0
- data/gems/core/spec/language/regexp_spec.rb +26 -0
- data/{opals/opal/opal → gems/core}/spec/language/rescue_spec.rb +0 -0
- data/{opals/opal/opal → gems/core}/spec/language/return_spec.rb +0 -0
- data/{opals/opal/opal → gems/core}/spec/language/string_spec.rb +0 -0
- data/gems/core/spec/language/super_spec.rb +32 -0
- data/{opals/opal/opal → gems/core}/spec/language/until_spec.rb +47 -47
- data/gems/core/spec/language/variables_spec.rb +155 -0
- data/{opals/opal/opal → gems/core}/spec/language/while_spec.rb +47 -47
- data/{opals/opal/opal → gems/core}/spec/spec_helper.rb +1 -1
- data/gems/core_fs/README.md +19 -0
- data/gems/dev/Rakefile +5 -0
- data/gems/dev/lib/dev.js +99 -0
- data/gems/dev/lib/dev/generator.js +1264 -0
- data/gems/dev/lib/dev/parser.js +979 -0
- data/gems/dev/lib/dev/ruby_parser.js +1088 -0
- data/gems/dev/lib/dev/ruby_parser.y +1267 -0
- data/gems/dev/lib/dev/string_scanner.js +38 -0
- data/gems/dev/tools/racc2js/README.md +39 -0
- data/gems/dev/tools/racc2js/math_parser.js +222 -0
- data/gems/dev/tools/racc2js/math_parser.rb +133 -0
- data/gems/dev/tools/racc2js/math_parser.y +28 -0
- data/gems/dev/tools/racc2js/parser.js +218 -0
- data/gems/dev/tools/racc2js/racc2js.rb +153 -0
- data/gems/json/README.md +4 -0
- data/gems/json/json.gemspec +14 -0
- data/gems/json/lib/json.rb +64 -0
- data/gems/json/lib/json/ext.rb +51 -0
- data/{opals/opal/browser/lib/browser/json_parse.js → gems/json/lib/json/json2.js} +197 -37
- data/gems/ospec/README.md +0 -0
- data/gems/ospec/lib/ospec.rb +6 -0
- data/gems/ospec/lib/ospec/autorun.rb +3 -0
- data/gems/ospec/lib/ospec/dsl.rb +15 -0
- data/gems/ospec/lib/ospec/example.rb +11 -0
- data/gems/ospec/lib/ospec/example/before_and_after_hooks.rb +56 -0
- data/gems/ospec/lib/ospec/example/errors.rb +17 -0
- data/gems/ospec/lib/ospec/example/example_group.rb +12 -0
- data/gems/ospec/lib/ospec/example/example_group_factory.rb +21 -0
- data/gems/ospec/lib/ospec/example/example_group_hierarchy.rb +20 -0
- data/{opals/opal/spec/lib/spec → gems/ospec/lib/ospec}/example/example_group_methods.rb +26 -68
- data/gems/ospec/lib/ospec/example/example_group_proxy.rb +14 -0
- data/gems/ospec/lib/ospec/example/example_methods.rb +46 -0
- data/gems/ospec/lib/ospec/example/example_proxy.rb +18 -0
- data/gems/ospec/lib/ospec/expectations.rb +19 -0
- data/gems/ospec/lib/ospec/expectations/errors.rb +8 -0
- data/gems/ospec/lib/ospec/expectations/fail_with.rb +8 -0
- data/gems/ospec/lib/ospec/expectations/handler.rb +27 -0
- data/gems/ospec/lib/ospec/matchers.rb +24 -0
- data/{opals/opal/Rakefile → gems/ospec/lib/ospec/matchers/be.rb} +0 -0
- data/gems/ospec/lib/ospec/matchers/generated_descriptions.rb +20 -0
- data/gems/ospec/lib/ospec/matchers/operator_matcher.rb +52 -0
- data/gems/ospec/lib/ospec/runner.rb +40 -0
- data/gems/ospec/lib/ospec/runner/example_group_runner.rb +44 -0
- data/{opals/opal/spec/lib/spec → gems/ospec/lib/ospec}/runner/formatter/html_formatter.rb +31 -40
- data/gems/ospec/lib/ospec/runner/formatter/terminal_formatter.rb +48 -0
- data/gems/ospec/lib/ospec/runner/options.rb +36 -0
- data/{opals/opal/spec/lib/spec → gems/ospec/lib/ospec}/runner/reporter.rb +23 -55
- data/gems/ospec/ospec.gemspec +0 -0
- data/gems/rquery/README.md +9 -0
- data/gems/rquery/lib/rquery.rb +10 -0
- data/gems/rquery/lib/rquery/ajax.rb +4 -0
- data/gems/rquery/lib/rquery/css.rb +96 -0
- data/gems/rquery/lib/rquery/document.rb +25 -0
- data/gems/rquery/lib/rquery/element.rb +292 -0
- data/gems/rquery/lib/rquery/event.rb +108 -0
- data/gems/rquery/lib/rquery/jquery.js +8177 -0
- data/gems/rquery/lib/rquery/request.rb +138 -0
- data/gems/rquery/lib/rquery/response.rb +49 -0
- data/gems/rquery/rquery.gemspec +16 -0
- data/lib/opal.js +1597 -0
- data/lib/opal.rb +6 -69
- data/lib/opal/builder.rb +115 -0
- data/lib/opal/bundle.rb +131 -0
- data/lib/opal/command.rb +11 -0
- data/lib/opal/context.rb +69 -0
- data/lib/opal/context/console.rb +12 -0
- data/lib/opal/context/file_system.rb +19 -0
- data/lib/opal/context/loader.rb +117 -0
- data/lib/opal/gem.rb +153 -0
- data/lib/opal/ruby/nodes.rb +1302 -0
- data/lib/opal/ruby/parser.rb +780 -0
- data/lib/opal/ruby/ruby_parser.rb +5170 -0
- data/lib/opal/ruby/ruby_parser.y +1298 -0
- data/opal.gemspec +11 -256
- metadata +179 -240
- data/.gitmodules +0 -6
- data/Opalfile +0 -384
- data/VERSION +0 -1
- data/demos/apps/browser_demo/index.html +0 -11
- data/demos/apps/browser_demo/lib/browser_demo.rb +0 -31
- data/demos/apps/simple_opal/Opalfile +0 -13
- data/demos/apps/simple_opal/index.html +0 -11
- data/demos/apps/simple_opal/lib/app_controller.rb +0 -62
- data/demos/apps/simple_opal/lib/main_window.rb +0 -146
- data/demos/browser/request/index.html +0 -52
- data/demos/browser/request/request.rb +0 -48
- data/gen/browser/__PROJECT_NAME__/Rakefile +0 -12
- data/gen/browser/__PROJECT_NAME__/index.html +0 -11
- data/gen/browser/__PROJECT_NAME__/javascripts/opal.debug.js +0 -4687
- data/gen/browser/__PROJECT_NAME__/javascripts/opal.min.js +0 -175
- data/gen/browser/__PROJECT_NAME__/lib/__PROJECT_NAME__.rb +0 -1
- data/lib/opal/builders/base.rb +0 -50
- data/lib/opal/builders/css.rb +0 -46
- data/lib/opal/builders/javascript.rb +0 -44
- data/lib/opal/builders/opal.rb +0 -79
- data/lib/opal/builders/ruby.rb +0 -50
- data/lib/opal/builders/ruby/generate.rb +0 -1851
- data/lib/opal/builders/ruby/nodes.rb +0 -210
- data/lib/opal/builders/ruby/ruby.rb +0 -916
- data/lib/opal/builders/ruby/ruby_parser.rb +0 -6008
- data/lib/opal/builders/ruby/ruby_parser.rb.y +0 -1451
- data/lib/opal/models/build_item.rb +0 -104
- data/lib/opal/models/hash_struct.rb +0 -40
- data/lib/opal/models/project.rb +0 -252
- data/lib/opal/models/struct_accessors.rb +0 -58
- data/lib/opal/models/target.rb +0 -176
- data/lib/opal/opal/build.rb +0 -169
- data/lib/opal/opal/env/console.rb +0 -66
- data/lib/opal/opal/env/fs.rb +0 -98
- data/lib/opal/opal/env/object.rb +0 -48
- data/lib/opal/opal/environment.rb +0 -139
- data/lib/opal/opal/gen.rb +0 -62
- data/lib/opal/opal/opal.rb +0 -75
- data/lib/opal/opal/repl.rb +0 -38
- data/lib/opal/opalfile/dsl.rb +0 -62
- data/lib/opal/opalfile/opalfile.rb +0 -133
- data/lib/opal/opalfile/task.rb +0 -96
- data/lib/opal/opalfile/task_manager.rb +0 -63
- data/lib/opal/opalfile/task_scope.rb +0 -52
- data/lib/opal/rack/app_server.rb +0 -119
- data/lib/opal/rake/opal_task.rb +0 -34
- data/opals/opal/README.md +0 -37
- data/opals/opal/browser/Opalfile +0 -11
- data/opals/opal/browser/README.md +0 -146
- data/opals/opal/browser/SIZZLE_LICESNSE.txt +0 -148
- data/opals/opal/browser/lib/browser.rb +0 -118
- data/opals/opal/browser/lib/browser/builder.rb +0 -41
- data/opals/opal/browser/lib/browser/canvas_context.rb +0 -115
- data/opals/opal/browser/lib/browser/dimensions.rb +0 -50
- data/opals/opal/browser/lib/browser/document.rb +0 -146
- data/opals/opal/browser/lib/browser/element.rb +0 -487
- data/opals/opal/browser/lib/browser/element/attributes.rb +0 -88
- data/opals/opal/browser/lib/browser/element/css.rb +0 -290
- data/opals/opal/browser/lib/browser/element/form.rb +0 -146
- data/opals/opal/browser/lib/browser/event/dom_events.rb +0 -81
- data/opals/opal/browser/lib/browser/event/event.rb +0 -177
- data/opals/opal/browser/lib/browser/event/trigger_events.rb +0 -53
- data/opals/opal/browser/lib/browser/geometry.rb +0 -97
- data/opals/opal/browser/lib/browser/json.rb +0 -32
- data/opals/opal/browser/lib/browser/request/request.rb +0 -201
- data/opals/opal/browser/lib/browser/sizzle.js +0 -1068
- data/opals/opal/browser/lib/browser/string.rb +0 -42
- data/opals/opal/browser/lib/browser/touch.rb +0 -37
- data/opals/opal/browser/lib/browser/vml_context.js +0 -33
- data/opals/opal/browser/lib/browser/window.rb +0 -36
- data/opals/opal/browser/spec/browser/browser_detection_spec.rb +0 -7
- data/opals/opal/browser/spec/document/aref_spec.rb +0 -110
- data/opals/opal/browser/spec/document/ready_spec.rb +0 -16
- data/opals/opal/browser/spec/element/body_spec.rb +0 -11
- data/opals/opal/browser/spec/element/clear_spec.rb +0 -26
- data/opals/opal/browser/spec/element/empty_spec.rb +0 -29
- data/opals/opal/browser/spec/element/has_class_spec.rb +0 -40
- data/opals/opal/browser/spec/element/hidden_spec.rb +0 -23
- data/opals/opal/browser/spec/element/hide_spec.rb +0 -31
- data/opals/opal/browser/spec/element/remove_spec.rb +0 -25
- data/opals/opal/browser/spec/element/show_spec.rb +0 -31
- data/opals/opal/browser/spec/element/style_spec.rb +0 -69
- data/opals/opal/browser/spec/element/toggle_spec.rb +0 -31
- data/opals/opal/browser/spec/element/visible_spec.rb +0 -23
- data/opals/opal/browser/spec/spec_helper.rb +0 -1
- data/opals/opal/opal/Opalfile +0 -14
- data/opals/opal/opal/spec/core/array/compact_spec.rb +0 -15
- data/opals/opal/opal/spec/fixtures/super.rb +0 -70
- data/opals/opal/opal/spec/language/____temp_remove_this.rb +0 -12
- data/opals/opal/opal/spec/language/block_spec.rb +0 -18
- data/opals/opal/opal/spec/language/case_spec.rb +0 -103
- data/opals/opal/opal/spec/language/metaclass_spec.rb +0 -21
- data/opals/opal/opal/spec/language/super_spec.rb +0 -26
- data/opals/opal/runtime/Opalfile +0 -78
- data/opals/opal/runtime/README.md +0 -12
- data/opals/opal/runtime/docs/debugging.md +0 -51
- data/opals/opal/runtime/lib/array.rb +0 -1516
- data/opals/opal/runtime/lib/basic_object.rb +0 -49
- data/opals/opal/runtime/lib/class.rb +0 -54
- data/opals/opal/runtime/lib/dir.rb +0 -36
- data/opals/opal/runtime/lib/error.rb +0 -49
- data/opals/opal/runtime/lib/false_class.rb +0 -52
- data/opals/opal/runtime/lib/file.rb +0 -79
- data/opals/opal/runtime/lib/hash.rb +0 -791
- data/opals/opal/runtime/lib/io.rb +0 -39
- data/opals/opal/runtime/lib/kernel.rb +0 -288
- data/opals/opal/runtime/lib/match_data.rb +0 -36
- data/opals/opal/runtime/lib/module.rb +0 -109
- data/opals/opal/runtime/lib/nil_class.rb +0 -69
- data/opals/opal/runtime/lib/number.rb +0 -398
- data/opals/opal/runtime/lib/proc.rb +0 -77
- data/opals/opal/runtime/lib/range.rb +0 -63
- data/opals/opal/runtime/lib/regexp.rb +0 -111
- data/opals/opal/runtime/lib/ruby.rb +0 -30
- data/opals/opal/runtime/lib/string.rb +0 -328
- data/opals/opal/runtime/lib/symbol.rb +0 -40
- data/opals/opal/runtime/lib/top_self.rb +0 -33
- data/opals/opal/runtime/lib/true_class.rb +0 -45
- data/opals/opal/runtime/runtime/browser.js +0 -287
- data/opals/opal/runtime/runtime/debug.js +0 -180
- data/opals/opal/runtime/runtime/opal.js +0 -1008
- data/opals/opal/runtime/runtime/post_opal.js +0 -1
- data/opals/opal/runtime/runtime/pre_opal.js +0 -2
- data/opals/opal/runtime/runtime/server_side.js +0 -50
- data/opals/opal/spec/LICENSE.txt +0 -26
- data/opals/opal/spec/Opalfile +0 -5
- data/opals/opal/spec/bin/spec.rb +0 -43
- data/opals/opal/spec/lib/spec.rb +0 -33
- data/opals/opal/spec/lib/spec/dsl.rb +0 -41
- data/opals/opal/spec/lib/spec/example.rb +0 -35
- data/opals/opal/spec/lib/spec/example/before_and_after_hooks.rb +0 -81
- data/opals/opal/spec/lib/spec/example/errors.rb +0 -42
- data/opals/opal/spec/lib/spec/example/example_group.rb +0 -37
- data/opals/opal/spec/lib/spec/example/example_group_factory.rb +0 -43
- data/opals/opal/spec/lib/spec/example/example_group_hierarchy.rb +0 -45
- data/opals/opal/spec/lib/spec/example/example_group_proxy.rb +0 -41
- data/opals/opal/spec/lib/spec/example/example_methods.rb +0 -73
- data/opals/opal/spec/lib/spec/example/example_proxy.rb +0 -48
- data/opals/opal/spec/lib/spec/expectations.rb +0 -46
- data/opals/opal/spec/lib/spec/expectations/errors.rb +0 -35
- data/opals/opal/spec/lib/spec/expectations/fail_with.rb +0 -37
- data/opals/opal/spec/lib/spec/expectations/handler.rb +0 -48
- data/opals/opal/spec/lib/spec/matchers.rb +0 -50
- data/opals/opal/spec/lib/spec/matchers/be.rb +0 -26
- data/opals/opal/spec/lib/spec/matchers/generated_descriptions.rb +0 -47
- data/opals/opal/spec/lib/spec/matchers/operator_matcher.rb +0 -66
- data/opals/opal/spec/lib/spec/runner.rb +0 -48
- data/opals/opal/spec/lib/spec/runner/example_group_runner.rb +0 -71
- data/opals/opal/spec/lib/spec/runner/formatter/terminal_formatter.rb +0 -82
- data/opals/opal/spec/lib/spec/runner/options.rb +0 -63
- data/opals/opal/spec/resources/index.html +0 -25
- data/opals/opal/spec/resources/spec.css +0 -132
- data/spec/cherry_kit/iseq_spec.rb +0 -38
- data/spec/spec_helper.rb +0 -16
- data/spec/vienna_spec.rb +0 -7
- data/yard/index.html +0 -43
- data/yard/style.css +0 -765
data/lib/opal/opalfile/task.rb
DELETED
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
#
|
|
2
|
-
# task.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
|
-
module Vienna
|
|
28
|
-
|
|
29
|
-
class Opalfile::Task
|
|
30
|
-
|
|
31
|
-
# action for task
|
|
32
|
-
attr_accessor :action, :prerequisites
|
|
33
|
-
|
|
34
|
-
def initialize(task_name, opalfile)
|
|
35
|
-
@task_name = task_name
|
|
36
|
-
@prerequisites = []
|
|
37
|
-
@opalfile = opalfile
|
|
38
|
-
@action = nil
|
|
39
|
-
@description = nil
|
|
40
|
-
@scope = opalfile.current_scope
|
|
41
|
-
@invoke_count = 0
|
|
42
|
-
end
|
|
43
|
-
|
|
44
|
-
def invoke_with_call_array(invocation_array, task_scope_instance)
|
|
45
|
-
# puts "invoking #{@task_name}"
|
|
46
|
-
@task_scope = task_scope_instance
|
|
47
|
-
# puts "\n##### #@task_name #{self}\n"
|
|
48
|
-
unless invocation_array.include? @task_name
|
|
49
|
-
# puts "||||| #{@task_name} actually running"
|
|
50
|
-
invocation_array << @task_name
|
|
51
|
-
|
|
52
|
-
invocation_array = invoke_prerequisites invocation_array
|
|
53
|
-
@invoke_count += 1
|
|
54
|
-
execute(task_scope_instance)
|
|
55
|
-
|
|
56
|
-
else
|
|
57
|
-
# puts "!!!!! #@task_name already run this task"
|
|
58
|
-
end
|
|
59
|
-
# puts "~~~~~ Finished #@task_name\n\n"
|
|
60
|
-
invocation_array
|
|
61
|
-
end
|
|
62
|
-
|
|
63
|
-
def invoke(task_scope_instance)
|
|
64
|
-
invoke_with_call_array [], task_scope_instance
|
|
65
|
-
end
|
|
66
|
-
|
|
67
|
-
def invoke_prerequisites(invocation_array)
|
|
68
|
-
@prerequisites.each do |pre|
|
|
69
|
-
|
|
70
|
-
ctx = Vienna::TaskScope.new
|
|
71
|
-
ctx.opalfile = @task_scope.opalfile
|
|
72
|
-
ctx.task_variables = @task_scope.task_variables
|
|
73
|
-
|
|
74
|
-
task = @task_scope.opalfile[pre, @scope]
|
|
75
|
-
|
|
76
|
-
@opalfile.task_scope_stack << ctx
|
|
77
|
-
|
|
78
|
-
invocation_array = task.invoke_with_call_array(invocation_array, ctx)
|
|
79
|
-
end
|
|
80
|
-
invocation_array
|
|
81
|
-
end
|
|
82
|
-
|
|
83
|
-
def execute(task_scope_instance)
|
|
84
|
-
if @action
|
|
85
|
-
task_scope_instance.instance_eval(&@action)
|
|
86
|
-
else
|
|
87
|
-
# puts "no action to run."
|
|
88
|
-
end
|
|
89
|
-
end
|
|
90
|
-
|
|
91
|
-
def to_s
|
|
92
|
-
"#<Task name=#@task_name, scope=#@scope prereq=#{@prerequisites.inspect}>"
|
|
93
|
-
end
|
|
94
|
-
|
|
95
|
-
end
|
|
96
|
-
end
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
#
|
|
2
|
-
# task_manager.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
|
-
module Vienna
|
|
28
|
-
|
|
29
|
-
class Opalfile
|
|
30
|
-
|
|
31
|
-
def define_task task_name, &block
|
|
32
|
-
if task_name.is_a? Hash
|
|
33
|
-
name = task_name.keys.first
|
|
34
|
-
dep = task_name[name]
|
|
35
|
-
else
|
|
36
|
-
name = task_name
|
|
37
|
-
dep = []
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
full_name = @namespace_scope.dup.push(name) * ":"
|
|
41
|
-
|
|
42
|
-
# musrt assign new task to avoid overriding task meaning in other
|
|
43
|
-
# opalfiles
|
|
44
|
-
task = (@tasks[full_name] = Task.new full_name, self)
|
|
45
|
-
task.action = block
|
|
46
|
-
task.prerequisites = dep
|
|
47
|
-
|
|
48
|
-
@last_desc = nil
|
|
49
|
-
end
|
|
50
|
-
|
|
51
|
-
def current_scope
|
|
52
|
-
@namespace_scope * ":"
|
|
53
|
-
end
|
|
54
|
-
|
|
55
|
-
def define_namespace(name)
|
|
56
|
-
# puts "in new namespace #{name}"
|
|
57
|
-
@namespace_scope.push name
|
|
58
|
-
yield
|
|
59
|
-
@namespace_scope.pop
|
|
60
|
-
end
|
|
61
|
-
|
|
62
|
-
end
|
|
63
|
-
end
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
#
|
|
2
|
-
# task_scope.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
|
-
module Vienna
|
|
28
|
-
|
|
29
|
-
# When we call each task, we instance_eval it into a scope so we can set
|
|
30
|
-
# various constants on that scope without effecing anything else....
|
|
31
|
-
# TaskScope is that context
|
|
32
|
-
class TaskScope
|
|
33
|
-
|
|
34
|
-
# access the task variables: hash of names => values
|
|
35
|
-
attr_reader :task_variables
|
|
36
|
-
|
|
37
|
-
# to maintain the righe opalfile for the current scope. The Task's actual
|
|
38
|
-
# opalfile might have some taks soverridden, so we cannot rely on using that
|
|
39
|
-
# opalfile to get prerequirement tasks. This task scope keeps us in the
|
|
40
|
-
# correct scope.
|
|
41
|
-
attr_accessor :opalfile
|
|
42
|
-
|
|
43
|
-
# custom setter. Actually set all variables in scope also
|
|
44
|
-
def task_variables=(task_variables)
|
|
45
|
-
@task_variables = task_variables
|
|
46
|
-
|
|
47
|
-
task_variables.each do |key, value|
|
|
48
|
-
instance_variable_set "@#{key}", value
|
|
49
|
-
end
|
|
50
|
-
end
|
|
51
|
-
end
|
|
52
|
-
end
|
data/lib/opal/rack/app_server.rb
DELETED
|
@@ -1,119 +0,0 @@
|
|
|
1
|
-
#
|
|
2
|
-
# app_server.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
|
-
require 'pp'
|
|
28
|
-
|
|
29
|
-
module Vienna
|
|
30
|
-
|
|
31
|
-
# App server for any opal project (single project)
|
|
32
|
-
class AppServer
|
|
33
|
-
|
|
34
|
-
attr_accessor :project
|
|
35
|
-
|
|
36
|
-
def initialize(project)
|
|
37
|
-
# we need rack
|
|
38
|
-
begin
|
|
39
|
-
require 'rack'
|
|
40
|
-
rescue LoadError
|
|
41
|
-
require 'rubygems'
|
|
42
|
-
require 'rack'
|
|
43
|
-
end
|
|
44
|
-
|
|
45
|
-
@project = project
|
|
46
|
-
|
|
47
|
-
# hash of paths => procs to return their result
|
|
48
|
-
@paths = {}
|
|
49
|
-
|
|
50
|
-
# we need to reload/rebuild our project!
|
|
51
|
-
path '/', '/index.html' do
|
|
52
|
-
# we need to rebuild, so do that
|
|
53
|
-
rebuild!
|
|
54
|
-
# simply return /index.html from the project_dir (once built)
|
|
55
|
-
file '/index.html'
|
|
56
|
-
end
|
|
57
|
-
|
|
58
|
-
# lets just return something to avoid missing file error
|
|
59
|
-
path '/favicon.ico' do
|
|
60
|
-
[200, {"Content-Type" => ::Rack::Mime.mime_type(File.extname('/favicon.ico'), 'text/plain')}, ""]
|
|
61
|
-
end
|
|
62
|
-
|
|
63
|
-
port = 3030
|
|
64
|
-
puts "Starting server on port #{port}"
|
|
65
|
-
::Rack::Handler::Mongrel.run self, :Port => port
|
|
66
|
-
end
|
|
67
|
-
|
|
68
|
-
# Rebuild our project
|
|
69
|
-
def rebuild!
|
|
70
|
-
@project.build!
|
|
71
|
-
end
|
|
72
|
-
|
|
73
|
-
# Project root/path
|
|
74
|
-
def project_root
|
|
75
|
-
@project_root ||= @project.project_root
|
|
76
|
-
end
|
|
77
|
-
|
|
78
|
-
# We map the full given path to the given action. Whenever a request for the
|
|
79
|
-
# given path is received, we run the given action and return the result.
|
|
80
|
-
#
|
|
81
|
-
# @param {String} path to resource - can take multiple strings
|
|
82
|
-
# @param {Proc} action to run and respond with
|
|
83
|
-
#
|
|
84
|
-
def path(*path, &action)
|
|
85
|
-
path.each do |path|
|
|
86
|
-
# puts "need to map path: #{path}"
|
|
87
|
-
@paths[path] = action
|
|
88
|
-
end
|
|
89
|
-
end
|
|
90
|
-
|
|
91
|
-
# Returns the content of the file, or method missing if it does not exist
|
|
92
|
-
def file(local_path)
|
|
93
|
-
path = File.join(project_root, local_path)
|
|
94
|
-
|
|
95
|
-
if File.exist? path
|
|
96
|
-
[200, {"Content-Type" => ::Rack::Mime.mime_type(File.extname(path), 'text/plain')}, File.read(path)]
|
|
97
|
-
else
|
|
98
|
-
raise "file doest exist: #{path}"
|
|
99
|
-
end
|
|
100
|
-
end
|
|
101
|
-
|
|
102
|
-
def call(env)
|
|
103
|
-
# @env = env
|
|
104
|
-
# pp env
|
|
105
|
-
request_path = env['REQUEST_PATH']
|
|
106
|
-
|
|
107
|
-
puts "accessing #{request_path}"
|
|
108
|
-
|
|
109
|
-
action = @paths[request_path]
|
|
110
|
-
|
|
111
|
-
if action
|
|
112
|
-
# puts "we have an action! #{request_path}"
|
|
113
|
-
action.call
|
|
114
|
-
else
|
|
115
|
-
file request_path
|
|
116
|
-
end
|
|
117
|
-
end
|
|
118
|
-
end
|
|
119
|
-
end
|
data/lib/opal/rake/opal_task.rb
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
require 'rake'
|
|
2
|
-
require 'rake/tasklib'
|
|
3
|
-
|
|
4
|
-
module Opal
|
|
5
|
-
module Rake
|
|
6
|
-
|
|
7
|
-
class OpalTask < ::Rake::TaskLib
|
|
8
|
-
|
|
9
|
-
attr_accessor :source
|
|
10
|
-
|
|
11
|
-
attr_accessor :destination
|
|
12
|
-
|
|
13
|
-
attr_accessor :options
|
|
14
|
-
|
|
15
|
-
def initialize(name = :opal)
|
|
16
|
-
@name = name
|
|
17
|
-
@options = []
|
|
18
|
-
@source = []
|
|
19
|
-
@destination = []
|
|
20
|
-
yield self if block_given?
|
|
21
|
-
|
|
22
|
-
define_rake_task
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
def define_rake_task
|
|
26
|
-
desc "Build opal files"
|
|
27
|
-
task(@name) do
|
|
28
|
-
puts "running opal build task"
|
|
29
|
-
Opal.build!(([@source] + [@destination] + [@options]).flatten)
|
|
30
|
-
end
|
|
31
|
-
end
|
|
32
|
-
end
|
|
33
|
-
end
|
|
34
|
-
end
|
data/opals/opal/README.md
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
Opal: Ruby compiler/runtime for the browser
|
|
2
|
-
=============================================
|
|
3
|
-
|
|
4
|
-
### NOTE: opal has been renamed from vienna. Vienna is now just a code name for the build tools
|
|
5
|
-
|
|
6
|
-
Opal is the runtime/standard lib for ruby in the browser.
|
|
7
|
-
|
|
8
|
-
Installing
|
|
9
|
-
-----------
|
|
10
|
-
|
|
11
|
-
# Insall gem from gemcutter/rubygems
|
|
12
|
-
sudo gem install opal
|
|
13
|
-
|
|
14
|
-
Trying out
|
|
15
|
-
----------
|
|
16
|
-
To make a test project, use the following command where project_name is the name of the project to use.
|
|
17
|
-
|
|
18
|
-
# make the project
|
|
19
|
-
opal new project_name
|
|
20
|
-
# jump into the project
|
|
21
|
-
cd project_name
|
|
22
|
-
|
|
23
|
-
The project also creates a Rakefile with an 'opal' task. Run this task, and then opal will continuously watch your ruby file for changes, and then recompile it everytime you change the code.
|
|
24
|
-
|
|
25
|
-
rake opal
|
|
26
|
-
|
|
27
|
-
Open index.html in the browser to run the project.
|
|
28
|
-
|
|
29
|
-
Next steps
|
|
30
|
-
----------
|
|
31
|
-
|
|
32
|
-
Opal has many of the libraries built. Check out the documentation (more coming soon), ask me questions on freenode (adambeynon): usually in #ruby, #ruby-lang, #javascript etc, or email me: adam.beynon@me.com.
|
|
33
|
-
|
|
34
|
-
Command line tools / v8
|
|
35
|
-
-----------------------
|
|
36
|
-
|
|
37
|
-
I am playing with experimental support for therubyracer. Essentially, this gem allows you to embed the v8 javascript engine into ruby applications. Vienna has support for this allowing, firstly, a REPL system for trying out commands, but more importantly/interestingly, can run an entire opal application through the engine. The compilation step is not necessary as ruby files are compiled as they are required. For now, all specs are by default run through this system. Node, *nix (unix/linux) only, no windows support for opal command line.
|
data/opals/opal/browser/Opalfile
DELETED
|
@@ -1,146 +0,0 @@
|
|
|
1
|
-
# Browser
|
|
2
|
-
|
|
3
|
-
## Getting Started
|
|
4
|
-
|
|
5
|
-
To build/run a browser project, you only require two files: the html file used to load the ruby, and a ruby source file with your application code. By default the build tools will look in a `lib/` directory for your sources, so for simplicity sakes we will use that directory for our code. Also, by default the base-name for the directory is used for loading the main ruby file.
|
|
6
|
-
|
|
7
|
-
### Project Directory Structure
|
|
8
|
-
|
|
9
|
-
Create the following files/directories for our "browser_test" project:
|
|
10
|
-
|
|
11
|
-
!!!plain
|
|
12
|
-
browser_test/
|
|
13
|
-
index.html
|
|
14
|
-
lib/
|
|
15
|
-
browser_test.rb
|
|
16
|
-
|
|
17
|
-
With the new fresh project, the build tools need to be run in the project root, so jump into the browser_test directory.
|
|
18
|
-
|
|
19
|
-
!!!plain
|
|
20
|
-
cd path/to/browser_test
|
|
21
|
-
|
|
22
|
-
### HTML file
|
|
23
|
-
|
|
24
|
-
Out html file simply needs to require the resulting javascript file from our build tools, which (by default) has the same name as our project, so edit index.html to contain the following simple HTML5 document.
|
|
25
|
-
|
|
26
|
-
!!!plain
|
|
27
|
-
<!DOCTYPE html>
|
|
28
|
-
<html>
|
|
29
|
-
<head>
|
|
30
|
-
<script src="javascripts/browser_test.js"></script>
|
|
31
|
-
</head>
|
|
32
|
-
</html>
|
|
33
|
-
|
|
34
|
-
### Hello, World!
|
|
35
|
-
|
|
36
|
-
For a very simple program, "Hello world" seems appropriate. Change the contents of the browser_test.rb file to the following:
|
|
37
|
-
|
|
38
|
-
puts "Hello, World!"
|
|
39
|
-
|
|
40
|
-
This, of course, is very simple ruby. We now need to use the build tools to build the project. This is simply done by running the following command in our root directory:
|
|
41
|
-
|
|
42
|
-
!!!plain
|
|
43
|
-
vn-build
|
|
44
|
-
|
|
45
|
-
The build tool will then generate our `javascripts/browser_test.js` file, which is loaded by our HTML document in the browser. Our generated javascript file also contains the runtime needed (which includes the ruby implementation, the core library, and the browser opal).
|
|
46
|
-
|
|
47
|
-
In any browser with a console (Firefox, Chrome, Safari, IE8 etc), open the HTML document and you will see the message in the console output:
|
|
48
|
-
|
|
49
|
-
"Hello, World!"
|
|
50
|
-
|
|
51
|
-
## Browser API
|
|
52
|
-
|
|
53
|
-
### Document
|
|
54
|
-
|
|
55
|
-
The `Document` module represents the common `document` object in javascript. Its functionality is extended beyond the javascript offering to add common features found in javascript frameworks.
|
|
56
|
-
|
|
57
|
-
#### Document.ready?
|
|
58
|
-
|
|
59
|
-
Ruby code in opal begins running as soon as the source file downloads. This may mean that the document is not yet ready to be manipulated. This method takes a block (or many blocks) that will be executed when the document is ready. Placing code in here ensures that it will not be run before the document can be manipulated, which is sure to yield errors. Place the following code in the browser_test.rb file.
|
|
60
|
-
|
|
61
|
-
puts "this should run first"
|
|
62
|
-
|
|
63
|
-
Document.ready? do
|
|
64
|
-
puts "this should run third"
|
|
65
|
-
end
|
|
66
|
-
|
|
67
|
-
puts "this should run second"
|
|
68
|
-
|
|
69
|
-
Rebuild the project (`vn-build`) and refresh the html page in your browser. You should observe the console results in the following order:
|
|
70
|
-
|
|
71
|
-
"this should run first"
|
|
72
|
-
"this should run second"
|
|
73
|
-
"this should run third"
|
|
74
|
-
|
|
75
|
-
The puts statement in the block runs third because it is only then that the document is ready. Placing DOM manipulation code, or event handlers inside this `ready?` statement is recommended.
|
|
76
|
-
|
|
77
|
-
`Document#ready?` can also be called without a block, which simply returns a boolean whether the document is now ready or not.
|
|
78
|
-
|
|
79
|
-
Document.ready? # => false
|
|
80
|
-
|
|
81
|
-
Document.ready? do
|
|
82
|
-
Document.ready? # => true
|
|
83
|
-
end
|
|
84
|
-
|
|
85
|
-
Document.ready? # => false
|
|
86
|
-
|
|
87
|
-
#### Document.[]
|
|
88
|
-
|
|
89
|
-
This method is used for searching for selectors in the DOM. Every {Element} instance has a `[]` method, which uses itself as the context. For the document, the document itself is the context. This method takes either a string or symbol. In the case of a symbol, the document is searched for an element whose id matches the symbol name, or `nil` if an element with that id cannot be found.
|
|
90
|
-
|
|
91
|
-
!!!plain
|
|
92
|
-
<div id="foo"></div>
|
|
93
|
-
<div id="bar"></div>
|
|
94
|
-
|
|
95
|
-
The above example would produce the following results:
|
|
96
|
-
|
|
97
|
-
Document[:foo]
|
|
98
|
-
# => #<Element div, id="foo">
|
|
99
|
-
|
|
100
|
-
Document [:baz]
|
|
101
|
-
# => nil
|
|
102
|
-
|
|
103
|
-
The returned element is an instance of the {Element} class.
|
|
104
|
-
|
|
105
|
-
The second case, for a string, either returns a single element if the selector is for an id, or returns an array for any other selector type. Looking for an id will take the form `#element_id`. The hash indicates an id. As above, if the elements cannot be found, then `nil` is returned.
|
|
106
|
-
|
|
107
|
-
HTML:
|
|
108
|
-
|
|
109
|
-
!!!plain
|
|
110
|
-
<div id="foo" class="a"></div>
|
|
111
|
-
<div class="b"></div>
|
|
112
|
-
<div class="a"></div>
|
|
113
|
-
|
|
114
|
-
Ruby:
|
|
115
|
-
|
|
116
|
-
Document['#foo']
|
|
117
|
-
# => #<Element div, id="foo", class="a">
|
|
118
|
-
Document['#bar']
|
|
119
|
-
# => nil
|
|
120
|
-
Document['.a']
|
|
121
|
-
# => [#<Element div, id="foo", class="a">, #<Element div, class="a">]
|
|
122
|
-
Document['.b']
|
|
123
|
-
# => [#<Element div, class="b">]
|
|
124
|
-
Document['.c']
|
|
125
|
-
# => nil
|
|
126
|
-
|
|
127
|
-
## Implementation
|
|
128
|
-
|
|
129
|
-
This section discusses the low level implementation details for dealing with the opal runtime. Every class in the browser opal uses pure opal class instances and object instances. No native objects (elements, xmlhttprequests) are accessible from the ruby. Due to cross browser differences, relying on adding opal methods to these natives causes issues, so all references to object's native counterparts are stored purely as an instance variable on the ruby object, so that no addition properties can affect different browser implementations.
|
|
130
|
-
|
|
131
|
-
### Document
|
|
132
|
-
|
|
133
|
-
The {Document} module has a private instance variable called `__element__` which points to the javascript `document` object.
|
|
134
|
-
|
|
135
|
-
### Window
|
|
136
|
-
|
|
137
|
-
The {Window} module also has a private instance variable called `__element__` which point to the native `window` object.
|
|
138
|
-
|
|
139
|
-
### Element
|
|
140
|
-
|
|
141
|
-
Every {Element} instance has a private instance variable called `__element__` which points to the native javascript element that this ruby object represents. To create an {Element} instance with a native element, the class method {Element.from_native} is used, and the native element is passed as a parameter. The result is an instance, with the element set as the private `__element__` variable.
|
|
142
|
-
|
|
143
|
-
### Event
|
|
144
|
-
|
|
145
|
-
Every {Event} instance wraps a native event with a private variable `__event__`. To create an Opal event from a native event, the {Event.from_native} method should be used, which returns a new instance of the {Event} class.
|
|
146
|
-
|