de_rjs 0.2.1 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/Rakefile +1 -2
  3. data/test/de_rjs_test.rb +58 -58
  4. metadata +3 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d660448d4fe1823a9f71d6a2f4f4ba5d1e38ac95
4
- data.tar.gz: bd42c4e907d97a136d75939823d7371f5aac7b47
3
+ metadata.gz: f44960ac0f469ff1711cd967aac5329ddf0e5396
4
+ data.tar.gz: fea015c10bdea4828b694beba00315d0581d3e55
5
5
  SHA512:
6
- metadata.gz: d86d3dfc21d72253e42118f5034a533d70fd1d7c52e20164bb6a9afe69c70763d0acb2ccc4a3e6814eab8e3e45334a70481845b6221bbb6b2c13b9ddfca9da89
7
- data.tar.gz: ce15d413bdc07281b20cc5a4ef8110c3927b6b3ee4cd42470496b3bdff159c72bd03ab2fd3708097360fe130678a9ffb7cbf0a2ee383648a89aee7e46abe78a2
6
+ metadata.gz: d96893c52e23fb62646b5067275f1834f0ef20202dd8f99ee0edffdcfba13fe16d85df388966f58a16dbf31f4c6420543e1d5b1462c2ee75dbca9ff1d8e5c5de
7
+ data.tar.gz: 91d27c2831e7cd3ca8efcfbb69c266b519b9d55a1fe2d55ea0e5d72ddf5f29d3b61d768c1b5ff5af27bae7b71f18611cb71030816391539ecda5bd9373ec2118
data/Rakefile CHANGED
@@ -4,7 +4,6 @@ task :default => :test
4
4
 
5
5
  Rake::TestTask.new do |t|
6
6
  t.libs << 'test'
7
- t.test_files = Dir.glob('test/*_test.rb') + Dir.glob('test/{controller,template}/**/*_test.rb')
8
- t.warning = true
7
+ t.pattern = 'test/*_test.rb'
9
8
  t.verbose = true
10
9
  end
@@ -40,67 +40,67 @@ class DeRjsTest < DeRjsBaseTest
40
40
  def _evaluate_assigns_and_ivars() end
41
41
 
42
42
  def test_insert_html_with_string
43
- assert_equal '$("#element").prepend("\\u003cp\\u003eThis is a test\\u003c/p\\u003e");',
43
+ assert_equal 'jQuery("#element").prepend("\\u003cp\\u003eThis is a test\\u003c/p\\u003e");',
44
44
  generate_js(%Q{ page.insert_html(:top, 'element', '<p>This is a test</p>') })
45
- assert_equal '$("#element").append("\\u003cp\u003eThis is a test\\u003c/p\u003e");',
45
+ assert_equal 'jQuery("#element").append("\\u003cp\u003eThis is a test\\u003c/p\u003e");',
46
46
  generate_js(%Q{ page.insert_html(:bottom, 'element', '<p>This is a test</p>') })
47
- assert_equal '$("#element").before("\\u003cp\u003eThis is a test\\u003c/p\u003e");',
47
+ assert_equal 'jQuery("#element").before("\\u003cp\u003eThis is a test\\u003c/p\u003e");',
48
48
  generate_js(%Q{ page.insert_html(:before, 'element', '<p>This is a test</p>') })
49
- assert_equal '$("#element").after("\\u003cp\u003eThis is a test\\u003c/p\u003e");',
49
+ assert_equal 'jQuery("#element").after("\\u003cp\u003eThis is a test\\u003c/p\u003e");',
50
50
  generate_js(%Q{ page.insert_html(:after, 'element', '<p>This is a test</p>') })
51
51
  end
52
52
 
53
53
  def test_replace_html_with_string
54
- assert_equal '$("#element").html("\\u003cp\\u003eThis is a test\\u003c/p\\u003e");',
54
+ assert_equal 'jQuery("#element").html("\\u003cp\\u003eThis is a test\\u003c/p\\u003e");',
55
55
  generate_js(%Q{ page.replace_html('element', '<p>This is a test</p>') })
56
56
  end
57
57
 
58
58
  def test_replace_element_with_string
59
- assert_equal '$("#element").replaceWith("\\u003cdiv id=\"element\"\\u003e\\u003cp\\u003eThis is a test\\u003c/p\\u003e\\u003c/div\\u003e");',
59
+ assert_equal 'jQuery("#element").replaceWith("\\u003cdiv id=\"element\"\\u003e\\u003cp\\u003eThis is a test\\u003c/p\\u003e\\u003c/div\\u003e");',
60
60
  generate_js(%Q{ page.replace('element', '<div id="element"><p>This is a test</p></div>') })
61
61
  end
62
62
 
63
63
  def test_insert_html_with_hash
64
- assert_equal '$("#element").prepend("<%= escape_javascript(render(:partial => "post", :locals => {:ab => "cd"})) %>");',
64
+ assert_equal 'jQuery("#element").prepend("<%= escape_javascript(render(:partial => "post", :locals => {:ab => "cd"})) %>");',
65
65
  generate_js(%Q{ page.insert_html(:top, 'element', :partial => "post", :locals => {:ab => "cd"}) })
66
66
  end
67
67
 
68
68
  def test_replace_html_with_hash
69
- assert_equal '$("#element").html("<%= escape_javascript(render(:partial => "post", :locals => {:ab => "cd"})) %>");',
69
+ assert_equal 'jQuery("#element").html("<%= escape_javascript(render(:partial => "post", :locals => {:ab => "cd"})) %>");',
70
70
  generate_js(%Q{ page.replace_html('element', :partial => "post", :locals => {:ab => "cd"}) })
71
71
  end
72
72
 
73
73
  def test_replace_element_with_hash
74
- assert_equal '$("#element").replaceWith("<%= escape_javascript(render(:partial => "post", :locals => {:ab => "cd"})) %>");',
74
+ assert_equal 'jQuery("#element").replaceWith("<%= escape_javascript(render(:partial => "post", :locals => {:ab => "cd"})) %>");',
75
75
  generate_js(%Q{ page.replace('element', :partial => "post", :locals => {:ab => "cd"}) })
76
76
  end
77
77
 
78
78
 
79
79
  def test_remove
80
- assert_equal '$("#foo").remove();',
80
+ assert_equal 'jQuery("#foo").remove();',
81
81
  generate_js(%Q{ page.remove('foo') })
82
- assert_equal '$("#foo,#bar,#baz").remove();',
82
+ assert_equal 'jQuery("#foo,#bar,#baz").remove();',
83
83
  generate_js(%Q{ page.remove('foo', 'bar', 'baz') })
84
84
  end
85
85
 
86
86
  def test_show
87
- assert_equal '$("#foo").show();',
87
+ assert_equal 'jQuery("#foo").show();',
88
88
  generate_js(%Q{ page.show('foo') })
89
- assert_equal '$("#foo,#bar,#baz").show();',
89
+ assert_equal 'jQuery("#foo,#bar,#baz").show();',
90
90
  generate_js(%Q{ page.show('foo', 'bar', 'baz') })
91
91
  end
92
92
 
93
93
  def test_hide
94
- assert_equal '$("#foo").hide();',
94
+ assert_equal 'jQuery("#foo").hide();',
95
95
  generate_js(%Q{ page.hide('foo') })
96
- assert_equal '$("#foo,#bar,#baz").hide();',
96
+ assert_equal 'jQuery("#foo,#bar,#baz").hide();',
97
97
  generate_js(%Q{ page.hide('foo', 'bar', 'baz') })
98
98
  end
99
99
 
100
100
  def test_toggle
101
- assert_equal '$("#foo").toggle();',
101
+ assert_equal 'jQuery("#foo").toggle();',
102
102
  generate_js(%Q{ page.toggle('foo') })
103
- assert_equal '$("#foo,#bar,#baz").toggle();',
103
+ assert_equal 'jQuery("#foo,#bar,#baz").toggle();',
104
104
  generate_js(%Q{ page.toggle('foo', 'bar', 'baz') })
105
105
  end
106
106
 
@@ -127,7 +127,7 @@ class DeRjsTest < DeRjsBaseTest
127
127
  @generator.hide('foo')
128
128
  end
129
129
 
130
- assert_equal "setTimeout(function() {\n;\n$(\"#foo\").hide();\n}, 20000);", @generator.to_s
130
+ assert_equal "setTimeout(function() {\n;\njQuery(\"#foo\").hide();\n}, 20000);", @generator.to_s
131
131
  end
132
132
 
133
133
  def test_to_s
@@ -139,77 +139,77 @@ class DeRjsTest < DeRjsBaseTest
139
139
  @generator.replace_html('baz', '<p>This is a test</p>')
140
140
 
141
141
  assert_equal <<-EOS.chomp, @generator.to_s
142
- $("#element").prepend("\\u003cp\\u003eThis is a test\\u003c/p\\u003e");
143
- $("#element").append("\\u003cp\\u003eThis is a test\\u003c/p\\u003e");
144
- $("#foo,#bar").remove();
145
- $("#baz").html("\\u003cp\\u003eThis is a test\\u003c/p\\u003e");
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
146
  EOS
147
147
  end
148
148
 
149
149
  def test_element_access
150
- assert_equal %($("#hello");), generate_js(%Q{ page['hello'] })
150
+ assert_equal %(jQuery("#hello");), generate_js(%Q{ page['hello'] })
151
151
  end
152
152
 
153
153
  def test_element_access_on_variable
154
154
  assert_raises DeRjs::Rewriter::Erbify::MustTranslateManually do
155
- assert_equal %($("#<%= 'hello' + @var %>");), generate_js(%Q{ page['hello' + @var] })
155
+ assert_equal %(jQuery("#<%= 'hello' + @var %>");), generate_js(%Q{ page['hello' + @var] })
156
156
  end
157
157
  assert_raises DeRjs::Rewriter::Erbify::MustTranslateManually do
158
- assert_equal %($("#<%= 'hello' + @var %>").hide();), generate_js(%Q{ page['hello' + @var].hide })
158
+ assert_equal %(jQuery("#<%= 'hello' + @var %>").hide();), generate_js(%Q{ page['hello' + @var].hide })
159
159
  end
160
160
  end
161
161
 
162
162
  def test_element_access_on_records
163
163
  assert_raises DeRjs::Rewriter::Erbify::MustTranslateManually do
164
- assert_equal %($("#<%= Bunny.new(:id => 5) %>");), generate_js(%Q{ page[Bunny.new(:id => 5)] })
164
+ assert_equal %(jQuery("#<%= Bunny.new(:id => 5) %>");), generate_js(%Q{ page[Bunny.new(:id => 5)] })
165
165
  end
166
166
  assert_raises DeRjs::Rewriter::Erbify::MustTranslateManually do
167
- assert_equal %($("#<%= Bunny.new %>");), generate_js(%Q{ page[Bunny.new] })
167
+ assert_equal %(jQuery("#<%= Bunny.new %>");), generate_js(%Q{ page[Bunny.new] })
168
168
  end
169
169
  end
170
170
 
171
171
 
172
172
  def test_element_proxy_one_deep
173
- assert_equal %($("#hello").hide();), generate_js(%Q{ page['hello'].hide })
173
+ assert_equal %(jQuery("#hello").hide();), generate_js(%Q{ page['hello'].hide })
174
174
  end
175
175
 
176
176
  def test_element_proxy_variable_access
177
- assert_equal %($("#hello").style;), generate_js(%Q{ page['hello']['style'] })
177
+ assert_equal %(jQuery("#hello").style;), generate_js(%Q{ page['hello']['style'] })
178
178
  end
179
179
 
180
180
  def test_element_proxy_variable_access_with_assignment
181
- assert_equal %($("#hello").style.color = "red";), generate_js(%Q{ page['hello']['style']['color'] = 'red' })
181
+ assert_equal %(jQuery("#hello").style.color = "red";), generate_js(%Q{ page['hello']['style']['color'] = 'red' })
182
182
  end
183
183
 
184
184
  def test_element_proxy_assignment
185
- assert_equal %($("#hello").width = 400;), generate_js(%Q{ page['hello'].width = 400 })
185
+ assert_equal %(jQuery("#hello").width = 400;), generate_js(%Q{ page['hello'].width = 400 })
186
186
  end
187
187
 
188
188
  def test_element_proxy_two_deep
189
189
  @generator['hello'].hide("first").clean_whitespace
190
- assert_equal %($("#hello").hide("first").cleanWhitespace();), @generator.to_s
190
+ assert_equal %(jQuery("#hello").hide("first").cleanWhitespace();), @generator.to_s
191
191
  end
192
192
 
193
193
  def test_select_access
194
- assert_equal %($("div.hello");), @generator.select('div.hello')
194
+ assert_equal %(jQuery("div.hello");), @generator.select('div.hello')
195
195
  end
196
196
 
197
197
  def test_select_proxy_one_deep
198
- assert_equal %($("p.welcome b").first().hide();), generate_js(%Q{ page.select('p.welcome b').first.hide })
198
+ assert_equal %(jQuery("p.welcome b").first().hide();), generate_js(%Q{ page.select('p.welcome b').first.hide })
199
199
  end
200
200
 
201
201
  def test_visual_effect
202
- assert_equal %($(\"#blah\").effect(\"puff\",{});),
202
+ assert_equal %(jQuery(\"#blah\").effect(\"puff\",{});),
203
203
  generate_js(%Q{ page.visual_effect(:puff,'blah') })
204
204
  end
205
205
 
206
206
  def test_visual_effect_toggle
207
- assert_equal %($(\"#blah\").toggle(\"fade\",{});),
207
+ assert_equal %(jQuery(\"#blah\").toggle(\"fade\",{});),
208
208
  generate_js(%Q{ page.visual_effect(:toggle_appear,'blah') })
209
209
  end
210
210
 
211
211
  def test_visual_effect_with_variable
212
- assert_equal %($(\"#<%= "blah" + blah.id %>\").toggle(\"fade\",{});),
212
+ assert_equal %(jQuery(\"#<%= "blah" + blah.id %>\").toggle(\"fade\",{});),
213
213
  generate_js(%Q{ page.visual_effect(:toggle_appear,"blah" + blah.id) })
214
214
  end
215
215
 
@@ -238,8 +238,8 @@ $("#baz").html("\\u003cp\\u003eThis is a test\\u003c/p\\u003e");
238
238
  page.select('p.welcome b').last.show()
239
239
  })
240
240
  assert_equal <<-EOS.strip, js
241
- $("p.welcome b").first().hide();
242
- $("p.welcome b").last().show();
241
+ jQuery("p.welcome b").first().hide();
242
+ jQuery("p.welcome b").last().show();
243
243
  EOS
244
244
  end
245
245
 
@@ -253,11 +253,11 @@ $("p.welcome b").last().show();
253
253
  @generator.visual_effect :highlight, value
254
254
  end
255
255
  assert_equal <<-EOS.strip, @generator.to_s
256
- $("p.welcome b").each(function(value, index) {
256
+ jQuery("p.welcome b").each(function(value, index) {
257
257
  value.removeClassName("selected");
258
258
  });
259
- $("p.welcome b").each(function(value, index) {
260
- $("#value").effect("highlight",{});
259
+ jQuery("p.welcome b").each(function(value, index) {
260
+ jQuery("#value").effect("highlight",{});
261
261
  });
262
262
  EOS
263
263
  end
@@ -268,10 +268,10 @@ $("#value").effect("highlight",{});
268
268
  @generator.select('p').collect('a') { |para| para.show }
269
269
  @generator.select('p').collect { |para| para.hide }
270
270
  assert_equal <<-EOS.strip, @generator.to_s
271
- var a = $("p").collect(function(value, index) {
271
+ var a = jQuery("p").collect(function(value, index) {
272
272
  return value.show();
273
273
  });
274
- $("p").collect(function(value, index) {
274
+ jQuery("p").collect(function(value, index) {
275
275
  return value.hide();
276
276
  });
277
277
  EOS
@@ -284,16 +284,16 @@ return value.hide();
284
284
  @generator.select('p').grep 'a', /^a/ do |value|
285
285
  @generator << '(value.className == "welcome")'
286
286
  end
287
- @generator.select('p').grep 'b', /b$/ do |value, index|
287
+ @generator.select('p').grep 'b', /bjQuery/ do |value, index|
288
288
  @generator.call 'alert', value
289
289
  @generator << '(value.className == "welcome")'
290
290
  end
291
291
 
292
292
  assert_equal <<-EOS.strip, @generator.to_s
293
- var a = $("p").grep(/^a/, function(value, index) {
293
+ var a = jQuery("p").grep(/^a/, function(value, index) {
294
294
  return (value.className == "welcome");
295
295
  });
296
- var b = $("p").grep(/b$/, function(value, index) {
296
+ var b = jQuery("p").grep(/bjQuery/, function(value, index) {
297
297
  alert(value);
298
298
  return (value.className == "welcome");
299
299
  });
@@ -312,10 +312,10 @@ return (value.className == "welcome");
312
312
  end
313
313
 
314
314
  assert_equal <<-EOS.strip, @generator.to_s
315
- var a = $("p").inject([], function(memo, value, index) {
315
+ var a = jQuery("p").inject([], function(memo, value, index) {
316
316
  return (value.className == "welcome");
317
317
  });
318
- var b = $("p").inject(null, function(memo, value, index) {
318
+ var b = jQuery("p").inject(null, function(memo, value, index) {
319
319
  alert(memo);
320
320
  return (value.className == "welcome");
321
321
  });
@@ -324,7 +324,7 @@ return (value.className == "welcome");
324
324
 
325
325
  def test_collection_proxy_with_pluck
326
326
  js = generate_js(%Q{ page.select('p').pluck('a', 'className') })
327
- assert_equal %(var a = $("p").pluck("className");), js
327
+ assert_equal %(var a = jQuery("p").pluck("className");), js
328
328
  end
329
329
 
330
330
  def test_collection_proxy_with_zip
@@ -351,7 +351,7 @@ return array.reverse();
351
351
  end
352
352
 
353
353
  assert_equal <<-EOS.strip, @generator.to_s
354
- var a = $("p").findAll(function(value, index) {
354
+ var a = jQuery("p").findAll(function(value, index) {
355
355
  return (value.className == "welcome");
356
356
  });
357
357
  EOS
@@ -363,8 +363,8 @@ return (value.className == "welcome");
363
363
  @generator.select('p').in_groups_of('a', 3)
364
364
  @generator.select('p').in_groups_of('a', 3, 'x')
365
365
  assert_equal <<-EOS.strip, @generator.to_s
366
- var a = $("p").inGroupsOf(3);
367
- var a = $("p").inGroupsOf(3, "x");
366
+ var a = jQuery("p").inGroupsOf(3);
367
+ var a = jQuery("p").inGroupsOf(3, "x");
368
368
  EOS
369
369
  end
370
370
 
@@ -377,8 +377,8 @@ var a = $("p").inGroupsOf(3, "x");
377
377
  end
378
378
 
379
379
  assert_equal <<-EOS.strip, @generator.to_s
380
- var a = $("p").eachSlice(3);
381
- var a = $("p").eachSlice(3, function(value, index) {
380
+ var a = jQuery("p").eachSlice(3);
381
+ var a = jQuery("p").eachSlice(3, function(value, index) {
382
382
  return value.reverse();
383
383
  });
384
384
  EOS
@@ -387,7 +387,7 @@ return value.reverse();
387
387
  #def test_debug_rjs
388
388
  #ActionView::Base.debug_rjs = true
389
389
  #@generator['welcome'].replace_html 'Welcome'
390
- #assert_equal "try {\n$(\"#welcome\").html(\"Welcome\");\n} catch (e) { alert('RJS error:\\n\\n' + e.toString()); alert('$(\\\"#welcome\\\").html(\\\"Welcome\\\");'); throw e }", @generator.to_s
390
+ #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
391
391
  #ensure
392
392
  #ActionView::Base.debug_rjs = false
393
393
  #end
@@ -417,7 +417,7 @@ return value.reverse();
417
417
  @generator.call(:my_method_with_arguments, true, "hello") do |p|
418
418
  p[:three].visual_effect(:highlight)
419
419
  end
420
- assert_equal "before();\nmy_method(function() { $(\"#one\").show();\n$(\"#two\").hide(); });\nin_between();\nmy_method_with_arguments(true, \"hello\", function() { $(\"#three\").visualEffect(\"highlight\"); });", @generator.to_s
420
+ 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
421
421
  end
422
422
 
423
423
  def test_class_proxy_call_with_block
@@ -427,6 +427,6 @@ return value.reverse();
427
427
  p[:one].show
428
428
  p[:two].hide
429
429
  end
430
- assert_equal "MyObject.myMethod(function() { $(\"#one\").show();\n$(\"#two\").hide(); });", @generator.to_s
430
+ assert_equal "MyObject.myMethod(function() { jQuery(\"#one\").show();\njQuery(\"#two\").hide(); });", @generator.to_s
431
431
  end
432
432
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: de_rjs
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Thong Kuah
@@ -66,7 +66,8 @@ dependencies:
66
66
  version: '9.0'
67
67
  description:
68
68
  email: kuahyeow@gmail.com
69
- executables: []
69
+ executables:
70
+ - de_rjs
70
71
  extensions: []
71
72
  extra_rdoc_files: []
72
73
  files: