opal 0.4.2 → 0.4.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (93) hide show
  1. data/.travis.yml +5 -0
  2. data/README.md +42 -2
  3. data/Rakefile +7 -6
  4. data/bin/opal +2 -2
  5. data/{opal → corelib}/opal.rb +21 -21
  6. data/{opal → corelib}/opal/array.rb +37 -24
  7. data/{opal → corelib}/opal/basic_object.rb +0 -0
  8. data/{opal → corelib}/opal/boolean.rb +0 -0
  9. data/{opal → corelib}/opal/class.rb +45 -22
  10. data/{opal → corelib}/opal/comparable.rb +0 -0
  11. data/{opal → corelib}/opal/enumerable.rb +0 -0
  12. data/{opal → corelib}/opal/enumerator.rb +0 -0
  13. data/{opal → corelib}/opal/error.rb +16 -12
  14. data/{opal → corelib}/opal/hash.rb +2 -2
  15. data/{opal → corelib}/opal/kernel.rb +16 -14
  16. data/{opal → corelib}/opal/native.rb +0 -0
  17. data/{opal → corelib}/opal/nil_class.rb +1 -1
  18. data/{opal → corelib}/opal/numeric.rb +0 -0
  19. data/{opal → corelib}/opal/proc.rb +0 -0
  20. data/{opal → corelib}/opal/range.rb +2 -2
  21. data/{opal → corelib}/opal/regexp.rb +0 -0
  22. data/{opal → corelib}/opal/runtime.js +92 -126
  23. data/{opal → corelib}/opal/string.rb +14 -13
  24. data/{opal → corelib}/opal/time.rb +0 -0
  25. data/lib/opal.rb +9 -8
  26. data/lib/opal/builder.rb +81 -0
  27. data/lib/opal/erb.rb +17 -0
  28. data/lib/opal/grammar.rb +33 -30
  29. data/lib/opal/grammar.y +18 -15
  30. data/lib/opal/grammar_helpers.rb +5 -5
  31. data/lib/opal/lexer.rb +3 -2
  32. data/lib/opal/parser.rb +58 -41
  33. data/lib/opal/require_parser.rb +77 -0
  34. data/lib/opal/version.rb +1 -1
  35. data/opal.gemspec +1 -1
  36. data/{config.ru → spec/config.ru} +0 -0
  37. data/spec/opal/array/to_json_spec.rb +3 -1
  38. data/spec/opal/boolean/to_json_spec.rb +3 -1
  39. data/spec/opal/erb/erb_spec.rb +25 -0
  40. data/spec/opal/erb/quoted.opalerb +1 -0
  41. data/spec/opal/erb/simple.opalerb +1 -0
  42. data/spec/opal/json/parse_spec.rb +3 -1
  43. data/spec/opal/kernel/to_json_spec.rb +3 -1
  44. data/spec/opal/nil/to_json_spec.rb +3 -1
  45. data/spec/opal/string/to_json_spec.rb +3 -1
  46. data/spec/parser/int_spec.rb +13 -0
  47. data/spec/parser/regexp_spec.rb +16 -0
  48. data/spec/parser/str_spec.rb +11 -0
  49. data/spec/rubyspec/core/array/plus_spec.rb +7 -2
  50. data/spec/rubyspec/core/hash/to_json_spec.rb +3 -1
  51. data/spec/rubyspec/core/numeric/to_json_spec.rb +3 -1
  52. data/spec/rubyspec/language/defined_spec.rb +9 -0
  53. data/spec/rubyspec/library/stringscanner/pos_spec.rb +20 -0
  54. data/{opal → stdlib}/date.rb +0 -0
  55. data/stdlib/erb.rb +26 -0
  56. data/{opal → stdlib}/fileutils.rb +0 -0
  57. data/{opal → stdlib}/iconv.rb +0 -0
  58. data/{opal/opal → stdlib}/json.rb +0 -0
  59. data/{opal → stdlib}/observer.rb +0 -0
  60. data/{opal → stdlib}/opal-browser/local_storage.rb +0 -0
  61. data/{opal → stdlib}/opal-browser/script_loader.rb +1 -1
  62. data/{opal → stdlib}/opal-parser.js.erb +1 -1
  63. data/{opal → stdlib}/opal-source-maps.js.erb +0 -0
  64. data/{opal → stdlib}/pp.rb +0 -0
  65. data/{opal → stdlib}/racc.rb +0 -0
  66. data/{opal → stdlib}/rbconfig.rb +0 -0
  67. data/{opal → stdlib}/source_map.rb +1 -1
  68. data/{opal → stdlib}/source_map/generator.rb +0 -0
  69. data/{opal → stdlib}/source_map/parser.rb +0 -0
  70. data/{opal → stdlib}/source_map/vlq.rb +0 -0
  71. data/{opal → stdlib}/strscan.rb +15 -0
  72. data/{opal → stdlib}/yaml.rb +0 -0
  73. metadata +87 -77
  74. checksums.yaml +0 -7
  75. data/CHANGELOG.md +0 -176
  76. data/examples/native/Gemfile +0 -3
  77. data/examples/native/README.md +0 -17
  78. data/examples/native/app/app.rb +0 -57
  79. data/examples/native/config.ru +0 -8
  80. data/examples/native/index.html.erb +0 -12
  81. data/examples/rack/Gemfile +0 -3
  82. data/examples/rack/README.md +0 -22
  83. data/examples/rack/app/app.rb +0 -5
  84. data/examples/rack/config.ru +0 -20
  85. data/examples/rack/index.html +0 -12
  86. data/examples/server/Gemfile +0 -3
  87. data/examples/server/README.md +0 -22
  88. data/examples/server/app/app.rb +0 -18
  89. data/examples/server/config.ru +0 -10
  90. data/examples/server/index.html.erb +0 -10
  91. data/opal/opal-template.rb +0 -33
  92. data/spec/opal/class/_inherited_spec.rb +0 -32
  93. data/spec/opal/class/new_spec.rb +0 -27
