de_rjs 0.3.1 → 0.4.0

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: ef7b1985606279e19f688ce19a2bf653ec16b9f2
4
- data.tar.gz: 1d4b2e9945ef5faf9364b45da0d5c9a162d98e2d
3
+ metadata.gz: eae4de9892c19b5e8f6192db42a2a79723406577
4
+ data.tar.gz: 9079ab6320e36da5aeca6ac240313d1e451b4569
5
5
  SHA512:
6
- metadata.gz: '048cff985a57484e5a978347761e9a72fd80a7f7ba6cbf3250099ae5b6163faf339eb80bf55927c6e85ec9141603d092d2f09abf4e9eae77ae0b1e3fc57f10a7'
7
- data.tar.gz: 749b55aa71df3705d28470be60aad909828483107d3636239110246fc8373ddffa0aa6cd9a9c5e8abf2d252472f0054a93cd6fda5fa91b46bfb723d44bbc7f9e
6
+ metadata.gz: 78bd18998d5a272491e345a190c1c131d181fb6d3e8f6844a88d47e559ef6f2803122dec6fb200233e32508c33c62a81705c4264cb2091bfc869cfe7c2824184
7
+ data.tar.gz: 427622719892e792ae4847b94e6cb948897617482dafa5fac48d485f29a26258e60a83c441467771fd97cf6da692a42157ad18adf9c99ef7631d1753274ee2c4
@@ -566,10 +566,6 @@ module DeRjs
566
566
  generator = self.class.new(@context, &block)
567
567
  literal("function() { #{generator.to_s} }")
568
568
  end
569
-
570
- def method_missing(method, *arguments)
571
- JavaScriptProxy.new(self, method.to_s.camelize)
572
- end
573
569
  end
574
570
  end
575
571
 
@@ -584,15 +580,30 @@ module DeRjs
584
580
  klass == JavaScriptProxy
585
581
  end
586
582
 
583
+ def ==(other)
584
+ raise "haha"
585
+ end
586
+
587
587
  private
588
588
  def method_missing(method, *arguments, &block)
589
589
  if method.to_s =~ /(.*)=$/
590
+ warn(method.to_s, *arguments)
590
591
  assign($1, arguments.first)
591
592
  else
593
+ warn(method.to_s, *arguments)
592
594
  call("#{method.to_s.camelize(:lower)}", *arguments, &block)
593
595
  end
594
596
  end
595
597
 
598
+ def known_jquery_methods
599
+ %w(hide show first last)
600
+ end
601
+
602
+ def warn(method, *arguments)
603
+ return if known_jquery_methods.include? method.to_s
604
+ ::Kernel.puts "#{method} is called via method_missing with args: #{arguments.inspect} at: #{::Kernel.caller.join("\n")}"
605
+ end
606
+
596
607
  def call(function, *arguments, &block)
597
608
  append_to_function_chain!("#{function}(#{@generator.send(:arguments_for_call, arguments, block)})")
598
609
  self
@@ -789,7 +800,7 @@ module DeRjs
789
800
 
790
801
  class JavaScriptElementCollectionProxy < JavaScriptCollectionProxy #:nodoc:\
791
802
  def initialize(generator, pattern)
792
- super(generator, "#{::JQUERY_VAR}(#{::ActiveSupport::JSON.encode(pattern)})")
803
+ super(generator, "#{::JQUERY_VAR}(#{::ActiveSupport::JSON.encode(pattern)});")
793
804
  end
794
805
  end
795
806
  end
@@ -9,15 +9,6 @@ end
9
9
 
10
10
  class DeRjsBaseTest < Minitest::Test
11
11
  protected
12
- def not_supported
13
- skip "not supported"
14
- end
15
-
16
- def create_generator
17
- block = Proc.new { |*args| yield(*args) if block_given? }
18
- DeRjs::JqueryGenerator.new self, &block
19
- end
20
-
21
12
  def generate_js(rjs)
22
13
  rewritten_source = DeRjs::Rewriter.rewrite_rjs(rjs)
23
14
  generator = DeRjs::JqueryGenerator.new(nil) { eval(rewritten_source)}
@@ -29,7 +20,6 @@ end
29
20
  class DeRjsTest < DeRjsBaseTest
30
21
  def setup
31
22
  super
32
- @generator = create_generator
33
23
  ActiveSupport.escape_html_entities_in_json = true
34
24
  end
35
25
 
@@ -120,32 +110,6 @@ class DeRjsTest < DeRjsBaseTest
120
110
  generate_js(%Q{ page.reload })
121
111
  end
122
112
 
123
- def test_delay
124
- not_supported
125
-
126
- @generator.delay(20) do
127
- @generator.hide('foo')
128
- end
129
-
130
- assert_equal "setTimeout(function() {\n;\njQuery(\"#foo\").hide();\n}, 20000);", @generator.to_s
131
- end
132
-
133
- def test_to_s
134
- not_supported
135
-
136
- @generator.insert_html(:top, 'element', '<p>This is a test</p>')
137
- @generator.insert_html(:bottom, 'element', '<p>This is a test</p>')
138
- @generator.remove('foo', 'bar')
139
- @generator.replace_html('baz', '<p>This is a test</p>')
140
-
141
- assert_equal <<-EOS.chomp, @generator.to_s
142
- jQuery("#element").prepend("\\u003cp\\u003eThis is a test\\u003c/p\\u003e");
143
- jQuery("#element").append("\\u003cp\\u003eThis is a test\\u003c/p\\u003e");
144
- jQuery("#foo,#bar").remove();
145
- jQuery("#baz").html("\\u003cp\\u003eThis is a test\\u003c/p\\u003e");
146
- EOS
147
- end
148
-
149
113
  def test_element_access
150
114
  assert_equal %(jQuery("#hello");), generate_js(%Q{ page['hello'] })
151
115
  end
@@ -189,12 +153,12 @@ jQuery("#baz").html("\\u003cp\\u003eThis is a test\\u003c/p\\u003e");
189
153
  end
190
154
 
191
155
  def test_element_proxy_two_deep
192
- @generator['hello'].hide("first").clean_whitespace
193
- assert_equal %(jQuery("#hello").hide("first").cleanWhitespace();), @generator.to_s
156
+ skip "I don't think this has ever worked"
157
+ assert_equal %(jQuery("#hello").hide("first").cleanWhitespace();), generate_js(%Q{ page.hide("first").clean_whitespace })
194
158
  end
195
159
 
196
160
  def test_select_access
197
- assert_equal %(jQuery("div.hello");), @generator.select('div.hello')
161
+ assert_equal %(jQuery("div.hello");), generate_js(%Q{ page.select('div.hello') })
198
162
  end
199
163
 
200
164
  def test_select_proxy_one_deep
@@ -219,25 +183,6 @@ jQuery("#baz").html("\\u003cp\\u003eThis is a test\\u003c/p\\u003e");
219
183
  generate_js(%Q{ page.visual_effect(:toggle_appear,"blah" + blah.id) })
220
184
  end
221
185
 
222
- def test_sortable
223
- assert_equal %(Sortable.create("blah", {onUpdate:function(){new Ajax.Request('http://www.example.com/order', {asynchronous:true, evalScripts:true, parameters:Sortable.serialize("blah")})}});),
224
- @generator.sortable('blah', :url => { :action => "order" })
225
- assert_equal %(Sortable.create("blah", {onUpdate:function(){new Ajax.Request('http://www.example.com/order', {asynchronous:false, evalScripts:true, parameters:Sortable.serialize("blah")})}});),
226
- @generator.sortable('blah', :url => { :action => "order" }, :type => :synchronous)
227
- end
228
-
229
- def test_draggable
230
- assert_equal %(new Draggable("blah", {});),
231
- @generator.draggable('blah')
232
- end
233
-
234
- def test_drop_receiving
235
- assert_equal %(Droppables.add("blah", {onDrop:function(element){new Ajax.Request('http://www.example.com/order', {asynchronous:true, evalScripts:true, parameters:'id=' + encodeURIComponent(element.id)})}});),
236
- @generator.drop_receiving('blah', :url => { :action => "order" })
237
- assert_equal %(Droppables.add("blah", {onDrop:function(element){new Ajax.Request('http://www.example.com/order', {asynchronous:false, evalScripts:true, parameters:'id=' + encodeURIComponent(element.id)})}});),
238
- @generator.drop_receiving('blah', :url => { :action => "order" }, :type => :synchronous)
239
- end
240
-
241
186
  def test_collection_first_and_last
242
187
  js = generate_js(%Q{
243
188
  page.select('p.welcome b').first.hide()
@@ -249,190 +194,8 @@ jQuery("p.welcome b").last().show();
249
194
  EOS
250
195
  end
251
196
 
252
- def test_collection_proxy_with_each
253
- not_supported
254
-
255
- @generator.select('p.welcome b').each do |value|
256
- value.remove_class_name 'selected'
257
- end
258
- @generator.select('p.welcome b').each do |value, index|
259
- @generator.visual_effect :highlight, value
260
- end
261
- assert_equal <<-EOS.strip, @generator.to_s
262
- jQuery("p.welcome b").each(function(value, index) {
263
- value.removeClassName("selected");
264
- });
265
- jQuery("p.welcome b").each(function(value, index) {
266
- jQuery("#value").effect("highlight",{});
267
- });
268
- EOS
269
- end
270
-
271
- def test_collection_proxy_on_collect
272
- not_supported
273
-
274
- @generator.select('p').collect('a') { |para| para.show }
275
- @generator.select('p').collect { |para| para.hide }
276
- assert_equal <<-EOS.strip, @generator.to_s
277
- var a = jQuery("p").collect(function(value, index) {
278
- return value.show();
279
- });
280
- jQuery("p").collect(function(value, index) {
281
- return value.hide();
282
- });
283
- EOS
284
- @generator = create_generator
285
- end
286
-
287
- def test_collection_proxy_with_grep
288
- not_supported
289
-
290
- @generator.select('p').grep 'a', /^a/ do |value|
291
- @generator << '(value.className == "welcome")'
292
- end
293
- @generator.select('p').grep 'b', /bjQuery/ do |value, index|
294
- @generator.call 'alert', value
295
- @generator << '(value.className == "welcome")'
296
- end
297
-
298
- assert_equal <<-EOS.strip, @generator.to_s
299
- var a = jQuery("p").grep(/^a/, function(value, index) {
300
- return (value.className == "welcome");
301
- });
302
- var b = jQuery("p").grep(/bjQuery/, function(value, index) {
303
- alert(value);
304
- return (value.className == "welcome");
305
- });
306
- EOS
307
- end
308
-
309
- def test_collection_proxy_with_inject
310
- not_supported
311
-
312
- @generator.select('p').inject 'a', [] do |memo, value|
313
- @generator << '(value.className == "welcome")'
314
- end
315
- @generator.select('p').inject 'b', nil do |memo, value, index|
316
- @generator.call 'alert', memo
317
- @generator << '(value.className == "welcome")'
318
- end
319
-
320
- assert_equal <<-EOS.strip, @generator.to_s
321
- var a = jQuery("p").inject([], function(memo, value, index) {
322
- return (value.className == "welcome");
323
- });
324
- var b = jQuery("p").inject(null, function(memo, value, index) {
325
- alert(memo);
326
- return (value.className == "welcome");
327
- });
328
- EOS
329
- end
330
-
331
197
  def test_collection_proxy_with_pluck
332
198
  js = generate_js(%Q{ page.select('p').pluck('a', 'className') })
333
199
  assert_equal %(var a = jQuery("p").pluck("className");), js
334
200
  end
335
-
336
- def test_collection_proxy_with_zip
337
- not_supported
338
-
339
- ActionView::Helpers::JavaScriptCollectionProxy.new(@generator, '[1, 2, 3]').zip('a', [4, 5, 6], [7, 8, 9])
340
- ActionView::Helpers::JavaScriptCollectionProxy.new(@generator, '[1, 2, 3]').zip('b', [4, 5, 6], [7, 8, 9]) do |array|
341
- @generator.call 'array.reverse'
342
- end
343
-
344
- assert_equal <<-EOS.strip, @generator.to_s
345
- var a = [1, 2, 3].zip([4,5,6], [7,8,9]);
346
- var b = [1, 2, 3].zip([4,5,6], [7,8,9], function(array) {
347
- return array.reverse();
348
- });
349
- EOS
350
- end
351
-
352
- def test_collection_proxy_with_find_all
353
- not_supported
354
-
355
- @generator.select('p').find_all 'a' do |value, index|
356
- @generator << '(value.className == "welcome")'
357
- end
358
-
359
- assert_equal <<-EOS.strip, @generator.to_s
360
- var a = jQuery("p").findAll(function(value, index) {
361
- return (value.className == "welcome");
362
- });
363
- EOS
364
- end
365
-
366
- def test_collection_proxy_with_in_groups_of
367
- not_supported
368
-
369
- @generator.select('p').in_groups_of('a', 3)
370
- @generator.select('p').in_groups_of('a', 3, 'x')
371
- assert_equal <<-EOS.strip, @generator.to_s
372
- var a = jQuery("p").inGroupsOf(3);
373
- var a = jQuery("p").inGroupsOf(3, "x");
374
- EOS
375
- end
376
-
377
- def test_collection_proxy_with_each_slice
378
- not_supported
379
-
380
- @generator.select('p').each_slice('a', 3)
381
- @generator.select('p').each_slice('a', 3) do |group, index|
382
- group.reverse
383
- end
384
-
385
- assert_equal <<-EOS.strip, @generator.to_s
386
- var a = jQuery("p").eachSlice(3);
387
- var a = jQuery("p").eachSlice(3, function(value, index) {
388
- return value.reverse();
389
- });
390
- EOS
391
- end
392
-
393
- #def test_debug_rjs
394
- #ActionView::Base.debug_rjs = true
395
- #@generator['welcome'].replace_html 'Welcome'
396
- #assert_equal "try {\njQuery(\"#welcome\").html(\"Welcome\");\n} catch (e) { alert('RJS error:\\n\\n' + e.toString()); alert('jQuery(\\\"#welcome\\\").html(\\\"Welcome\\\");'); throw e }", @generator.to_s
397
- #ensure
398
- #ActionView::Base.debug_rjs = false
399
- #end
400
-
401
- def test_literal
402
- not_supported
403
-
404
- literal = @generator.literal("function() {}")
405
- assert_equal "function() {}", ActiveSupport::JSON.encode(literal)
406
- assert_equal "", @generator.to_s
407
- end
408
-
409
- def test_class_proxy
410
- @generator.form.focus('my_field')
411
- assert_equal "Form.focus(\"my_field\");", @generator.to_s
412
- end
413
-
414
- def test_call_with_block
415
- not_supported
416
-
417
- @generator.call(:before)
418
- @generator.call(:my_method) do |p|
419
- p[:one].show
420
- p[:two].hide
421
- end
422
- @generator.call(:in_between)
423
- @generator.call(:my_method_with_arguments, true, "hello") do |p|
424
- p[:three].visual_effect(:highlight)
425
- end
426
- assert_equal "before();\nmy_method(function() { jQuery(\"#one\").show();\njQuery(\"#two\").hide(); });\nin_between();\nmy_method_with_arguments(true, \"hello\", function() { jQuery(\"#three\").visualEffect(\"highlight\"); });", @generator.to_s
427
- end
428
-
429
- def test_class_proxy_call_with_block
430
- not_supported
431
-
432
- @generator.my_object.my_method do |p|
433
- p[:one].show
434
- p[:two].hide
435
- end
436
- assert_equal "MyObject.myMethod(function() { jQuery(\"#one\").show();\njQuery(\"#two\").hide(); });", @generator.to_s
437
- end
438
201
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: de_rjs
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Thong Kuah
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-07-28 00:00:00.000000000 Z
11
+ date: 2017-08-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails