opal 0.7.0.beta2 → 0.7.0.beta3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a9bd47fb47cabeb742adca4e6b377de113225b60
4
- data.tar.gz: 0dfa5e47116f8d56b3d1a2ff0b9473fa9b563b87
3
+ metadata.gz: 56f72a2aa585530e324d1024147329f90ac699ef
4
+ data.tar.gz: a75ca4d5fc0abc995d98d6e9884286986fe54666
5
5
  SHA512:
6
- metadata.gz: 3965105a918d9cfded13bf9526cdda32b73caa31c4ae7e3760f36c205f5cdb1e359604e9d6e4a519d0687ea0b0eced908140b54ddf952b4c7036ef0d0736a2b9
7
- data.tar.gz: 5764370dc015b931115ab0bdb7e61b1a6699b067179545fdea0d5dd86366929e58b391726ef4257e752d5ebd33d9e9bdb316fd4f09309ec0c3ce24d28225f1b3
6
+ metadata.gz: 2dd0158e79a73ea54fed5a02fe222606b8a4d45198c1338f3c17f902a30e37e19da3d8347d82256a2f8e70faeb31c04a6076bc16a630662c93d9c0d52b657cd7
7
+ data.tar.gz: f59534fa214044c4cb01096f722745db095b4c67dc4b1129b5ec70fe24d4e7653729e219847b62445281ca061f905a83a945f917b92825d43c42a1059a4be0d8
data/.travis.yml CHANGED
@@ -25,12 +25,16 @@ matrix:
25
25
  - rvm: jruby
26
26
  env: RUN=rspec
27
27
 
28
+ - rvm: jruby-head
29
+ env: RUN=rspec
30
+
28
31
  allow_failures:
29
32
  - rvm: 1.8.7
30
33
  - rvm: 1.9.3
31
34
  - rvm: 2.0.0
32
35
  - rvm: rbx
33
36
  - rvm: jruby
37
+ - rvm: jruby-head
34
38
 
35
39
 
36
40
  before_install:
data/CHANGELOG.md CHANGED
@@ -1,5 +1,12 @@
1
1
  ## edge (upcoming 0.7)
2
2
 
3
+ * `String#to_proc` now uses `__send__` instead of `send` for calling
4
+ methods on receivers.
5
+
6
+ * Deprecated `Opal::Sprockets::Environment`. It can easily be replaced by `Opal::Server` or by appending `Opal.paths` to a `Sprockets::Environment`:
7
+
8
+ Sprockets::Environment.new.tap { |e| Opal.paths.each {|p| e.append_path(p)} }
9
+
3
10
  * Add `Set` methods `#classify`, `#collect!`, `#map!`, `#subtract` `#replace`,
4
11
  `#difference` and `#eql?`
5
12
 
data/Rakefile CHANGED
@@ -76,6 +76,7 @@ Example: rake dist DIR=cdn/opal/master
76
76
  DESC
77
77
  task :dist do
78
78
  require 'opal/util'
79
+ require 'opal/sprockets/environment'
79
80
 
80
81
  Opal::Processor.arity_check_enabled = false
81
82
  Opal::Processor.const_missing_enabled = false
@@ -0,0 +1,13 @@
1
+ # 'asdf' =~ /(a)./
2
+ #
3
+ # p $'
4
+ # p $1
5
+ # p $2
6
+ # `console.log(2, $opal.gvars['1'])`
7
+ # b = $1
8
+ # `console.log(1, b)`
9
+ # nil
10
+
11
+ puts [*1..3].to_s
12
+ puts [*(1..3)].to_s
13
+ puts [*Object.new].to_s
@@ -0,0 +1 @@
1
+
@@ -1,4 +1,3 @@
1
- require 'opal/sprockets/environment'
2
1
  require 'opal/sprockets/processor'
3
2
  require 'opal/sprockets/erb'
4
3
  require 'opal/sprockets/server'
@@ -19,6 +19,8 @@ module Opal
19
19
  # do this for you.
20
20
  class Environment < ::Sprockets::Environment
21
21
  def initialize *args
22
+ warn "WARNING: Opal::Sprockets::Environment is deprecated. "\
23
+ "Please use Opal::Server directly or append Opal.paths to the environment manually."
22
24
  super
23
25
  append_opal_paths
24
26
  end
@@ -75,7 +75,7 @@ module Opal
75
75
 
76
76
  if self.class.source_map_enabled
77
77
  register_source_map(context.logical_path, result.source_map.to_s)
78
- "#{result.to_s}\n//# sourceMappingURL=#{context.logical_path}.map\n"
78
+ "#{result.to_s}\n//# sourceMappingURL=#{File.basename(context.logical_path)}.map\n"
79
79
  else
80
80
  result.to_s
81
81
  end
@@ -104,7 +104,7 @@ module Opal
104
104
  :const_missing => const_missing_enabled,
105
105
  :dynamic_require_severity => dynamic_require_severity,
106
106
  :irb => irb_enabled,
107
- :inline_operators => inline_operators_enabled
107
+ :inline_operators => inline_operators_enabled,
108
108
  }
109
109
 
110
110
  path_reader = ::Opal::Sprockets::PathReader.new(context.environment, context)
@@ -6,7 +6,8 @@ require 'rack/deflater'
6
6
  require 'rack/directory'
7
7
  require 'rack/showexceptions'
8
8
  require 'opal/source_map'
9
- require 'opal/sprockets/environment'
9
+ require 'sprockets'
10
+ require 'sourcemap'
10
11
  require 'erb'
11
12
 
12
13
  module Opal
@@ -35,6 +36,9 @@ module Opal
35
36
 
36
37
  # "logical_name" of a BundledAsset keeps the .js extension
37
38
  source = register[asset.logical_path.sub(/\.js$/, '')]
39
+ map = JSON.parse(source)
40
+ map['sources'] = map['sources'].map {|s| "#{prefix}/#{s}"}
41
+ source = map.to_json
38
42
  return not_found(asset) if source.nil?
39
43
 
40
44
  return [200, {"Content-Type" => "text/json"}, [source.to_s]]
@@ -73,10 +77,12 @@ module Opal
73
77
  @use_index = true
74
78
  @public_root = nil
75
79
  @public_urls = ['/']
76
- @sprockets = options.fetch(:sprockets, Environment.new)
80
+ @sprockets = options.fetch(:sprockets, ::Sprockets::Environment.new)
77
81
  @debug = options.fetch(:debug, true)
78
82
  @prefix = options.fetch(:prefix, '/assets')
79
83
 
84
+ Opal.paths.each { |p| @sprockets.append_path(p) }
85
+
80
86
  yield self if block_given?
81
87
  create_app
82
88
  end
data/lib/opal/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Opal
2
- VERSION = '0.7.0.beta2'
2
+ VERSION = '0.7.0.beta3'
3
3
  end
@@ -16,7 +16,7 @@ module Enumerable
16
16
  result = false;
17
17
  return $breaker;
18
18
  }
19
- }
19
+ };
20
20
  }
21
21
  else {
22
22
  self.$each.$$p = function(obj) {
@@ -24,7 +24,7 @@ module Enumerable
24
24
  result = false;
25
25
  return $breaker;
26
26
  }
27
- }
27
+ };
28
28
  }
29
29
 
30
30
  self.$each();
data/opal/corelib/hash.rb CHANGED
@@ -501,6 +501,44 @@ class Hash
501
501
  }
502
502
  end
503
503
 
504
+ `var hash_ids = null;`
505
+ def hash
506
+ %x{
507
+ var top = (hash_ids === null);
508
+ try {
509
+ var key, value,
510
+ hash = ['Hash'],
511
+ keys = self.keys,
512
+ id = self.$object_id(),
513
+ counter = 0;
514
+
515
+ if (top) {
516
+ hash_ids = {}
517
+ }
518
+
519
+ if (hash_ids.hasOwnProperty(id)) {
520
+ return 'self';
521
+ }
522
+
523
+ hash_ids[id] = true;
524
+
525
+ for (var i = 0, length = keys.length; i < length; i++) {
526
+ key = keys[i];
527
+ value = key.$$is_string ? self.smap[key] : self.map[key.$hash()];
528
+ key = key.$hash();
529
+ value = (typeof(value) === 'undefined') ? '' : value.$hash();
530
+ hash.push([key,value]);
531
+ }
532
+
533
+ return hash.sort().join();
534
+ } finally {
535
+ if (top) {
536
+ hash_ids = null;
537
+ }
538
+ }
539
+ }
540
+ end
541
+
504
542
  alias include? has_key?
505
543
 
506
544
  def index(object)
@@ -569,11 +607,12 @@ class Hash
569
607
  %x{
570
608
  var top = (inspect_ids === null);
571
609
  try {
572
- var inspect = [],
610
+
611
+ var key, value,
612
+ inspect = [],
573
613
  keys = self.keys
574
- _map = self.map,
575
- smap = self.smap,
576
- id = #{object_id};
614
+ id = self.$object_id(),
615
+ counter = 0;
577
616
 
578
617
  if (top) {
579
618
  inspect_ids = {}
@@ -586,12 +625,11 @@ class Hash
586
625
  inspect_ids[id] = true;
587
626
 
588
627
  for (var i = 0, length = keys.length; i < length; i++) {
589
- var key = keys[i],
590
- value = key.$$is_string ? smap[key] : _map[key.$hash()];
591
-
592
- value = value;
593
- key = key;
594
- inspect.push(key.$inspect() + '=>' + value.$inspect());
628
+ key = keys[i];
629
+ value = key.$$is_string ? self.smap[key] : self.map[key.$hash()];
630
+ key = key.$inspect();
631
+ value = value.$inspect();
632
+ inspect.push(key + '=>' + value);
595
633
  }
596
634
 
597
635
  return '{' + inspect.join(', ') + '}';
@@ -4,7 +4,7 @@ class Regexp
4
4
  class << self
5
5
  def escape(string)
6
6
  %x{
7
- return string.replace(/([-[\]/{}()*+?.^$\\| ])/g, '\\$1')
7
+ return string.replace(/([-[\]\/{}()*+?.^$\\| ])/g, '\\$1')
8
8
  .replace(/[\n]/g, '\\n')
9
9
  .replace(/[\r]/g, '\\r')
10
10
  .replace(/[\f]/g, '\\f')
@@ -926,7 +926,7 @@ class String
926
926
  proc do |*args, &block|
927
927
  raise ArgumentError, "no receiver given" if args.empty?
928
928
  obj = args.shift
929
- obj.send(sym, *args, &block)
929
+ obj.__send__(sym, *args, &block)
930
930
  end
931
931
  end
932
932
 
@@ -57,8 +57,8 @@ opal_filter "Hash" do
57
57
 
58
58
  fails "Hash#hash returns the same hash for recursive hashes through arrays"
59
59
  fails "Hash#hash returns the same hash for recursive hashes"
60
- fails "Hash#hash generates a hash for recursive hash structures"
61
- fails "Hash#hash returns a value which doesn't depend on the hash order"
60
+ # fails "Hash#hash generates a hash for recursive hash structures"
61
+ # fails "Hash#hash returns a value which doesn't depend on the hash order"
62
62
 
63
63
  fails "Hash#invert compares new keys with eql? semantics"
64
64
 
@@ -0,0 +1 @@
1
+ puts 'smap!'
@@ -0,0 +1 @@
1
+ puts 'other!'
@@ -5,7 +5,7 @@ require 'opal/sprockets/path_reader'
5
5
  describe Opal::Sprockets::PathReader do
6
6
  subject(:path_reader) { described_class.new(env, context) }
7
7
 
8
- let(:env) { Opal::Environment.new }
8
+ let(:env) { Sprockets::Environment.new.tap { |e| Opal.paths.each {|p| e.append_path(p)} } }
9
9
  let(:context) { double('context', depend_on: nil, depend_on_asset: nil) }
10
10
 
11
11
  let(:logical_path) { 'sprockets_file' }
@@ -1,4 +1,5 @@
1
1
  require 'lib/spec_helper'
2
+ require 'sourcemap'
2
3
  require 'rack/test'
3
4
 
4
5
  describe Opal::Server do
@@ -8,6 +9,7 @@ describe Opal::Server do
8
9
  described_class.new { |s|
9
10
  s.main = 'opal'
10
11
  s.debug = false
12
+ s.append_path File.expand_path('../../fixtures', __FILE__)
11
13
  s.sprockets.logger = Logger.new('/dev/null')
12
14
  }
13
15
  end
@@ -17,4 +19,50 @@ describe Opal::Server do
17
19
  expect(last_response).to be_ok
18
20
  end
19
21
 
22
+ describe 'source maps' do
23
+ it 'serves map on a top level file' do
24
+ get '/assets/source_map.js'
25
+ expect(last_response).to be_ok
26
+
27
+ get '/assets/source_map.map'
28
+ expect(last_response).to be_ok
29
+ end
30
+
31
+ it 'serves map on a subfolder file' do
32
+ js_path = '/assets/source_map/subfolder/other_file.js'
33
+ map_path = '/assets/source_map/subfolder/other_file.map'
34
+
35
+ get js_path
36
+
37
+ expect(last_response).to be_ok
38
+ received_map_path = extract_linked_map(last_response.body)
39
+ expect(File.expand_path(received_map_path, js_path+'/..')).to eq(map_path)
40
+
41
+ get '/assets/source_map/subfolder/other_file.map'
42
+ expect(last_response).to be_ok
43
+ end
44
+
45
+ it 'serves map on a subfolder file' do
46
+ js_path = '/assets/source_map/subfolder/other_file.js'
47
+ map_path = '/assets/source_map/subfolder/other_file.map'
48
+
49
+ get js_path
50
+
51
+ expect(last_response).to be_ok
52
+ received_map_path = extract_linked_map(last_response.body)
53
+ expect(File.expand_path(received_map_path, js_path+'/..')).to eq(map_path)
54
+
55
+
56
+ get '/assets/source_map/subfolder/other_file.map'
57
+ expect(last_response).to be_ok
58
+ map = ::SourceMap::Map.from_json(last_response.body)
59
+ expect(map.sources).to include('/assets/source_map/subfolder/other_file.rb')
60
+ end
61
+ end
62
+
63
+ def extract_linked_map(body)
64
+ source_map_comment_regexp = %r{//# sourceMappingURL=(.*)$}
65
+ expect(body).to match(source_map_comment_regexp)
66
+ body.scan(source_map_comment_regexp).first.first
67
+ end
20
68
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: opal
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.0.beta2
4
+ version: 0.7.0.beta3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adam Beynon
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-11-12 00:00:00.000000000 Z
11
+ date: 2014-11-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sourcemap
@@ -209,6 +209,7 @@ files:
209
209
  - README.md
210
210
  - Rakefile
211
211
  - benchmarks/operators.rb
212
+ - benchmarks/prova.js.rb
212
213
  - bin/opal
213
214
  - bin/opal-build
214
215
  - bin/opal-mspec
@@ -223,6 +224,7 @@ files:
223
224
  - examples/sinatra/app/application.rb
224
225
  - examples/sinatra/config.ru
225
226
  - lib/mspec/opal/main.rb.erb
227
+ - lib/mspec/opal/new.html.erb
226
228
  - lib/mspec/opal/rake_task.rb
227
229
  - lib/mspec/opal/runner.rb
228
230
  - lib/mspec/opal/special_calls.rb
@@ -378,6 +380,8 @@ files:
378
380
  - spec/lib/fixtures/required_tree_test/required_file1.rb
379
381
  - spec/lib/fixtures/required_tree_test/required_file2.rb
380
382
  - spec/lib/fixtures/requires.rb
383
+ - spec/lib/fixtures/source_map.rb
384
+ - spec/lib/fixtures/source_map/subfolder/other_file.rb
381
385
  - spec/lib/fixtures/sprockets_file.js.rb
382
386
  - spec/lib/fixtures/sprockets_require_tree_test.rb
383
387
  - spec/lib/hike_path_finder_spec.rb
@@ -416,7 +420,6 @@ files:
416
420
  - spec/lib/shared/path_finder_shared.rb
417
421
  - spec/lib/shared/path_reader_shared.rb
418
422
  - spec/lib/spec_helper.rb
419
- - spec/lib/sprockets/environment_spec.rb
420
423
  - spec/lib/sprockets/erb_spec.rb
421
424
  - spec/lib/sprockets/path_reader_spec.rb
422
425
  - spec/lib/sprockets/processor_spec.rb
@@ -695,7 +698,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
695
698
  version: 1.3.1
696
699
  requirements: []
697
700
  rubyforge_project:
698
- rubygems_version: 2.4.2
701
+ rubygems_version: 2.4.3
699
702
  signing_key:
700
703
  specification_version: 4
701
704
  summary: Ruby runtime and core library for javascript
@@ -751,6 +754,8 @@ test_files:
751
754
  - spec/lib/fixtures/required_tree_test/required_file1.rb
752
755
  - spec/lib/fixtures/required_tree_test/required_file2.rb
753
756
  - spec/lib/fixtures/requires.rb
757
+ - spec/lib/fixtures/source_map.rb
758
+ - spec/lib/fixtures/source_map/subfolder/other_file.rb
754
759
  - spec/lib/fixtures/sprockets_file.js.rb
755
760
  - spec/lib/fixtures/sprockets_require_tree_test.rb
756
761
  - spec/lib/hike_path_finder_spec.rb
@@ -789,7 +794,6 @@ test_files:
789
794
  - spec/lib/shared/path_finder_shared.rb
790
795
  - spec/lib/shared/path_reader_shared.rb
791
796
  - spec/lib/spec_helper.rb
792
- - spec/lib/sprockets/environment_spec.rb
793
797
  - spec/lib/sprockets/erb_spec.rb
794
798
  - spec/lib/sprockets/path_reader_spec.rb
795
799
  - spec/lib/sprockets/processor_spec.rb
@@ -1,30 +0,0 @@
1
- require 'lib/spec_helper'
2
- require 'opal/sprockets/environment'
3
-
4
- describe Opal::Environment do
5
- let(:env) { described_class.new }
6
- let(:logical_path) { 'sprockets_file' }
7
-
8
- before { env.append_path File.expand_path('../../fixtures/', __FILE__) }
9
-
10
- it 'compiles Ruby to JS' do
11
- expect(env[logical_path].source).to include('$puts(')
12
- expect(env[logical_path+'.js'].source).to include('$puts(')
13
- end
14
-
15
- describe 'require_tree sprockets directive' do
16
- it 'is still supported' do
17
- source = env['sprockets_require_tree_test'].source
18
- expect(source).to include('required_file1')
19
- expect(source).to include('required_file2')
20
- end
21
- end
22
-
23
- describe 'require_tree helper' do
24
- it 'is handled by the processor' do
25
- source = env['require_tree_test'].source
26
- expect(source).to include('required_file1')
27
- expect(source).to include('required_file2')
28
- end
29
- end
30
- end