checksums.yaml DELETED
@@ -1,7 +0,0 @@
1
- ---
2
- SHA1:
3
- metadata.gz: 21f31bff5e89852e9643aec27ca8a41008a42130
4
- data.tar.gz: 5958461f09fa61100fd1c3b8a95aed70705687bc
5
- SHA512:
6
- metadata.gz: 2825d7fea9566cf8e272099bb73e902575aa0ae64aa8e81bde751f5ddbd5d5a0a6150c2faaea775308b666e5bc0925a190d92c05d58b011626967bb7ea457978
7
- data.tar.gz: 0a0d9f6d6759512726088751d88518f75041b6c890d9f76a316a7dc75bb74e97bf37aaa250d640eba4e053078fe42d2c3a2a38f1025310fdb96c23fb14c3f5de
data/CHANGELOG.md DELETED
@@ -1,176 +0,0 @@
1
- ## edge
2
-
3
- ## 0.4.2 2013-07-03
4
-
5
- * Added `Kernel#rand`. (fntzr)
6
-
7
- * Restored the `bin/opal` executable in gemspec.
8
-
9
- * Now `.valueOf()` is used in `#to_n` of Boolean, Numeric, Regexp and String
10
- to return the naked JavaScript value instead of a wrapping object.
11
-
12
- * Parser now wraps or-ops in paranthesis to stop variable order from
13
- leaking out when minified by uglify. We now have code in this
14
- format: `(((tmp = lhs) !== false || !==nil) ? tmp : rhs)`.
15
-
16
- ## 0.4.1 2013-06-16
17
-
18
- * Move sprockets logic out to external opal-sprockets gem. That now
19
- handles the compiling and loading of opal files in sprockets.
20
-
21
- ## 0.4.0 2013-06-15
22
-
23
- * Added fragments to parser. All parser methods now generate one or
24
- more Fragments which store the original sexp. This allows us to
25
- enumerate over them after parsing to map generated lines back to
26
- original line numbers.
27
-
28
- * Reverted `null` for `nil`. Too buggy at this time.
29
-
30
- * Add Opal::SprocketsParser as Parser subclass for handling parsing
31
- for sprockets environment. This subclass handles require statements
32
- and stores them for sprockets to use.
33
-
34
- * Add :irb option to parser to keep top level lvars stored inside
35
- opal runtime so that an irb session can be persisted and maintain
36
- access to local variables.
37
-
38
- * Add Opal::Environment#use_gem() helper to add a gem to opals load
39
- path.
40
-
41
- * Stop pre-setting ivars to `nil`. This is no longer needed as `nil`
42
- is now `null` or `undefined`.
43
-
44
- * Use `null` as `nil` in opal. This allows us to send methods to
45
- `null` and `undefined`, and both act as `nil`. This makes opal a
46
- much better javascript citizen. **REVERTED**
47
-
48
- * Add Enumerable#none? with specs.
49
-
50
- * Add Opal.block_send() runtime helper for sending methods to an
51
- object which uses a block.
52
-
53
- * Remove \_klass variable for denoting ruby classes, and use
54
- constructor instead. constructor is a javascript property used for
55
- the same purpose, and this makes opal fit in as a better js citizen.
56
-
57
- * Add Class.bridge\_class method to bridge a native constructor into an
58
- opal class which will set it up with all methods from Object, as
59
- well as giving it a scope and name.
60
-
61
- * Added native #[]= and #to_h methods, for setting properties and
62
- converting to a hash respectivaly.
63
-
64
- * Fix bug where '::' was parsed as :colon2 instead of :colon3 when in
65
- an args scope. Fixes #213
66
-
67
- * Remove lots of properties added to opal classes. This makes normal
68
- js constructors a lot closer to opal classes, making is easier to
69
- treat js classes as opal classes.
70
-
71
- * Merge Hash.from_native into Hash.new
72
-
73
- ## 0.3.44 2013-05-31
74
-
75
- * Cleanup runtime, and remove various flags and functions from opal
76
- objects and classes (moving them to runtime methods).
77
-
78
- * Remove some activesupport methods into external lib.
79
-
80
- * Add/fix lots of String methods, with specs.
81
-
82
- * Add more methods to MatchData class.
83
-
84
- * Implement $' and $` variables.
85
-
86
- * Opal can now call methods on all native objects, via method missing
87
- dispatcher.
88
-
89
- * Add Opal::Environment as custom sprockets subclass which adds all
90
- opal load paths automatically.
91
-
92
- ## 0.3.43 2013-05-02
93
-
94
- * Stop inlining respond_to? inside the parser. This now fully respects
95
- an object overriding respond_to?.
96
-
97
- * Expose `Opal.eval()` function when parser is loaded for parsing
98
- and running strings of ruby code.
99
-
100
- * Add erb to corelib (as well as compiler to gem lib). ERB files with
101
- .opalerb extension will automatically be compiled into Template
102
- constant.
103
-
104
- * Added some examples into examples/ dir.
105
-
106
- * Add Opal.send() javascript function for sending methods to ruby
107
- objects.
108
-
109
- * Native class for wrapping and interacting with native objects and
110
- function calls.
111
-
112
- * Add local_storage to stdlib as a basic wrapper around localStorage.
113
-
114
- * Make method_missing more performant by reusing same dispatch function
115
- instead of reallocating one for each run.
116
-
117
- * Fix Kernel#format to work in firefox. String.prototype.replace() had
118
- different semantics for empty matching groups which was breaking
119
- Kernel#format.
120
-
121
- ## 0.3.42 2013-03-21
122
-
123
- * Fix/add lots of language specs.
124
-
125
- * Seperate sprockets support out to opal-sprockets gem.
126
-
127
- * Support %r[foo] style regexps.
128
-
129
- * Use mspec to run specs on corelib and runtime. Rubyspecs are now
130
- used, where possible to be as compliant as possible.
131
-
132
- ## 0.3.41 2013-02-26
133
-
134
- * Remove bin/opal - no longer required for building sources.
135
-
136
- * Depreceate Opal::Environment. The Opal::Server class provides a better
137
- method of using the opal load paths. Opal.paths still stores a list of
138
- load paths for generic sprockets based apps to use.
139
-
140
- ## 0.3.40 2013-02-23
141
-
142
- * Add Opal::Server as an easy to configure rack server for testing and
143
- running Opal based apps.
144
-
145
- * Added optional arity check mode for parser. When turned on, every method
146
- will have code which checks the argument arity. Off by default.
147
-
148
- * Exception subclasses now relfect their name in webkit/firefox debuggers
149
- to show both their class name and message.
150
-
151
- * Add Class#const_set. Trying to access undefined constants by a literal
152
- constant will now also raise a NameError.
153
-
154
- ## 0.3.39 2013-02-20
155
-
156
- * Fix bug where methods defined on a parent class after subclass was defined
157
- would not given subclass access to method. Subclasses are now also tracked
158
- by superclass, by a private '_inherited' property.
159
-
160
- * Fix bug where classes defined by `Class.new` did not have a constant scope.
161
-
162
- * Move Date out of opal.rb loading, as it is part of stdlib not corelib.
163
-
164
- * Fix for defining methods inside metaclass, or singleton_class scopes.
165
-
166
- ## 0.3.38 2013-02-13
167
-
168
- * Add Native module used for wrapping objects to forward calls as native
169
- calls.
170
-
171
- * Support method_missing for all objects. Feature can be enabled/disabled on
172
- Opal::Processor.
173
-
174
- * Hash can now use any ruby object as a key.
175
-
176
- * Move to Sprockets based building via `Opal::Processor`.
@@ -1,3 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- gem 'opal', :path => '../..'
@@ -1,17 +0,0 @@
1
- # opal native example
2
-
3
- This example shows how native objects and functions can be called
4
- directly from ruby code.
5
-
6
- ## Usage
7
-
8
- First, change into this directory and get required gems:
9
-
10
- $ bundle install
11
-
12
- Run the rack server:
13
-
14
- $ bundle exec rackup
15
-
16
- Now just visit `http://localhost:9292` in the browser, and view the
17
- added elements on screen.
@@ -1,57 +0,0 @@
1
- require 'opal'
2
-
3
- # We can treat native objects (in this case `window`) as a ruby object
4
- # and open up a singleton class on it and define methods on the object
5
- # directly. This basically defines just a single ruby method onto
6
- # `window`.
7
- class << $global
8
-
9
- # on_ready is a simple method that just adds a 'DOMContentLoaded'
10
- # event onto window. `self` inside this method will be `window`,
11
- # so we can call addEventListener as we would in ruby
12
- def on_ready(&block)
13
- addEventListener 'DOMContentLoaded', block, false
14
- end
15
- end
16
-
17
- # Call our new method on window (which is accessed by `$global`
18
- $global.on_ready do
19
- css = <<-CSS
20
- body {
21
- font-family: 'Arial';
22
- }
23
-
24
- h1 {
25
- color: rgb(10, 94, 232);
26
- }
27
- CSS
28
-
29
- document = $global.document
30
-
31
- title = document.createElement 'h1'
32
- title.className = 'main-title'
33
- title.innerHTML = 'Opal Native Example'
34
-
35
- desc = document.createElement 'p'
36
- desc.innerHTML = "Hello world! From Opal."
37
-
38
- target = document.getElementById 'native-example'
39
-
40
- unless target
41
- raise "'native-example' doesn't exist?"
42
- end
43
-
44
- target.appendChild title
45
- target.appendChild desc
46
-
47
- styles = document.createElement 'style'
48
- styles.type = 'text/css'
49
-
50
- if styles.respond_to? :styleSheet
51
- styles.styleSheet.cssText = css
52
- else
53
- styles.appendChild document.createTextNode css
54
- end
55
-
56
- document.getElementsByTagName('head')[0].appendChild(styles)
57
- end
@@ -1,8 +0,0 @@
1
- require 'bundler'
2
- Bundler.require
3
-
4
- run Opal::Server.new { |s|
5
- s.append_path 'app'
6
- s.debug = true
7
- s.main = 'app'
8
- }
@@ -1,12 +0,0 @@
1
- <!doctype html>
2
- <html lang="en">
3
- <head>
4
- <meta charset="utf-8">
5
- <title>opal native example</title>
6
- <%= javascript_include_tag 'app' %>
7
- </head>
8
- <body>
9
- <div id="native-example">
10
- </div>
11
- </body>
12
- </html>
@@ -1,3 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- gem 'opal', :path => '../..'
@@ -1,22 +0,0 @@
1
- # Opal Rack example
2
-
3
- This example uses a simple rack server, along with sprockets to serve
4
- the assets. Sprockets makes opal easy to use, and is the basis for
5
- integration with rails (via opal-rails).
6
-
7
- ## Running
8
-
9
- Install dependencies (opal):
10
-
11
- ```
12
- $ bundle install
13
- ```
14
-
15
- Run rack server:
16
-
17
- ```
18
- $ bundle exec rackup
19
- ```
20
-
21
- Open any browser to `http://127.0.0.1/index.html`, and enjoy!
22
-
@@ -1,5 +0,0 @@
1
- require 'opal'
2
-
3
- # use native alert from browser
4
- $global.alert "Boo! from opal"
5
-
@@ -1,20 +0,0 @@
1
- require 'bundler'
2
- Bundler.require
3
-
4
- # Use sprockets for handling our assets
5
- map '/assets' do
6
- env = Sprockets::Environment.new
7
-
8
- # add all our opal load paths to sprockets
9
- Opal.paths.each { |p| env.append_path p }
10
-
11
- # add 'app' dir for serving app.rb
12
- env.append_path 'app'
13
-
14
- # run!
15
- run env
16
- end
17
-
18
- # Use simple Rack::Directory for serving current dir
19
- run Rack::Directory.new('.')
20
-
@@ -1,12 +0,0 @@
1
- <!doctype html>
2
- <html lang="en">
3
- <head>
4
- <meta charset="utf-8">
5
- <title>Opal rack example</title>
6
-
7
- <script src="/assets/app.js"></script>
8
-
9
- </head>
10
- <body>
11
- </body>
12
- </html>
@@ -1,3 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- gem 'opal', :path => '../..'
@@ -1,22 +0,0 @@
1
- # Opal Example Application
2
-
3
- This example shows how to use `Opal::Server` on top of a rack app to run
4
- a simple opal application.
5
-
6
- ## Run example
7
-
8
- Change into this directory, and install dependencies:
9
-
10
- ```
11
- $ bundle install
12
- ```
13
-
14
- Start the rack server (which will compile/build opal runtime for you):
15
-
16
- ```
17
- $ bundle exec rackup
18
- ```
19
-
20
- Then just open `http://127.0.0.1:9292` in any browser and checkout the console.
21
-
22
- Happy hacking.
@@ -1,18 +0,0 @@
1
- require 'opal'
2
-
3
- [1, 2, 3, 4].each do |a|
4
- puts a
5
- end
6
-
7
- class Foo
8
- attr_accessor :name
9
-
10
- def method_missing(sym, *args, &block)
11
- puts "You tried to call: #{sym}"
12
- end
13
- end
14
-
15
- adam = Foo.new
16
- adam.name = 'Adam Beynon'
17
- puts adam.name
18
- adam.do_task
@@ -1,10 +0,0 @@
1
- require 'bundler'
2
- Bundler.require
3
-
4
- run Opal::Server.new { |s|
5
- s.append_path 'app'
6
-
7
- s.index_path = 'index.html.erb'
8
- s.debug = true
9
- s.main = 'app'
10
- }
@@ -1,10 +0,0 @@
1
- <!doctype html>
2
- <html lang="en">
3
- <head>
4
- <meta charset="utf-8">
5
- <title>opal server example</title>
6
- <%= javascript_include_tag 'app' %>
7
- </head>
8
- <body>
9
- </body>
10
- </html>
@@ -1,33 +0,0 @@
1
- # A base namespace for template libraries to register their templates. This
2
- # file is not loaded by opal directly, so a templating library would need to
3
- # require this file itself (e.g. opal-erb.rb requires it, so each erb template)
4
- # doesn't need to do it itself.
5
- #
6
- # # foo.erb
7
- # ERB.new('foo') do
8
- # # template body
9
- # end
10
- #
11
- # # inside opal-erb.rb
12
- # class ERB
13
- # def initialize(name, &block)
14
- # @block = block
15
- # Template[name] = self
16
- # end
17
- #
18
- # # standard method for templates
19
- # def render(ctx)
20
- # #...
21
- # end
22
- # end
23
- #
24
- module Template
25
- @_cache = {}
26
- def self.[](name)
27
- @_cache[name]
28
- end
29
-
30
- def self.[]=(name, instance)
31
- @_cache[name] = instance
32
- end
33
- end