opal-jquery 0.4.1 → 0.4.5

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 (51) hide show
  1. checksums.yaml +5 -5
  2. data/.editorconfig +12 -0
  3. data/.travis.yml +27 -9
  4. data/CHANGELOG.md +56 -2
  5. data/Gemfile +15 -0
  6. data/README.md +5 -3
  7. data/Rakefile +22 -4
  8. data/config.ru +4 -6
  9. data/lib/opal/jquery/element.rb +91 -25
  10. data/lib/opal/jquery/http.rb +10 -2
  11. data/lib/opal/jquery/version.rb +1 -1
  12. data/lib/opal/jquery/window.rb +2 -1
  13. data/opal-jquery.gemspec +8 -7
  14. data/{spec → spec-opal}/document_spec.rb +11 -4
  15. data/{spec → spec-opal}/element/after_spec.rb +1 -1
  16. data/{spec → spec-opal}/element/animations_spec.rb +5 -5
  17. data/{spec → spec-opal}/element/append_spec.rb +1 -1
  18. data/{spec → spec-opal}/element/append_to_spec.rb +1 -1
  19. data/{spec → spec-opal}/element/at_spec.rb +1 -1
  20. data/{spec → spec-opal}/element/attributes_spec.rb +1 -1
  21. data/{spec → spec-opal}/element/before_spec.rb +1 -1
  22. data/{spec → spec-opal}/element/class_name_spec.rb +2 -2
  23. data/{spec → spec-opal}/element/css_spec.rb +3 -3
  24. data/{spec → spec-opal}/element/display_spec.rb +6 -6
  25. data/spec-opal/element/expose_spec.rb +73 -0
  26. data/{spec → spec-opal}/element/height_width_spec.rb +1 -1
  27. data/{spec → spec-opal}/element/inspect_spec.rb +1 -1
  28. data/{spec → spec-opal}/element/iterable_spec.rb +1 -1
  29. data/{spec → spec-opal}/element/length_spec.rb +1 -1
  30. data/spec-opal/element/method_missing_spec.rb +34 -0
  31. data/{spec → spec-opal}/element/prepend_spec.rb +1 -1
  32. data/{spec → spec-opal}/element/to_s_spec.rb +1 -1
  33. data/{spec → spec-opal}/element/traversing_spec.rb +5 -5
  34. data/spec-opal/element_spec.rb +261 -0
  35. data/{spec → spec-opal}/event_spec.rb +1 -1
  36. data/{spec → spec-opal}/fixtures/simple.txt +0 -0
  37. data/{spec → spec-opal}/fixtures/user.json +0 -0
  38. data/{spec → spec-opal}/http_spec.rb +15 -1
  39. data/{spec → spec-opal}/jquery/index.html.erb +2 -1
  40. data/spec-opal/jquery/index3.html.erb +10 -0
  41. data/{spec/jquery/jquery.js → spec-opal/jquery/jquery-1.8.3.js} +0 -0
  42. data/spec-opal/jquery/jquery-3.0.0.js +4 -0
  43. data/spec-opal/kernel_spec.rb +15 -0
  44. data/{spec → spec-opal}/local_storage_spec.rb +1 -1
  45. data/{spec → spec-opal}/spec_helper.rb +10 -0
  46. data/{spec → spec-opal}/zepto/index.html.erb +1 -0
  47. data/{spec → spec-opal}/zepto/zepto.js +0 -0
  48. metadata +81 -83
  49. data/spec/element/method_missing_spec.rb +0 -32
  50. data/spec/element_spec.rb +0 -261
  51. data/spec/kernel_spec.rb +0 -7
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 2d0493a816344f5ccc123dad4b73a1bb8319c8d9
4
- data.tar.gz: 8c22311cacb394ab66126673e56231a11e69042d
2
+ SHA256:
3
+ metadata.gz: 5fb5f3264743058c0229d35a857bb530f52f936ba393a8822f72c10a2cd858d6
4
+ data.tar.gz: bdac53f27ef24689e15caad60921b3fd0df36f2e029af0c7b1b5a88fcf03b069
5
5
  SHA512:
6
- metadata.gz: 22671b6eeee6f93555cdd3e55400de6d79b5556668da6a7accc4b7150520d0dc63df263556ba4adf7274a227a120a40314927adc7c5e9dda0143a68b964ccd5a
7
- data.tar.gz: 922d2972c09ad020135ee14cdd3d83c6d88979a7e5994ef0aa055fa1468c6259f4ab402a8f3c1204c2e89fa0d09268c50301c338de82ac5ed5211c60dd4b9c8a
6
+ metadata.gz: 3ecc94487c39a9adccbac5d5a7cb8d5308121c39a7ead21bb78749d4936200cb60540c032d7d8db804c8e55b9a54746e9ced788752f3fae1a5ed4ae75d2636fc
7
+ data.tar.gz: 65d06f7f03862a84b2862530536cf9c2684540bd7070447871cd458c3a932f730733172ffa7e40c619a0a215288618a5ad433ca8209df50c36418c93fee8142c
data/.editorconfig ADDED
@@ -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
data/.travis.yml CHANGED
@@ -2,20 +2,38 @@ language: ruby
2
2
  sudo: false
3
3
 
4
4
  fast_finish: true
5
- script: rake $RUN
5
+ script: bundle exec rake $RUN
6
6
 
7
7
  matrix:
8
8
  include:
9
- - rvm: 2.2
10
- - rvm: 2.1
11
- - rvm: 1.9.3
12
- - rvm: 2.0
9
+ - rvm: 2.4.2
10
+ env: OPAL_VERSION='master'
11
+ - rvm: 2.3.4
12
+ env: OPAL_VERSION='~> 0.10.5'
13
+ - rvm: 2.1.10
14
+ env: RACK_VERSION='< 2.0'
15
+ - rvm: 2.0.0
16
+ env: RACK_VERSION='< 2.0'
13
17
 
14
- # We use 2.1.4 to differentiate the rvm version
18
+ # We use 2.1.9 to differentiate the rvm version
15
19
  # as travis doesn't allow failures by env.
16
- - rvm: 2.1.4
17
- env: RUN=zepto
20
+ - rvm: 2.1.9
21
+ env: RUN=zepto PATH=".:$PATH" RACK_VERSION='< 2.0'
18
22
 
19
23
  allow_failures:
20
- - rvm: 2.1.4
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"
21
39
 
data/CHANGELOG.md CHANGED
@@ -1,4 +1,58 @@
1
- ## 0.4.1 2015-11-02
1
+ ## [0.5.0](https://github.com/opal/opal-jquery/compare/v0.4.5...HEAD) Unreleased
2
+
3
+ *see diff*
4
+
5
+ ## [0.4.5](https://github.com/opal/opal-jquery/compare/v0.4.4...v0.4.5) 2021-07-28
6
+
7
+ * Expose `Element#replace_all` and `Element#replace_with` (#110)
8
+
9
+ * Open the opal dependency to any 1.x
10
+
11
+ ## [0.4.4](https://github.com/opal/opal-jquery/compare/v0.4.3...v0.4.4) 2019-07-01
12
+
13
+ * Use `::Native::Wrapper` where available
14
+
15
+ * Allow Opal 1.0 in gemspec
16
+
17
+ ## [0.4.3](https://github.com/opal/opal-jquery/compare/v0.4.2...v0.4.3) 2018-09-07
18
+
19
+ * Add `Element#==` as an alias of `.is()`
20
+
21
+ * Add `Element#method_missing` to allow not yet wrapped methods and plugins to be accessed with zero setup
22
+
23
+ * Avoid `||` in JS-land because it would consider some values as falsy (e.g. `""` and `0`). **breaking**
24
+
25
+ * Call `Element#prop` via `Native.call` to get the right semantics around `nil` vs. `undefined` **breaking**
26
+
27
+ * Expose `Element#click`
28
+
29
+ * Fix semantics of `Element#attr` to better reflect jQuery's **breaking**
30
+
31
+ * Skip sending a callback to `Element#animate` if no block is given
32
+
33
+ * Let `Element#data` return a usable Ruby object (`Array`/`Hash`) instead of a native one **breaking**
34
+
35
+ * 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`
36
+
37
+ * 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
38
+
39
+ * 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**
40
+
41
+ * Add `Element#==` as an alias to jQuery's `.is()`
42
+
43
+ * Add `Element#method_missing` and `Element#respond_to_missing?` to forward calls to native plugins
44
+
45
+ * Add `HTTP#inspect` with a basic summary
46
+
47
+ * Updated specs to also use jQuery 3
48
+
49
+ * Allow Opal v0.11.0
50
+
51
+ ## [0.4.2](https://github.com/opal/opal-jquery/compare/v0.4.1...v0.4.2) 2016-07-04
52
+
53
+ * Allow Opal v0.10.0
54
+
55
+ ## [0.4.1](https://github.com/opal/opal-jquery/compare/v0.4.0...v0.4.1) 2015-11-02
2
56
 
3
57
  * Updated specs to use jQuery 1.8 (that was initially released in 2012)
4
58
 
@@ -8,7 +62,7 @@
8
62
 
9
63
  * `Document.ready?` now works even after the document is loaded (unlike jQuery)
10
64
 
11
- ## 0.4.0 2015-07-17
65
+ ## [0.4.0](https://github.com/opal/opal-jquery/compare/v0.3.0...v0.4.0) 2015-07-17
12
66
 
13
67
  * `Element#[]=` now removes the attribute when the assigned value is nil.
14
68
 
data/Gemfile CHANGED
@@ -1,2 +1,17 @@
1
1
  source 'https://rubygems.org'
2
2
  gemspec
3
+
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: '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'
17
+ gem 'rack', ENV['RACK_VERSION'] || '> 0'
data/README.md CHANGED
@@ -1,11 +1,13 @@
1
- # opal-jquery: jQuery wrapper for Opal
1
+ # Opal jQuery
2
+
3
+ *jQuery wrapper for Opal*
2
4
 
3
5
  [![Build Status](http://img.shields.io/travis/opal/opal-jquery/master.svg)](http://travis-ci.org/opal/opal-jquery)
4
6
 
5
- opal-jquery provides DOM access to opal by wrapping jQuery (or zepto)
7
+ **opal-jquery** provides DOM access to opal by wrapping jQuery (or zepto)
6
8
  and providing a nice ruby syntax for dealing with jQuery instances.
7
9
 
8
- See the Opal website for [documentation](http://opalrb.org/docs/jquery).
10
+ <!-- See the Opal website for [documentation](http://opalrb.org/docs/jquery). -->
9
11
 
10
12
 
11
13
 
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
-
@@ -261,6 +261,11 @@ class Element < `#{JQUERY_CLASS.to_n}`
261
261
  # @return [Element]
262
262
  alias_native :filter
263
263
 
264
+ # @!method not(selector)
265
+ # @param selector [String]
266
+ # @return [Element]
267
+ alias_native :not
268
+
264
269
  # @!method last
265
270
  #
266
271
  # Returns a new {Element} instance containing the last element in this
@@ -293,10 +298,12 @@ class Element < `#{JQUERY_CLASS.to_n}`
293
298
  # @!method get
294
299
  alias_native :get
295
300
 
296
- # @!method prop(name, value = nil)
301
+ # @!method prop(name, value = undefined)
297
302
  #
298
303
  # Get or set the property `name` on each element in collection.
299
- alias_native :prop
304
+ def prop(*args)
305
+ Native.call(self, :prop, *args)
306
+ end
300
307
 
301
308
  alias succ next
302
309
  alias << append
@@ -330,9 +337,18 @@ class Element < `#{JQUERY_CLASS.to_n}`
330
337
  # @!method remove_class(class_name)
331
338
  alias_native :remove_class, :removeClass
332
339
 
340
+ # @!method replace_all(target)
341
+ alias_native :replace_all, :replaceAll
342
+
343
+ # @!method replace_with(new_content)
344
+ alias_native :replace_with, :replaceWith
345
+
333
346
  # @!method submit()
334
347
  alias_native :submit
335
348
 
349
+ # @!method click()
350
+ alias_native :click
351
+
336
352
  # @!method text=(text)
337
353
  #
338
354
  # Set text content of each element in this collection.
@@ -411,10 +427,11 @@ class Element < `#{JQUERY_CLASS.to_n}`
411
427
  var size = args.length;
412
428
  switch (size) {
413
429
  case 1:
414
- return #{self[`args[0]`]};
430
+ var result = self.attr(args[0]);
431
+ return( (result == null) ? nil : result );
415
432
  break;
416
433
  case 2:
417
- return #{self[`args[0]`] = `args[1]`};
434
+ return self.attr(args[0], args[1]);
418
435
  break;
419
436
  default:
420
437
  #{raise ArgumentError, '#attr only accepts 1 or 2 arguments'}
@@ -503,16 +520,21 @@ class Element < `#{JQUERY_CLASS.to_n}`
503
520
  # is given, the block is run as a callback when the animation finishes.
504
521
  def animate(params, &block)
505
522
  speed = params.has_key?(:speed) ? params.delete(:speed) : 400
506
- %x{
507
- self.animate(#{params.to_n}, #{speed}, function() {
508
- #{block.call if block_given?}
509
- })
510
- }
523
+ if block_given?
524
+ `self.animate(#{params.to_n}, #{speed}, block)`
525
+ else
526
+ `self.animate(#{params.to_n}, #{speed})`
527
+ end
511
528
  end
512
529
 
513
530
  def data(*args)
514
531
  %x{
515
532
  var result = self.data.apply(self, args);
533
+ if (
534
+ (typeof(result) === 'object') && !(result instanceof #{JQUERY_CLASS})
535
+ ) {
536
+ result = #{ JSON.from_object `result` };
537
+ }
516
538
  return result == null ? nil : result;
517
539
  }
518
540
  end
@@ -641,15 +663,22 @@ class Element < `#{JQUERY_CLASS.to_n}`
641
663
 
642
664
  def on(name, sel = nil, &block)
643
665
  %x{
644
- var wrapper = function(evt) {
645
- if (evt.preventDefault) {
646
- evt = #{Event.new `evt`};
666
+ var has_args = #{block.arity} !== 0;
667
+
668
+ var wrapper = function() {
669
+ for(var args = new Array(arguments.length), i = 0, ii = args.length; i < ii; i++) {
670
+ args[i] = arguments[i];
671
+ }
672
+
673
+ // Use preventDefault as a canary for native events
674
+ if (has_args && args[0].preventDefault) {
675
+ args[0] = #{Event.new `args[0]`};
647
676
  }
648
677
 
649
- return block.apply(null, arguments);
678
+ return block.apply(null, args);
650
679
  };
651
680
 
652
- block._jq_wrap = wrapper;
681
+ block.$$jqwrap = wrapper;
653
682
 
654
683
  if (sel == nil) {
655
684
  self.on(name, wrapper);
@@ -664,15 +693,22 @@ class Element < `#{JQUERY_CLASS.to_n}`
664
693
 
665
694
  def one(name, sel = nil, &block)
666
695
  %x{
667
- var wrapper = function(evt) {
668
- if (evt.preventDefault) {
669
- evt = #{Event.new `evt`};
696
+ var has_args = #{block.arity} !== 0;
697
+
698
+ var wrapper = function() {
699
+ for(var args = new Array(arguments.length), i = 0, ii = args.length; i < ii; i++) {
700
+ args[i] = arguments[i];
670
701
  }
671
702
 
672
- return block.apply(null, arguments);
703
+ // Use preventDefault as a canary for native events
704
+ if (has_args && args[0].preventDefault) {
705
+ args[0] = #{Event.new `args[0]`};
706
+ }
707
+
708
+ return block.apply(null, args);
673
709
  };
674
710
 
675
- block._jq_wrap = wrapper;
711
+ block.$$jqwrap = wrapper;
676
712
 
677
713
  if (sel == nil) {
678
714
  self.one(name, wrapper);
@@ -691,15 +727,17 @@ class Element < `#{JQUERY_CLASS.to_n}`
691
727
  return self.off(name);
692
728
  }
693
729
  else if (block === nil) {
694
- return self.off(name, sel._jq_wrap);
730
+ return self.off(name, sel.$$jqwrap);
695
731
  }
696
732
  else {
697
- return self.off(name, sel, block._jq_wrap);
733
+ return self.off(name, sel, block.$$jqwrap);
698
734
  }
699
735
  }
700
736
  end
701
737
 
702
- # returns an Array of Hashes
738
+ # Serializes a form into an Array of Hash objects.
739
+ #
740
+ # @return [Array<Hashes>]
703
741
  def serialize_array
704
742
  `self.serializeArray()`.map { |e| Hash.new(e) }
705
743
  end
@@ -707,18 +745,46 @@ class Element < `#{JQUERY_CLASS.to_n}`
707
745
  alias size length
708
746
 
709
747
  def value
710
- `self.val() || ""`
748
+ `self.val()` || ""
711
749
  end
712
750
 
713
751
  def height
714
- `self.height() || nil`
752
+ `self.height()` || nil
715
753
  end
716
754
 
717
755
  def width
718
- `self.width() || nil`
756
+ `self.width()` || nil
719
757
  end
720
758
 
721
759
  def position
722
760
  Native(`self.position()`)
723
761
  end
762
+
763
+ def ==(other)
764
+ `self.is(other)`
765
+ end
766
+
767
+ def respond_to_missing?(name, _)
768
+ %x{
769
+ var method = self[#{name}];
770
+ if (typeof(method) === 'function') {
771
+ return true;
772
+ } else {
773
+ return #{super};
774
+ }
775
+ }
776
+ end
777
+
778
+ def method_missing(name, *args, &block)
779
+ args << block if block_given?
780
+
781
+ %x{
782
+ var method = self[#{name}];
783
+ if (typeof(method) === 'function') {
784
+ return method.apply(self, #{args.to_n});
785
+ } else {
786
+ return #{super};
787
+ }
788
+ }
789
+ end
724
790
  end