opal 0.3.6 → 0.3.9

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.
Files changed (98) hide show
  1. data/README.md +69 -97
  2. data/bin/opal +2 -2
  3. data/{lib/core → corelib}/array.rb +85 -56
  4. data/corelib/boolean.rb +20 -0
  5. data/corelib/class.rb +58 -0
  6. data/{lib → corelib}/core.rb +2 -50
  7. data/corelib/dir.rb +22 -0
  8. data/{lib/core → corelib}/enumerable.rb +0 -0
  9. data/corelib/error.rb +19 -0
  10. data/{lib/core → corelib}/file.rb +7 -9
  11. data/{lib/core → corelib}/hash.rb +104 -144
  12. data/{lib/core → corelib}/kernel.rb +38 -44
  13. data/corelib/load_order +21 -0
  14. data/{lib/core → corelib}/match_data.rb +0 -0
  15. data/{lib/core → corelib}/module.rb +12 -8
  16. data/{lib/core → corelib}/nil_class.rb +2 -2
  17. data/{lib/core → corelib}/numeric.rb +37 -100
  18. data/corelib/object.rb +37 -0
  19. data/{lib/core → corelib}/proc.rb +3 -3
  20. data/corelib/range.rb +27 -0
  21. data/{lib/core → corelib}/regexp.rb +1 -1
  22. data/{lib/core → corelib}/string.rb +16 -107
  23. data/{lib/core → corelib}/top_self.rb +0 -0
  24. data/lib/opal.rb +7 -0
  25. data/lib/opal/browserify.rb +34 -0
  26. data/{opal_lib → lib}/opal/builder.rb +70 -24
  27. data/lib/opal/command.rb +52 -0
  28. data/lib/opal/context.rb +197 -0
  29. data/{opal_lib/opal/ruby/parser.rb → lib/opal/lexer.rb} +20 -4
  30. data/{opal_lib/opal/ruby → lib/opal}/nodes.rb +238 -127
  31. data/lib/opal/parser.rb +4894 -0
  32. data/{opal_lib/opal/ruby/ruby_parser.y → lib/opal/parser.y} +38 -18
  33. data/lib/rbp.rb +2 -0
  34. data/lib/rbp/package.rb +49 -0
  35. data/runtime/class.js +216 -189
  36. data/runtime/fs.js +2 -2
  37. data/runtime/init.js +242 -244
  38. data/runtime/loader.js +78 -99
  39. data/runtime/module.js +34 -40
  40. data/runtime/post.js +2 -2
  41. data/runtime/pre.js +1 -1
  42. data/runtime/runtime.js +129 -135
  43. data/{lib → stdlib}/dev.rb +10 -10
  44. data/{lib → stdlib}/racc/parser.rb +0 -6
  45. data/{lib → stdlib}/strscan.rb +4 -4
  46. metadata +57 -105
  47. data/lib/core/basic_object.rb +0 -51
  48. data/lib/core/class.rb +0 -38
  49. data/lib/core/dir.rb +0 -26
  50. data/lib/core/error.rb +0 -75
  51. data/lib/core/false_class.rb +0 -81
  52. data/lib/core/object.rb +0 -6
  53. data/lib/core/range.rb +0 -27
  54. data/lib/core/symbol.rb +0 -42
  55. data/lib/core/true_class.rb +0 -41
  56. data/lib/ospec.rb +0 -7
  57. data/lib/ospec/autorun.rb +0 -8
  58. data/lib/ospec/dsl.rb +0 -15
  59. data/lib/ospec/example.rb +0 -11
  60. data/lib/ospec/example/before_and_after_hooks.rb +0 -56
  61. data/lib/ospec/example/errors.rb +0 -17
  62. data/lib/ospec/example/example_group.rb +0 -12
  63. data/lib/ospec/example/example_group_factory.rb +0 -18
  64. data/lib/ospec/example/example_group_hierarchy.rb +0 -21
  65. data/lib/ospec/example/example_group_methods.rb +0 -100
  66. data/lib/ospec/example/example_group_proxy.rb +0 -15
  67. data/lib/ospec/example/example_methods.rb +0 -46
  68. data/lib/ospec/example/example_proxy.rb +0 -18
  69. data/lib/ospec/expectations.rb +0 -19
  70. data/lib/ospec/expectations/errors.rb +0 -8
  71. data/lib/ospec/expectations/fail_with.rb +0 -9
  72. data/lib/ospec/expectations/handler.rb +0 -33
  73. data/lib/ospec/helpers/scratch.rb +0 -18
  74. data/lib/ospec/matchers.rb +0 -24
  75. data/lib/ospec/matchers/be.rb +0 -1
  76. data/lib/ospec/matchers/generated_descriptions.rb +0 -20
  77. data/lib/ospec/matchers/operator_matcher.rb +0 -54
  78. data/lib/ospec/matchers/raise_error.rb +0 -38
  79. data/lib/ospec/runner.rb +0 -90
  80. data/lib/ospec/runner/example_group_runner.rb +0 -41
  81. data/lib/ospec/runner/formatter/html_formatter.rb +0 -139
  82. data/lib/ospec/runner/formatter/terminal_formatter.rb +0 -48
  83. data/lib/ospec/runner/options.rb +0 -34
  84. data/lib/ospec/runner/reporter.rb +0 -82
  85. data/opal_lib/opal.rb +0 -16
  86. data/opal_lib/opal/build_methods.rb +0 -51
  87. data/opal_lib/opal/bundle.rb +0 -70
  88. data/opal_lib/opal/command.rb +0 -68
  89. data/opal_lib/opal/context.rb +0 -81
  90. data/opal_lib/opal/context/console.rb +0 -10
  91. data/opal_lib/opal/context/file_system.rb +0 -34
  92. data/opal_lib/opal/context/loader.rb +0 -135
  93. data/opal_lib/opal/gem.rb +0 -84
  94. data/opal_lib/opal/rake/builder_task.rb +0 -44
  95. data/opal_lib/opal/rake/spec_task.rb +0 -32
  96. data/opal_lib/opal/ruby/ruby_parser.rb +0 -4862
  97. data/opal_lib/opal/version.rb +0 -4
  98. data/runtime/debug.js +0 -84
@@ -1,139 +0,0 @@
1
- module Spec
2
- module Runner
3
- module Formatter
4
- class HtmlFormatter
5
-
6
- attr_reader :example_group, :example_group_number
7
-
8
- def initialize(options)
9
- @options = options
10
- @example_group_number = 0
11
- @example_number = 0
12
- @header_red = nil
13
-
14
- setup_page_dom
15
- end
16
-
17
- ##
18
- # Get the DOM ready for output
19
- #
20
- def setup_page_dom
21
- content = [
22
- "<style>#{css_content}</style>",
23
- '<div class="rspec-report">',
24
- '<div id="rspec-header">',
25
- '<div id="label">',
26
- '<h1>Rspec Code Examples</h1>',
27
- '</div>',
28
-
29
- '<div id="summary">',
30
- '<p id="totals">0</p>',
31
- '<p id="duration">0</p>',
32
- '</div>',
33
- '</div>',
34
- '<div id="results">',
35
- '</div>',
36
- '</div>'
37
- ].join ''
38
- `var wrapper = document.createElement('div');
39
- wrapper.id = "rspec-wrapper";
40
- wrapper.innerHTML = content;
41
- document.getElementsByTagName('body')[0].appendChild(wrapper);`
42
- `self.$results = document.getElementById('results');`
43
- nil
44
- end
45
-
46
- def css_content
47
- 'body{ margin:0px; padding:0px; background:white; font-size:80%}#rspec-header{ background:#65C400;color:#fff;height:4em}.rspec-report h1{ margin:0px 10px 0px 10px; padding:10px; font-family:"Lucida Grande",Helvetica,sans-serif; font-size:1.8em; position:absolute}#summary{ margin:0;padding:5px 10px; font-family:"Lucida Grande",Helvetica,sans-serif; text-align:right; top:0px; right:0px; float:right}#summary p{ margin:0 0 0 2px}#summary #totals{ font-size:1.2em}#results{}.example_group{ margin:0 10px 5px; background:#fff}dl{ margin:0;padding:0 0 5px; font:normal 11px "Lucida Grande",Helvetica,sans-serif}dt{ padding:3px; background:#65C400; color:#fff; font-weight:bold}dd{ margin:5px 0 5px 5px; padding:3px 3px 3px 18px}dd.spec.passed{ border-left:5px solid #65C400; border-bottom:1px solid #65C400; background:#DBFFB4;color:#3D7700}dd.spec.failed{ border-left:5px solid #C20000; border-bottom:1px solid #C20000; color:#C20000;background:#FFFBD3}dd.spec.not_implemented{ border-left:5px solid #FAF834; border-bottom:1px solid #FAF834; background:#FCFB98;color:#131313}dd.spec.pending_fixed{ border-left:5px solid #0000C2; border-bottom:1px solid #0000C2; color:#0000C2;background:#D3FBFF}.backtrace{ color:#000; font-size:12px}a{ color:#BE5C00}.ruby{ font-size:12px; font-family:monospace; color:white; background-color:black; padding:0.1em 0 0.2em 0}.ruby .keyword{color:#F60}.ruby .constant{color:#399}.ruby .attribute{color:white}.ruby .global{color:white}.ruby .module{color:white}.ruby .class{color:white}.ruby .string{color:#6F0}.ruby .ident{color:white}.ruby .method{color:#FC0}.ruby .number{color:white}.ruby .char{color:white}.ruby .comment{color:#93C}.ruby .symbol{color:white}.ruby .regex{color:#44B4CC}.ruby .punct{color:white}.ruby .escape{color:white}.ruby .interp{color:white}.ruby .expr{color:white}.ruby .offending{background-color:gray}.ruby .linenum{ width:75px; padding:0.1em 1em 0.2em 0; color:#000; background-color:#FFFBD3}'
48
- end
49
-
50
-
51
- def start(number_of_examples)
52
-
53
- end
54
-
55
- def end
56
- @end_time = Time.now
57
- end
58
-
59
- def example_group_started(example_group)
60
- @example_group = example_group
61
- @example_group_red = false
62
- @example_group_number += 1
63
-
64
- # @example_group_div = results_output.div :class_name => "example_group"
65
- # @example_group_dl = @example_group_div.dl
66
- # @example_group_dt = @example_group_dl.dt :content => example_group.description, :id => "example_group_#{example_group_number}"
67
-
68
- `var div = self.$example_div = document.createElement('div');
69
- div.className = 'example_group';
70
-
71
- var dl = self.$example_dl = document.createElement('dl');
72
- div.appendChild(dl);
73
-
74
- var dt = self.$example_dt = document.createElement('dt');
75
- dt.innerHTML = #{example_group.description};
76
- dt.id = "element_group_" + #{@element_group_number.to_s};
77
- dl.appendChild(dt);
78
-
79
- self.$results.appendChild(div);`
80
-
81
- end
82
-
83
- def example_started(example)
84
-
85
- end
86
-
87
- def example_failed(example, counter, failure)
88
- @header_red = true
89
- @example_group_red = true
90
-
91
- `var dd = document.createElement('dd');
92
- dd.className = "spec failed";
93
-
94
- var span = document.createElement('span');
95
- span.innerHTML = #{example.description};
96
- span.className = "failed_spec_name";
97
- dd.appendChild(span);
98
-
99
- self.$example_dl.appendChild(dd);
100
-
101
- var failure_div = document.createElement('div');
102
- failure_div.className = "failure";
103
-
104
- var msg = document.createElement('div');
105
- msg.className = "message";
106
-
107
- var pre = document.createElement('pre');
108
- pre.innerHTML = #{failure.exception.message};
109
- msg.appendChild(pre);
110
-
111
- failure_div.appendChild(msg);
112
- dd.appendChild(failure_div);`
113
-
114
- nil
115
- end
116
-
117
- def example_passed(example)
118
- `var dl = self.$example_dl;
119
-
120
- var dd = document.createElement('dd');
121
- dd.className = "spec passed";
122
-
123
- var span = document.createElement('span');
124
- dd.appendChild(span);
125
- span.innerHTML = #{example.description.to_s};
126
- span.className = "passed_spec_name";
127
-
128
- dl.appendChild(dd);`
129
- nil
130
- end
131
-
132
- def example_pending(example, message)
133
- # @example_group_dl.dd(:class_name => "spec not_implemented").span(:content => "#{example.description} (PENDING: #{message})", :class_name => "not_implemented_spec_name")
134
- end
135
- end
136
- end
137
- end
138
- end
139
-
@@ -1,48 +0,0 @@
1
- module Spec
2
- module Runner
3
- module Formatter
4
- class TerminalFormatter
5
-
6
- attr_reader :example_group, :example_group_number
7
-
8
- def initialize(options)
9
- @options = options
10
- @example_group_number = 0
11
- @example_number = 0
12
- end
13
-
14
- def start(number_of_examples)
15
-
16
- end
17
-
18
- def end
19
-
20
- end
21
-
22
- def example_group_started(example_group)
23
- @example_group = example_group
24
- end
25
-
26
- def example_started(example)
27
- @example_number += 1
28
- end
29
-
30
- def example_failed(example, counter, failure)
31
- puts "\033[0;31m#{@example_group.description}: #{example.description}\033[m"
32
- puts ""
33
- puts " #{failure.exception.message}"
34
- puts ""
35
- end
36
-
37
- def example_passed(example)
38
- puts "\033[0;32m#{@example_group.description}: #{example.description}\033[m"
39
- end
40
-
41
- def example_pending(example, message)
42
- puts "\033[0;33m#{@example_group.description}: #{example.description}\033[m"
43
- end
44
-
45
- end
46
- end
47
- end
48
- end
@@ -1,34 +0,0 @@
1
- module Spec
2
- module Runner
3
- class Options
4
-
5
- attr_accessor :reporter, :example_groups
6
- attr_writer :reporter
7
-
8
- def initialize
9
- @example_groups = []
10
- @reporter = Reporter.new self
11
- end
12
-
13
- def run_examples
14
- runner = ExampleGroupRunner.new self
15
- runner.run
16
- end
17
-
18
- def formatters
19
- return @formatters if @formatters
20
- if RUBY_ENGINE == "opal-browser"
21
- @formatters ||= [Spec::Runner::Formatter::HtmlFormatter.new(self)]
22
- else
23
- @formatters ||= [Spec::Runner::Formatter::TerminalFormatter.new(self)]
24
- end
25
- end
26
-
27
- def add_example_group(example_group)
28
- @example_groups << example_group
29
- end
30
-
31
- end # Options
32
- end
33
- end
34
-
@@ -1,82 +0,0 @@
1
- module Spec
2
- module Runner
3
- class Reporter
4
-
5
- attr_reader :options
6
-
7
- def initialize(options)
8
- @options = options
9
- @options.reporter = self
10
- @failures = []
11
- @pending_count = 0
12
- @example_count = 0
13
- end
14
-
15
- def start(number_of_examples)
16
- @start_time = 0
17
- formatters.each do |f|
18
- f.start number_of_examples
19
- end
20
- end
21
-
22
- def formatters
23
- @options.formatters
24
- end
25
-
26
- def example_group_started(example_group)
27
- @example_group = example_group
28
- formatters.each do |f|
29
- f.example_group_started example_group
30
- end
31
- end
32
-
33
- def example_started(example)
34
- formatters.each do |f|
35
- f.example_started example
36
- end
37
- end
38
-
39
- def example_finished(example, error)
40
- if error.nil?
41
- example_passed example
42
- elsif Spec::Example::ExamplePendingError === error
43
- example_pending example, error.message
44
- else
45
- example_failed example, error
46
- end
47
- end
48
-
49
- def example_failed(example, error)
50
- failure = Failure.new @example_group.description, example.description, error
51
- @failures << failure
52
- formatters.each do |f|
53
- f.example_failed example, @failures.length, failure
54
- end
55
- end
56
-
57
- def example_passed(example)
58
- formatters.each do |f|
59
- f.example_passed example
60
- end
61
- end
62
-
63
- def example_pending(example, message)
64
- # @pending_count += 1
65
- formatters.each do |f|
66
- f.example_pending example, message
67
- end
68
- end
69
- end # Reporter
70
-
71
- class Failure
72
-
73
- attr_reader :exception
74
-
75
- def initialize(group_description, example_description, exception)
76
- @example_name = "#{group_description} #{example_description}"
77
- @exception = exception
78
- end
79
- end
80
- end
81
- end
82
-
data/opal_lib/opal.rb DELETED
@@ -1,16 +0,0 @@
1
- require 'rubygems'
2
- require 'thor'
3
-
4
- module Opal
5
-
6
- end
7
-
8
- require 'opal/version'
9
- require 'opal/ruby/parser'
10
-
11
- require 'opal/gem'
12
- require 'opal/bundle'
13
- require 'opal/builder'
14
-
15
- require 'opal/rake/builder_task'
16
-
@@ -1,51 +0,0 @@
1
- module Opal
2
-
3
- module BuildMethods
4
-
5
- # Returns the result of the compiled file ready for opal to load.
6
- #
7
- # `relative_path` is used for the name the built file should have.
8
- # This is used for building a singular rb or js file into the
9
- # compiled output, and will avoid the user's dir setup being exposed
10
- # in production code. It will be of the form
11
- # `lib/some_lib/some_lib.rb`
12
- #
13
- # @param [String] full_path The full pathname to the file to build
14
- # @paeam [String] relative_path The pathname to be used in the build
15
- # file.
16
- #
17
- # @return [String]
18
- def wrap_source(full_path, relative_path = nil)
19
- relative_path ||= full_path
20
- ext = File.extname full_path
21
- # relative_path = relative_path.sub(/\.rb/, '.js') if ext == '.rb'
22
- content = compile_source full_path
23
-
24
- "opal.register('#{relative_path}', #{content});\n"
25
- end
26
-
27
- # Simply compile the given source code at the given path. This is
28
- # for compiling ruby or javascript sources only. This can be used
29
- # for any method that builds for the browser.
30
- #
31
- # @param [String] full_path location of the source to build
32
- # @return [String] compiled source
33
- def compile_source(full_path)
34
- ext = File.extname full_path
35
- src = File.read full_path
36
-
37
- case ext
38
- when '.js'
39
- "function($rb, self, __FILE__) { #{src} }"
40
-
41
- when '.rb'
42
- src = Opal::RubyParser.new(src).parse!.generate_top
43
- "function($rb, self, __FILE__) { #{src} }"
44
-
45
- else
46
- raise "Bad file type for wrapping. Must be ruby or javascript"
47
- end
48
- end
49
- end
50
- end
51
-
@@ -1,70 +0,0 @@
1
- require 'opal/build_methods'
2
-
3
- module Opal
4
-
5
- class Bundle
6
- include BuildMethods
7
-
8
- attr_reader :gem
9
-
10
- def initialize(gem)
11
- @gem = gem
12
- end
13
-
14
- def wrap_source(full_path, relative_path = nil)
15
- relative_path ||= full_path
16
- content = compile_source full_path
17
- "'#{relative_path}': #{content}\n"
18
- end
19
-
20
- # Actually build the bundle. Returns the result, for now, as a string.
21
- #
22
- # @return {String} bundled packages
23
- def build(options = {})
24
- gem = @gem
25
- if options[:test]
26
- result = build_test_files
27
- else
28
- result = build_lib_files
29
- end
30
-
31
- if options[:out]
32
- FileUtils.mkdir_p File.dirname(options[:out])
33
- File.open(options[:out], 'w+') { |o| o.write result }
34
- else
35
- result
36
- end
37
- end
38
-
39
- def build_lib_files
40
- files = @gem.lib_files
41
-
42
- bundle = []
43
- bundle << %[opal.register("#{gem.name}", {]
44
- bundle << %[ "name": #{gem.name.inspect},]
45
- bundle << %[ "version": #{gem.version.inspect},]
46
- bundle << %[ "require_paths": #{gem.require_paths.inspect},]
47
- bundle << %[ "files": {]
48
- bundle << %[ #{files.map { |f| wrap_source f }.join(",\n ")}]
49
- bundle << %[ }]
50
- bundle << %[});]
51
-
52
- result = bundle.join ''
53
- end
54
-
55
- def build_test_files
56
- files = @gem.test_files
57
-
58
- bundle = []
59
- bundle << %[opal.register("#{gem.name}", {]
60
- bundle << %[ "name": #{gem.name.inspect},]
61
- bundle << %[ "files": {]
62
- bundle << %[ #{files.map { |f| wrap_source f }.join(",\n ")}]
63
- bundle << %[ }]
64
- bundle << %[});]
65
-
66
- result = bundle.join ''
67
- end
68
- end
69
- end
70
-