opal-jquery 0.4.2 → 0.4.3

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 (50) hide show
  1. checksums.yaml +5 -5
  2. data/.editorconfig +12 -0
  3. data/.travis.yml +22 -15
  4. data/CHANGELOG.md +41 -3
  5. data/Gemfile +13 -2
  6. data/README.md +1 -1
  7. data/Rakefile +22 -4
  8. data/config.ru +4 -6
  9. data/lib/opal/jquery/element.rb +77 -24
  10. data/lib/opal/jquery/http.rb +5 -1
  11. data/lib/opal/jquery/version.rb +1 -1
  12. data/opal-jquery.gemspec +7 -6
  13. data/{spec → spec-opal}/document_spec.rb +11 -4
  14. data/{spec → spec-opal}/element/after_spec.rb +1 -1
  15. data/{spec → spec-opal}/element/animations_spec.rb +5 -5
  16. data/{spec → spec-opal}/element/append_spec.rb +1 -1
  17. data/{spec → spec-opal}/element/append_to_spec.rb +1 -1
  18. data/{spec → spec-opal}/element/at_spec.rb +1 -1
  19. data/{spec → spec-opal}/element/attributes_spec.rb +1 -1
  20. data/{spec → spec-opal}/element/before_spec.rb +1 -1
  21. data/{spec → spec-opal}/element/class_name_spec.rb +2 -2
  22. data/{spec → spec-opal}/element/css_spec.rb +3 -3
  23. data/{spec → spec-opal}/element/display_spec.rb +6 -6
  24. data/spec-opal/element/expose_spec.rb +73 -0
  25. data/{spec → spec-opal}/element/height_width_spec.rb +1 -1
  26. data/{spec → spec-opal}/element/inspect_spec.rb +1 -1
  27. data/{spec → spec-opal}/element/iterable_spec.rb +1 -1
  28. data/{spec → spec-opal}/element/length_spec.rb +1 -1
  29. data/spec-opal/element/method_missing_spec.rb +34 -0
  30. data/{spec → spec-opal}/element/prepend_spec.rb +1 -1
  31. data/{spec → spec-opal}/element/to_s_spec.rb +1 -1
  32. data/{spec → spec-opal}/element/traversing_spec.rb +5 -5
  33. data/spec-opal/element_spec.rb +261 -0
  34. data/{spec → spec-opal}/event_spec.rb +1 -1
  35. data/{spec → spec-opal}/fixtures/simple.txt +0 -0
  36. data/{spec → spec-opal}/fixtures/user.json +0 -0
  37. data/{spec → spec-opal}/http_spec.rb +1 -1
  38. data/{spec → spec-opal}/jquery/index.html.erb +1 -1
  39. data/spec-opal/jquery/index3.html.erb +10 -0
  40. data/{spec/jquery/jquery.js → spec-opal/jquery/jquery-1.8.3.js} +0 -0
  41. data/spec-opal/jquery/jquery-3.0.0.js +4 -0
  42. data/spec-opal/kernel_spec.rb +15 -0
  43. data/{spec → spec-opal}/local_storage_spec.rb +1 -1
  44. data/{spec → spec-opal}/spec_helper.rb +10 -0
  45. data/{spec → spec-opal}/zepto/index.html.erb +0 -0
  46. data/{spec → spec-opal}/zepto/zepto.js +0 -0
  47. metadata +63 -76
  48. data/spec/element/method_missing_spec.rb +0 -32
  49. data/spec/element_spec.rb +0 -273
  50. data/spec/kernel_spec.rb +0 -7
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 5756803ad9fee99689694217261dfbba137d50d7
4
- data.tar.gz: 4bfe28a1b93a06735ed6a83fce93855d8e52ca7e
2
+ SHA256:
3
+ metadata.gz: 03e8ec06442542e3a02161a4269dccf0b8462ae075ccd62754677edc32bf9be3
4
+ data.tar.gz: 97cc7ccc004b2efe8f5aaed1977897fdb77502396bcee847e8ec2f9f49c1e9bf
5
5
  SHA512:
6
- metadata.gz: 87271b5c13e5c02aadf0faa1515f8a8c65c5771c1e2343d8675f3ea0fdf603094a5eae73792481b7aa8b0c637e30956dc9ddc8895c50d17d6dffffcd0fbfa05f
7
- data.tar.gz: f86975805b7a90566de578722020aba59c512754895220e365ae109a4a78c8e4e5f1781b30d756929a0ed1c27102d5404a69f863cc337bf717772e4ff0adb5f3
6
+ metadata.gz: ab2f982ed40e4a462544cc0ebc050858a31ef381f6f57523d249afb032873662512f1b19219266f48efacaecc6335ee89744191fd0f952f93d88a44c61ca2672
7
+ data.tar.gz: 23a15f17d4230d9204685c45c1f537470f6fcc9357f8097d0ec6098d58dbd572a87050e53bdfc9ea023c236f5fc4e2d4bf07d323152d21ef4f4c83b7cc7f32f6
@@ -0,0 +1,12 @@
1
+ root = true
2
+
3
+ [*]
4
+ indent_style = space
5
+ indent_size = 2
6
+ end_of_line = lf
7
+ charset = utf-8
8
+ trim_trailing_whitespace = true
9
+ insert_final_newline = true
10
+
11
+ [*.md]
12
+ trim_trailing_whitespace = false
@@ -2,25 +2,18 @@ language: ruby
2
2
  sudo: false
3
3
 
4
4
  fast_finish: true
5
- script: rake $RUN
6
-
7
- before_install:
8
- # thanks to https://mediocre.com/forum/topics/phantomjs-2-and-travis-ci-we-beat-our-heads-against-a-wall-so-you-dont-have-to
9
- - wget https://s3.amazonaws.com/travis-phantomjs/phantomjs-2.0.0-ubuntu-12.04.tar.bz2
10
- - tar -xjf phantomjs-2.0.0-ubuntu-12.04.tar.bz2
11
- # Keep track of which version of phantomjs we're running the specs against
12
- - phantomjs -v
5
+ script: bundle exec rake $RUN
13
6
 
14
7
  matrix:
15
8
  include:
16
- - rvm: 2.3.1
17
- env: PATH=".:$PATH"
18
- - rvm: 2.2.4
19
- env: PATH=".:$PATH"
9
+ - rvm: 2.4.2
10
+ env: OPAL_VERSION='master'
11
+ - rvm: 2.3.4
12
+ env: OPAL_VERSION='~> 0.10.5'
20
13
  - rvm: 2.1.10
21
- env: PATH=".:$PATH" RACK_VERSION='< 2.0'
14
+ env: RACK_VERSION='< 2.0'
22
15
  - rvm: 2.0.0
23
- env: PATH=".:$PATH" RACK_VERSION='< 2.0'
16
+ env: RACK_VERSION='< 2.0'
24
17
 
25
18
  # We use 2.1.9 to differentiate the rvm version
26
19
  # as travis doesn't allow failures by env.
@@ -28,5 +21,19 @@ matrix:
28
21
  env: RUN=zepto PATH=".:$PATH" RACK_VERSION='< 2.0'
29
22
 
30
23
  allow_failures:
31
- - rvm: 2.1.9
24
+ - rvm: 2.1.9 # zepto
25
+
26
+
27
+ cache:
28
+ bundler: true
29
+ directories:
30
+ - node_modules
31
+
32
+ before_install:
33
+ - gem update --system
34
+ - "export PATH=$PWD/travis_phantomjs/phantomjs-2.1.1-linux-x86_64/bin:$PATH"
35
+ - "if [ $(phantomjs --version) != '2.1.1' ]; then rm -rf $PWD/travis_phantomjs; mkdir -p $PWD/travis_phantomjs; fi"
36
+ - "if [ $(phantomjs --version) != '2.1.1' ]; then wget https://assets.membergetmember.co/software/phantomjs-2.1.1-linux-x86_64.tar.bz2 -O $PWD/travis_phantomjs/phantomjs-2.1.1-linux-x86_64.tar.bz2; fi"
37
+ - "if [ $(phantomjs --version) != '2.1.1' ]; then tar -xvf $PWD/travis_phantomjs/phantomjs-2.1.1-linux-x86_64.tar.bz2 -C $PWD/travis_phantomjs; fi"
38
+ - "phantomjs --version"
32
39
 
@@ -1,8 +1,46 @@
1
- ## 0.4.2 2016-07-04
1
+ ## (0.5.0)[https://github.com/opal/opal-jquery/compare/v0.4.3...HEAD] Unreleased
2
+
3
+ *see diff*
4
+
5
+ ## (0.4.3)[https://github.com/opal/opal-jquery/compare/v0.4.2...v0.4.3] 2018-07-24
6
+
7
+ * Add `Element#==` as an alias of `.is()`
8
+
9
+ * Add `Element#method_missing` to allow not yet wrapped methods and plugins to be accessed with zero setup
10
+
11
+ * Avoid `||` in JS-land because it would consider some values as falsy (e.g. `""` and `0`). **breaking**
12
+
13
+ * Call `Element#prop` via `Native.call` to get the right semantics around `nil` vs. `undefined` **breaking**
14
+
15
+ * Expose `Element#click`
16
+
17
+ * Fix semantics of `Element#attr` to better reflect jQuery's **breaking**
18
+
19
+ * Skip sending a callback to `Element#animate` if no block is given
20
+
21
+ * Let `Element#data` return a usable Ruby object (`Array`/`Hash`) instead of a native one **breaking**
22
+
23
+ * Don't wrap events with `Event.new` if no args are provided or the event is not a native object to increase performance in `Element#on` and `Element#one`
24
+
25
+ * Rename the internal property holding the callback wrapper in `Element#on` and `Element#one` from `._jq_wrap` to `.$$jqwrap` to avoid polluting instance variables and following the custom of Opal's core classes
26
+
27
+ * Fix `Element#value`, `Element#height` and `Element#width` to perform the `||` at ruby level to avoid overwriting values that are *falsy* in JavaScript with `nil` **breaking**
28
+
29
+ * Add `Element#==` as an alias to jQuery's `.is()`
30
+
31
+ * Add `Element#method_missing` and `Element#respond_to_missing?` to forward calls to native plugins
32
+
33
+ * Add `HTTP#inspect` with a basic summary
34
+
35
+ * Updated specs to also use jQuery 3
36
+
37
+ * Allow Opal v0.11.0
38
+
39
+ ## (0.4.2)[https://github.com/opal/opal-jquery/compare/v0.4.1...v0.4.2] 2016-07-04
2
40
 
3
41
  * Allow Opal v0.10.0
4
42
 
5
- ## 0.4.1 2015-11-02
43
+ ## (0.4.1)[https://github.com/opal/opal-jquery/compare/v0.4.0...v0.4.1] 2015-11-02
6
44
 
7
45
  * Updated specs to use jQuery 1.8 (that was initially released in 2012)
8
46
 
@@ -12,7 +50,7 @@
12
50
 
13
51
  * `Document.ready?` now works even after the document is loaded (unlike jQuery)
14
52
 
15
- ## 0.4.0 2015-07-17
53
+ ## (0.4.0)[https://github.com/opal/opal-jquery/compare/v0.3.0...v0.4.0] 2015-07-17
16
54
 
17
55
  * `Element#[]=` now removes the attribute when the assigned value is nil.
18
56
 
data/Gemfile CHANGED
@@ -1,6 +1,17 @@
1
1
  source 'https://rubygems.org'
2
2
  gemspec
3
3
 
4
- gem 'opal', ENV['OPAL_VERSION'] || '~> 0.10.0'
5
- gem 'opal-rspec', github: 'opal/opal-rspec', submodules: true
4
+ case (opal_version = ENV['OPAL_VERSION'])
5
+ when 'master'
6
+ gem 'opal', github: 'opal/opal', branch: 'master'
7
+ gem 'opal-sprockets', github: 'opal/opal-sprockets'
8
+ gem 'opal-rspec', github: 'opal/opal-rspec', branch: 'elia/opal-master', submodules: true
9
+ when nil
10
+ gem 'opal' # let bundler pick a version
11
+ else
12
+ gem 'opal', opal_version
13
+ end
14
+
15
+ # gem 'opal-rspec', github: 'opal/opal-rspec', submodules: true
16
+ # gem 'opal-rspec', path: '../opal-rspec'
6
17
  gem 'rack', ENV['RACK_VERSION'] || '> 0'
data/README.md CHANGED
@@ -5,7 +5,7 @@
5
5
  opal-jquery provides DOM access to opal by wrapping jQuery (or zepto)
6
6
  and providing a nice ruby syntax for dealing with jQuery instances.
7
7
 
8
- See the Opal website for [documentation](http://opalrb.org/docs/jquery).
8
+ <!-- See the Opal website for [documentation](http://opalrb.org/docs/jquery). -->
9
9
 
10
10
 
11
11
 
data/Rakefile CHANGED
@@ -2,13 +2,22 @@ require 'bundler'
2
2
  Bundler.require
3
3
  Bundler::GemHelper.install_tasks
4
4
 
5
+ ENV['RUNNER'] = 'chrome'
6
+
5
7
  require 'opal/rspec/rake_task'
6
- Opal::RSpec::RakeTask.new(:default) do |s|
7
- s.index_path = 'spec/jquery/index.html.erb'
8
+ Opal::RSpec::RakeTask.new(:default) do |server, task|
9
+ server.index_path = 'spec-opal/jquery/index.html.erb'
10
+ task.default_path = 'spec-opal'
11
+ end
12
+
13
+ Opal::RSpec::RakeTask.new(:jquery3) do |server, task|
14
+ server.index_path = 'spec-opal/jquery/index3.html.erb'
15
+ task.default_path = 'spec-opal'
8
16
  end
9
17
 
10
- Opal::RSpec::RakeTask.new(:zepto) do |s|
11
- s.index_path = 'spec/zepto/index.html.erb'
18
+ Opal::RSpec::RakeTask.new(:zepto) do |server, task|
19
+ server.index_path = 'spec-opal/zepto/index.html.erb'
20
+ task.default_path = 'spec-opal'
12
21
  end
13
22
 
14
23
  desc "Build build/opal-jquery.js"
@@ -64,6 +73,11 @@ namespace :doc do
64
73
  sh 'git', 'clone', '-b', 'gh-pages', '--', remote, doc_repo.to_s
65
74
  end
66
75
 
76
+ # To generate docs that live on http://opalrb.org/opal-jquery/ use the
77
+ # `rake doc` task
78
+ #
79
+ # DOC_REPO_REMOTE=https://github.com/opal/opal-jquery.git bundle exec rake doc
80
+ # open gh-pages/index.html
67
81
  task :default => doc_repo.to_s do
68
82
  git = current_git_release.call
69
83
  name = 'api'
@@ -72,6 +86,10 @@ namespace :doc do
72
86
  "--readme opal/README.md -o gh-pages/doc/#{git}/#{name}"
73
87
  puts command; system command
74
88
  end
89
+
90
+ # To generate api docs on rubygems: http://www.rubydoc.info/gems/opal-jquery/0.4.2
91
+ # yard --main README.md --markup markdown --github
92
+ # open doc/index.html
75
93
  end
76
94
 
77
95
  task :doc => 'doc:default'
data/config.ru CHANGED
@@ -1,13 +1,11 @@
1
1
  require 'bundler'
2
2
  Bundler.require
3
3
 
4
- require 'opal-rspec'
5
- Opal.append_path File.expand_path('../spec', __FILE__)
4
+ require 'opal/rspec'
6
5
 
7
- run Opal::Server.new { |s|
6
+ sprockets_env = Opal::RSpec::SprocketsEnvironment.new
7
+ run Opal::Server.new(sprockets: sprockets_env) { |s|
8
8
  s.main = 'opal/rspec/sprockets_runner'
9
- s.append_path 'spec'
9
+ sprockets_env.add_spec_paths_to_sprockets
10
10
  s.debug = false
11
- s.index_path = 'spec/jquery/index.html.erb'
12
11
  }
13
-
@@ -298,10 +298,12 @@ class Element < `#{JQUERY_CLASS.to_n}`
298
298
  # @!method get
299
299
  alias_native :get
300
300
 
301
- # @!method prop(name, value = nil)
301
+ # @!method prop(name, value = undefined)
302
302
  #
303
303
  # Get or set the property `name` on each element in collection.
304
- alias_native :prop
304
+ def prop(*args)
305
+ Native.call(self, :prop, *args)
306
+ end
305
307
 
306
308
  alias succ next
307
309
  alias << append
@@ -338,6 +340,9 @@ class Element < `#{JQUERY_CLASS.to_n}`
338
340
  # @!method submit()
339
341
  alias_native :submit
340
342
 
343
+ # @!method click()
344
+ alias_native :click
345
+
341
346
  # @!method text=(text)
342
347
  #
343
348
  # Set text content of each element in this collection.
@@ -416,10 +421,11 @@ class Element < `#{JQUERY_CLASS.to_n}`
416
421
  var size = args.length;
417
422
  switch (size) {
418
423
  case 1:
419
- return #{self[`args[0]`]};
424
+ var result = self.attr(args[0]);
425
+ return( (result == null) ? nil : result );
420
426
  break;
421
427
  case 2:
422
- return #{self[`args[0]`] = `args[1]`};
428
+ return self.attr(args[0], args[1]);
423
429
  break;
424
430
  default:
425
431
  #{raise ArgumentError, '#attr only accepts 1 or 2 arguments'}
@@ -508,16 +514,21 @@ class Element < `#{JQUERY_CLASS.to_n}`
508
514
  # is given, the block is run as a callback when the animation finishes.
509
515
  def animate(params, &block)
510
516
  speed = params.has_key?(:speed) ? params.delete(:speed) : 400
511
- %x{
512
- self.animate(#{params.to_n}, #{speed}, function() {
513
- #{block.call if block_given?}
514
- })
515
- }
517
+ if block_given?
518
+ `self.animate(#{params.to_n}, #{speed}, block)`
519
+ else
520
+ `self.animate(#{params.to_n}, #{speed})`
521
+ end
516
522
  end
517
523
 
518
524
  def data(*args)
519
525
  %x{
520
526
  var result = self.data.apply(self, args);
527
+ if (
528
+ (typeof(result) === 'object') && !(result instanceof #{JQUERY_CLASS})
529
+ ) {
530
+ result = #{ JSON.from_object `result` };
531
+ }
521
532
  return result == null ? nil : result;
522
533
  }
523
534
  end
@@ -646,15 +657,22 @@ class Element < `#{JQUERY_CLASS.to_n}`
646
657
 
647
658
  def on(name, sel = nil, &block)
648
659
  %x{
649
- var wrapper = function(evt) {
650
- if (evt.preventDefault) {
651
- evt = #{Event.new `evt`};
660
+ var has_args = #{block.arity} !== 0;
661
+
662
+ var wrapper = function() {
663
+ for(var args = new Array(arguments.length), i = 0, ii = args.length; i < ii; i++) {
664
+ args[i] = arguments[i];
665
+ }
666
+
667
+ // Use preventDefault as a canary for native events
668
+ if (has_args && args[0].preventDefault) {
669
+ args[0] = #{Event.new `args[0]`};
652
670
  }
653
671
 
654
- return block.apply(null, arguments);
672
+ return block.apply(null, args);
655
673
  };
656
674
 
657
- block._jq_wrap = wrapper;
675
+ block.$$jqwrap = wrapper;
658
676
 
659
677
  if (sel == nil) {
660
678
  self.on(name, wrapper);
@@ -669,15 +687,22 @@ class Element < `#{JQUERY_CLASS.to_n}`
669
687
 
670
688
  def one(name, sel = nil, &block)
671
689
  %x{
672
- var wrapper = function(evt) {
673
- if (evt.preventDefault) {
674
- evt = #{Event.new `evt`};
690
+ var has_args = #{block.arity} !== 0;
691
+
692
+ var wrapper = function() {
693
+ for(var args = new Array(arguments.length), i = 0, ii = args.length; i < ii; i++) {
694
+ args[i] = arguments[i];
695
+ }
696
+
697
+ // Use preventDefault as a canary for native events
698
+ if (has_args && args[0].preventDefault) {
699
+ args[0] = #{Event.new `args[0]`};
675
700
  }
676
701
 
677
- return block.apply(null, arguments);
702
+ return block.apply(null, args);
678
703
  };
679
704
 
680
- block._jq_wrap = wrapper;
705
+ block.$$jqwrap = wrapper;
681
706
 
682
707
  if (sel == nil) {
683
708
  self.one(name, wrapper);
@@ -696,10 +721,10 @@ class Element < `#{JQUERY_CLASS.to_n}`
696
721
  return self.off(name);
697
722
  }
698
723
  else if (block === nil) {
699
- return self.off(name, sel._jq_wrap);
724
+ return self.off(name, sel.$$jqwrap);
700
725
  }
701
726
  else {
702
- return self.off(name, sel, block._jq_wrap);
727
+ return self.off(name, sel, block.$$jqwrap);
703
728
  }
704
729
  }
705
730
  end
@@ -714,18 +739,46 @@ class Element < `#{JQUERY_CLASS.to_n}`
714
739
  alias size length
715
740
 
716
741
  def value
717
- `self.val() || ""`
742
+ `self.val()` || ""
718
743
  end
719
744
 
720
745
  def height
721
- `self.height() || nil`
746
+ `self.height()` || nil
722
747
  end
723
748
 
724
749
  def width
725
- `self.width() || nil`
750
+ `self.width()` || nil
726
751
  end
727
752
 
728
753
  def position
729
754
  Native(`self.position()`)
730
755
  end
756
+
757
+ def ==(other)
758
+ `self.is(other)`
759
+ end
760
+
761
+ def respond_to_missing?(name, _)
762
+ %x{
763
+ var method = self[#{name}];
764
+ if (typeof(method) === 'function') {
765
+ return true;
766
+ } else {
767
+ return #{super};
768
+ }
769
+ }
770
+ end
771
+
772
+ def method_missing(name, *args, &block)
773
+ args << block if block_given?
774
+
775
+ %x{
776
+ var method = self[#{name}];
777
+ if (typeof(method) === 'function') {
778
+ return method.apply(self, #{args.to_n});
779
+ } else {
780
+ return #{super};
781
+ }
782
+ }
783
+ end
731
784
  end
@@ -165,7 +165,7 @@ class HTTP
165
165
 
166
166
  %x{
167
167
  if (typeof(#{payload}) === 'string') {
168
- #{settings}.data = payload;
168
+ settings.data = payload;
169
169
  }
170
170
  else if (payload != nil) {
171
171
  settings.data = payload.$to_json();
@@ -231,6 +231,10 @@ class HTTP
231
231
  }
232
232
  end
233
233
 
234
+ def inspect
235
+ "#<HTTP @url=#{@url} @method=#{@method}>"
236
+ end
237
+
234
238
  private
235
239
 
236
240
  def promise
@@ -1,5 +1,5 @@
1
1
  module Opal
2
2
  module JQuery
3
- VERSION = '0.4.2'
3
+ VERSION = '0.4.3'
4
4
  end
5
5
  end
@@ -4,19 +4,20 @@ require File.expand_path('../lib/opal/jquery/version', __FILE__)
4
4
  Gem::Specification.new do |s|
5
5
  s.name = 'opal-jquery'
6
6
  s.version = Opal::JQuery::VERSION
7
- s.author = 'Adam Beynon'
8
- s.email = 'adam.beynon@gmail.com'
7
+ s.authors = ['Adam Beynon', 'Elia Schito']
8
+ s.email = 'elia@schito.me'
9
9
  s.homepage = 'http://opalrb.org'
10
- s.summary = 'Opal access to jquery'
11
- s.description = 'Opal DOM library for jquery'
10
+ s.summary = 'Opal access to jQuery'
11
+ s.description = 'Opal DOM library for jQuery'
12
12
 
13
13
  s.files = `git ls-files`.split("\n")
14
14
  s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
15
15
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
16
16
  s.require_paths = ['lib']
17
17
 
18
- s.add_runtime_dependency 'opal', '>= 0.7.0', '< 0.11.0'
19
- s.add_development_dependency 'opal-rspec', '~> 0.5'
18
+ s.add_runtime_dependency 'opal', '>= 0.10.0', '< 0.12.0'
19
+ s.add_development_dependency 'opal-rspec', '~> 0.7.0.rc.2'
20
+ s.add_development_dependency 'opal-sprockets', '~> 0.4.1'
20
21
  s.add_development_dependency 'yard'
21
22
  s.add_development_dependency 'rake'
22
23
  end