de_rjs 0.4.2 → 0.4.3

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: 574697ee1e28df30923b0c2ccac6181b257f2485
4
- data.tar.gz: e7f6b8cfba7c0bac2150ce265b95b3a4be4c3f43
3
+ metadata.gz: 45fff0b7ea1479cbc72d621956f580b4a2eebae4
4
+ data.tar.gz: 385153d5782044994e2b5a13d0a408ba79b56205
5
5
  SHA512:
6
- metadata.gz: c49c29aa19cc77d5a84481fff423ca5a44ee30e426ee55f4ab04fdf6ede76aba4241f8d4bb24cbbc6fb02ba4db15f8d757944018bca01d64af27fbd228247dd2
7
- data.tar.gz: 105cd7cb54f3081fa85e22f35fcfc130abf1c0e5cc9ce39dde749f21a59cfafa3e3fe8e4c91141c9306816aeace4b4bcbd79052c04d121a4c109ad23459b7d15
6
+ metadata.gz: 55edfb6f9ca26275582323852e7c009ae5d947455e38647e589b34e0256ed9c08de1773caff5a5004206399411d68956c007cc7e1376516812210647db48ec34
7
+ data.tar.gz: 3de4af5f9488338fbc93371a9f4929cc7da7ae78e13b5df8a1d1bf07f80a68d4f78b7b8560f565c940d1d2951c68488efd435d2dd3fd120f53758dd9bf2ee0c5
@@ -555,7 +555,7 @@ module DeRjs
555
555
  end
556
556
 
557
557
  def javascript_object_for(object)
558
- if object.is_a?(String) && object =~ /\A<%=.*%>\z/ # if completely using e
558
+ if object.is_a?(String) && object =~ /\A<%=.*%>\z/m # if completely using erb
559
559
  "\"#{object}\""
560
560
  else
561
561
  ::ActiveSupport::JSON.encode(object)
@@ -31,102 +31,111 @@ class DeRjsTest < DeRjsBaseTest
31
31
 
32
32
  def test_insert_html_with_string
33
33
  assert_equal 'jQuery("#element").prepend("\\u003cp\\u003eThis is a test\\u003c/p\\u003e");',
34
- generate_js(%Q{ page.insert_html(:top, 'element', '<p>This is a test</p>') })
34
+ generate_js(%q{ page.insert_html(:top, 'element', '<p>This is a test</p>') })
35
35
  assert_equal 'jQuery("#element").append("\\u003cp\u003eThis is a test\\u003c/p\u003e");',
36
- generate_js(%Q{ page.insert_html(:bottom, 'element', '<p>This is a test</p>') })
36
+ generate_js(%q{ page.insert_html(:bottom, 'element', '<p>This is a test</p>') })
37
37
  assert_equal 'jQuery("#element").before("\\u003cp\u003eThis is a test\\u003c/p\u003e");',
38
- generate_js(%Q{ page.insert_html(:before, 'element', '<p>This is a test</p>') })
38
+ generate_js(%q{ page.insert_html(:before, 'element', '<p>This is a test</p>') })
39
39
  assert_equal 'jQuery("#element").after("\\u003cp\u003eThis is a test\\u003c/p\u003e");',
40
- generate_js(%Q{ page.insert_html(:after, 'element', '<p>This is a test</p>') })
40
+ generate_js(%q{ page.insert_html(:after, 'element', '<p>This is a test</p>') })
41
41
  end
42
42
 
43
43
  def test_replace_html_with_string
44
- assert_equal 'jQuery("#element").html("<p>This is a test</p>");',
45
- generate_js(%Q{ page.replace_html('element', '<p>This is a test</p>') })
44
+ assert_equal 'jQuery("#element").html("\\u003cp\\u003eThis is a test\\u003c/p\\u003e");',
45
+ generate_js(%q{ page.replace_html('element', '<p>This is a test</p>') })
46
46
  end
47
47
 
48
48
  def test_replace_element_with_string
49
- assert_equal 'jQuery("#element").replaceWith("<div id=\"element\"><p>This is a test</p></div>");',
50
- generate_js(%Q{ page.replace('element', '<div id="element"><p>This is a test</p></div>') })
49
+ assert_equal 'jQuery("#element").replaceWith("\\u003cdiv id=\"element\"\\u003e\\u003cp\\u003eThis is a test\\u003c/p\\u003e\\u003c/div\\u003e");',
50
+ generate_js(%q{ page.replace('element', '<div id="element"><p>This is a test</p></div>') })
51
+ end
52
+
53
+ def test_replace_html_with_new_line
54
+ lines = <<-'END'
55
+ page.replace_html("element_#{@element.id}", :partial => "show",
56
+ :locals => {:a => [@a], :b => false})
57
+ END
58
+ assert_equal 'jQuery("#<%= "element_#{@element.id}" %>").html("<%= escape_javascript(render(:partial => "show",' + "\n" + ' :locals => {:a => [@a], :b => false})) %>");',
59
+ generate_js(lines)
51
60
  end
52
61
 
53
62
  def test_insert_html_with_hash
54
63
  assert_equal 'jQuery("#element").prepend("<%= escape_javascript(render(:partial => "post", :locals => {:ab => "cd"})) %>");',
55
- generate_js(%Q{ page.insert_html(:top, 'element', :partial => "post", :locals => {:ab => "cd"}) })
64
+ generate_js(%q{ page.insert_html(:top, 'element', :partial => "post", :locals => {:ab => "cd"}) })
56
65
  end
57
66
 
58
67
  def test_insert_html_with_var
59
68
  assert_equal 'jQuery("#element").prepend("<%= escape_javascript(@var) %>");',
60
- generate_js(%Q{ page.insert_html(:top, 'element', @var) })
69
+ generate_js(%q{ page.insert_html(:top, 'element', @var) })
61
70
  end
62
71
 
63
72
  def test_replace_html_with_hash
64
73
  assert_equal 'jQuery("#element").html("<%= escape_javascript(render(:partial => "post", :locals => {:ab => "cd"})) %>");',
65
- generate_js(%Q{ page.replace_html('element', :partial => "post", :locals => {:ab => "cd"}) })
74
+ generate_js(%q{ page.replace_html("element", :partial => "post", :locals => {:ab => "cd"}) })
66
75
  end
67
76
 
68
77
  def test_replace_html_with_var
69
78
  assert_equal 'jQuery("#element").html("<%= escape_javascript(@var) %>");',
70
- generate_js(%Q{ page.replace_html('element', @var) })
79
+ generate_js(%q{ page.replace_html('element', @var) })
71
80
  end
72
81
 
73
82
  def test_replace_element_with_hash
74
83
  assert_equal 'jQuery("#element").replaceWith("<%= escape_javascript(render(:partial => "post", :locals => {:ab => "cd"})) %>");',
75
- generate_js(%Q{ page.replace('element', :partial => "post", :locals => {:ab => "cd"}) })
84
+ generate_js(%q{ page.replace('element', :partial => "post", :locals => {:ab => "cd"}) })
76
85
  end
77
86
 
78
87
 
79
88
  def test_remove
80
89
  assert_equal 'jQuery("#foo").remove();',
81
- generate_js(%Q{ page.remove('foo') })
90
+ generate_js(%q{ page.remove('foo') })
82
91
  assert_equal 'jQuery("#foo,#bar,#baz").remove();',
83
- generate_js(%Q{ page.remove('foo', 'bar', 'baz') })
92
+ generate_js(%q{ page.remove('foo', 'bar', 'baz') })
84
93
  end
85
94
 
86
95
  def test_show
87
96
  assert_equal 'jQuery("#foo").show();',
88
- generate_js(%Q{ page.show('foo') })
97
+ generate_js(%q{ page.show('foo') })
89
98
  assert_equal 'jQuery("#foo,#bar,#baz").show();',
90
- generate_js(%Q{ page.show('foo', 'bar', 'baz') })
99
+ generate_js(%q{ page.show('foo', 'bar', 'baz') })
91
100
  end
92
101
 
93
102
  def test_hide
94
103
  assert_equal 'jQuery("#foo").hide();',
95
- generate_js(%Q{ page.hide('foo') })
104
+ generate_js(%q{ page.hide('foo') })
96
105
  assert_equal 'jQuery("#foo,#bar,#baz").hide();',
97
- generate_js(%Q{ page.hide('foo', 'bar', 'baz') })
106
+ generate_js(%q{ page.hide('foo', 'bar', 'baz') })
98
107
  end
99
108
 
100
109
  def test_toggle
101
110
  assert_equal 'jQuery("#foo").toggle();',
102
- generate_js(%Q{ page.toggle('foo') })
111
+ generate_js(%q{ page.toggle('foo') })
103
112
  assert_equal 'jQuery("#foo,#bar,#baz").toggle();',
104
- generate_js(%Q{ page.toggle('foo', 'bar', 'baz') })
113
+ generate_js(%q{ page.toggle('foo', 'bar', 'baz') })
105
114
  end
106
115
 
107
116
  def test_alert
108
- assert_equal 'alert("hello");', generate_js(%Q{ page.alert('hello') })
117
+ assert_equal 'alert("hello");', generate_js(%q{ page.alert('hello') })
109
118
  end
110
119
 
111
120
  def test_redirect_to
112
121
  assert_equal 'window.location.href = "http://www.example.com/welcome?a=b&c=d";',
113
- generate_js(%Q{ page.redirect_to("http://www.example.com/welcome?a=b&c=d") })
122
+ generate_js(%q{ page.redirect_to("http://www.example.com/welcome?a=b&c=d") })
114
123
  assert_equal 'window.location.href = "<%= url_for(:action => \'welcome\') %>";',
115
- generate_js(%Q{ page.redirect_to(:action => 'welcome') })
124
+ generate_js(%q{ page.redirect_to(:action => 'welcome') })
116
125
  end
117
126
 
118
127
  def test_reload
119
128
  assert_equal 'window.location.reload();',
120
- generate_js(%Q{ page.reload })
129
+ generate_js(%q{ page.reload })
121
130
  end
122
131
 
123
132
  def test_element_access
124
- assert_equal %(jQuery("#hello");), generate_js(%Q{ page['hello'] })
133
+ assert_equal %(jQuery("#hello");), generate_js(%q{ page['hello'] })
125
134
  end
126
135
 
127
136
  def test_element_access_on_variable
128
- assert_equal %(jQuery("#<%= dom_id(@var) %>");), generate_js(%Q{ page[@var] })
129
- assert_equal %(jQuery("#<%= dom_id(@var) %>").hide();), generate_js(%Q{ page[@var].hide })
137
+ assert_equal %(jQuery("#<%= dom_id(@var) %>");), generate_js(%q{ page[@var] })
138
+ assert_equal %(jQuery("#<%= dom_id(@var) %>").hide();), generate_js(%q{ page[@var].hide })
130
139
  end
131
140
 
132
141
  def test_element_access_on_interpolated_string
@@ -135,66 +144,66 @@ class DeRjsTest < DeRjsBaseTest
135
144
  end
136
145
 
137
146
  def test_element_access_on_records
138
- assert_equal %(jQuery("#<%= dom_id(Bunny.new(:id => 5)) %>");), generate_js(%Q{ page[Bunny.new(:id => 5)] })
139
- assert_equal %(jQuery("#<%= dom_id(Bunny.new) %>");), generate_js(%Q{ page[Bunny.new] })
147
+ assert_equal %(jQuery("#<%= dom_id(Bunny.new(:id => 5)) %>");), generate_js(%q{ page[Bunny.new(:id => 5)] })
148
+ assert_equal %(jQuery("#<%= dom_id(Bunny.new) %>");), generate_js(%q{ page[Bunny.new] })
140
149
  end
141
150
 
142
151
  def test_element_access_on_dom_id
143
- assert_equal %(jQuery("#<%= dom_id(Bunny.new(:id => 5)) %>");), generate_js(%Q{ page[dom_id(Bunny.new(:id => 5))] })
144
- assert_equal %(jQuery("#<%= dom_id(Bunny.new) %>");), generate_js(%Q{ page[dom_id(Bunny.new)] })
152
+ assert_equal %(jQuery("#<%= dom_id(Bunny.new(:id => 5)) %>");), generate_js(%q{ page[dom_id(Bunny.new(:id => 5))] })
153
+ assert_equal %(jQuery("#<%= dom_id(Bunny.new) %>");), generate_js(%q{ page[dom_id(Bunny.new)] })
145
154
 
146
- assert_equal %(jQuery("#<%= dom_id(dom_id(Bunny.new) + evil) %>");), generate_js(%Q{ page[dom_id(Bunny.new) + evil] })
155
+ assert_equal %(jQuery("#<%= dom_id(dom_id(Bunny.new) + evil) %>");), generate_js(%q{ page[dom_id(Bunny.new) + evil] })
147
156
  end
148
157
 
149
158
  def test_element_proxy_one_deep
150
- assert_equal %(jQuery("#hello").hide();), generate_js(%Q{ page['hello'].hide })
159
+ assert_equal %(jQuery("#hello").hide();), generate_js(%q{ page['hello'].hide })
151
160
  end
152
161
 
153
162
  def test_element_proxy_variable_access
154
- assert_equal %(jQuery("#hello").style;), generate_js(%Q{ page['hello']['style'] })
163
+ assert_equal %(jQuery("#hello").style;), generate_js(%q{ page['hello']['style'] })
155
164
  end
156
165
 
157
166
  def test_element_proxy_variable_access_with_assignment
158
- assert_equal %(jQuery("#hello").style.color = "red";), generate_js(%Q{ page['hello']['style']['color'] = 'red' })
167
+ assert_equal %(jQuery("#hello").style.color = "red";), generate_js(%q{ page['hello']['style']['color'] = 'red' })
159
168
  end
160
169
 
161
170
  def test_element_proxy_assignment
162
- assert_equal %(jQuery("#hello").width = 400;), generate_js(%Q{ page['hello'].width = 400 })
171
+ assert_equal %(jQuery("#hello").width = 400;), generate_js(%q{ page['hello'].width = 400 })
163
172
  end
164
173
 
165
174
  def test_element_proxy_two_deep
166
175
  skip "I don't think this has ever worked"
167
- assert_equal %(jQuery("#hello").hide("first").cleanWhitespace();), generate_js(%Q{ page.hide("first").clean_whitespace })
176
+ assert_equal %(jQuery("#hello").hide("first").cleanWhitespace();), generate_js(%q{ page.hide("first").clean_whitespace })
168
177
  end
169
178
 
170
179
  def test_select_access
171
- assert_equal %(jQuery("div.hello");), generate_js(%Q{ page.select('div.hello') })
180
+ assert_equal %(jQuery("div.hello");), generate_js(%q{ page.select('div.hello') })
172
181
  end
173
182
 
174
183
  def test_select_proxy_one_deep
175
- assert_equal %(jQuery("p.welcome b").first().hide();), generate_js(%Q{ page.select('p.welcome b').first.hide })
184
+ assert_equal %(jQuery("p.welcome b").first().hide();), generate_js(%q{ page.select('p.welcome b').first.hide })
176
185
  end
177
186
 
178
187
  def test_visual_effect
179
188
  assert_equal %(jQuery(\"#blah\").effect(\"puff\",{});),
180
- generate_js(%Q{ page.visual_effect(:puff,'blah') })
189
+ generate_js(%q{ page.visual_effect(:puff,'blah') })
181
190
 
182
191
  assert_equal %(jQuery(\"#blah\").effect(\"puff\",{});),
183
- generate_js(%Q{ page['blah'].visual_effect(:puff) })
192
+ generate_js(%q{ page['blah'].visual_effect(:puff) })
184
193
  end
185
194
 
186
195
  def test_visual_effect_toggle
187
196
  assert_equal %(jQuery(\"#blah\").toggle(\"fade\",{});),
188
- generate_js(%Q{ page.visual_effect(:toggle_appear,'blah') })
197
+ generate_js(%q{ page.visual_effect(:toggle_appear,'blah') })
189
198
  end
190
199
 
191
200
  def test_visual_effect_with_variable
192
201
  assert_equal %(jQuery(\"#<%= "blah" + blah.id %>\").toggle(\"fade\",{});),
193
- generate_js(%Q{ page.visual_effect(:toggle_appear,"blah" + blah.id) })
202
+ generate_js(%q{ page.visual_effect(:toggle_appear,"blah" + blah.id) })
194
203
  end
195
204
 
196
205
  def test_collection_first_and_last
197
- js = generate_js(%Q{
206
+ js = generate_js(%q{
198
207
  page.select('p.welcome b').first.hide()
199
208
  page.select('p.welcome b').last.show()
200
209
  })
@@ -205,7 +214,7 @@ jQuery("p.welcome b").last().show();
205
214
  end
206
215
 
207
216
  def test_collection_proxy_with_pluck
208
- js = generate_js(%Q{ page.select('p').pluck('a', 'className') })
217
+ js = generate_js(%q{ page.select('p').pluck('a', 'className') })
209
218
  assert_equal %(var a = jQuery("p").pluck("className");), js
210
219
  end
211
220
  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.4.2
4
+ version: 0.4.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Thong Kuah