jelly 0.6.5 → 0.8.10

Sign up to get free protection for your applications and to get access to all the features.
@@ -2,10 +2,12 @@
2
2
  # from the project root directory.
3
3
  ENV["RAILS_ENV"] ||= 'test'
4
4
  ENV['RAILS_ROOT'] ||= File.dirname(__FILE__) + '/rails_root'
5
+ ARGV.push("-b")
5
6
  require File.expand_path(File.join(ENV['RAILS_ROOT'], 'config/environment.rb'))
6
7
  require 'rubygems'
7
8
  gem "test-unit"
8
9
  require 'test/unit'
10
+ require 'rr'
9
11
 
10
12
  class Test::Unit::TestCase
11
13
  class << self
@@ -21,11 +23,13 @@ end
21
23
  require 'spec'
22
24
  require 'spec/rails'
23
25
  require 'spec/autorun'
26
+ require 'nokogiri'
24
27
 
25
28
  $LOAD_PATH.unshift(File.expand_path("#{File.dirname(__FILE__)}/../lib"))
26
29
  require "jelly"
27
30
 
28
31
  Spec::Runner.configure do |configuration|
32
+ configuration.mock_with :rr
29
33
  end
30
34
 
31
35
  class Spec::ExampleGroup
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jelly
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.5
4
+ version: 0.8.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pivotal Labs, Inc
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-11-19 00:00:00 -08:00
12
+ date: 2010-01-20 00:00:00 -08:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -41,7 +41,6 @@ files:
41
41
  - generators/jelly/templates/javascripts/ajax_with_jelly.js
42
42
  - generators/jelly/templates/javascripts/jelly.js
43
43
  - generators/jelly/templates/javascripts/jquery/jquery-1.3.2.js
44
- - generators/jelly/templates/javascripts/jquery/jquery.protify-0.3.js
45
44
  - install.rb
46
45
  - jelly.gemspec
47
46
  - lib/jelly.rb
@@ -79,8 +78,9 @@ signing_key:
79
78
  specification_version: 3
80
79
  summary: a sweet unobtrusive javascript framework for jQuery and Rails
81
80
  test_files:
82
- - spec/controllers/jelly_controller_spec.rb
83
- - spec/helpers/jelly_helper_spec.rb
81
+ - spec/jelly/common_spec.rb
82
+ - spec/jelly/jelly_controller_spec.rb
83
+ - spec/jelly/jelly_helper_spec.rb
84
84
  - spec/rails_root/app/controllers/application_controller.rb
85
85
  - spec/rails_root/app/helpers/application_helper.rb
86
86
  - spec/rails_root/config/boot.rb
@@ -1,345 +0,0 @@
1
- /**
2
- * Protify jQuery Plugin
3
- * version 0.3
4
- *
5
- * Copyright (c) 2009 Josh Powell
6
- * Licensed under the MIT license.
7
- *
8
- * * Date: 2009-02-04 11:45:50 (Wed, 04 Feb 2009)
9
- *
10
- */
11
- (function ($) {
12
- var $break = { };
13
- var arrayFunc = {
14
- _each: function(iterator) {
15
- for (var i = 0, length = this.length; i < length; i++) {
16
- iterator(this[i]);
17
- }
18
- },
19
-
20
- all: function(iterator, context) {
21
- iterator = iterator || function(x) { return x; };
22
- var result = true;
23
- this.each(function(value, index) {
24
- result = result && !!iterator.call(context, value, index);
25
- if (!result) { throw $break; }
26
- });
27
- return result;
28
- },
29
-
30
- any: function(iterator, context) {
31
- iterator = iterator || function(x) { return x; };
32
- var result = false;
33
- this.each(function(value, index) {
34
- if (result = !!iterator.call(context, value, index)) {
35
- throw $break;
36
- }
37
- });
38
- return result;
39
- },
40
-
41
- clear: function() {
42
- this.length = 0;
43
- return this;
44
- },
45
-
46
- clone: function() {
47
- return $.protify([].concat(this));
48
- },
49
-
50
- collect: function(iterator, context) {
51
- iterator = iterator || function(x) { return x; };
52
- var results = $.protify([]);
53
- this.each(function(value, index) {
54
- results.push(iterator.call(context, value, index));
55
- });
56
- return results;
57
- },
58
-
59
- detect: function(iterator, context) {
60
- var result;
61
- this.each(function(value, index) {
62
- if (iterator.call(context, value, index)) {
63
- result = value;
64
- throw $break;
65
- }
66
- });
67
- return result;
68
- },
69
-
70
- compact: function() {
71
- return $.protify(this.select(function(value) {
72
- return value !== null;
73
- }));
74
- },
75
-
76
- each: function(iterator, context) {
77
- context = context || this;
78
- var index = 0;
79
- try {
80
- this._each(function(value) {
81
- iterator.call(context, value, index++);
82
- });
83
- } catch (e) {
84
- if (e != $break) { throw e; }
85
- }
86
- return this;
87
- },
88
-
89
- eachSlice: function(number, iterator, context) {
90
- var index = -number, slices = [], array = this.toArray();
91
- if (number < 1) { return array; }
92
- while ((index += number) < array.length) {
93
- slices.push(array.slice(index, index+number));
94
- }
95
- return $.protify($.protify(slices).collect(iterator, context));
96
- },
97
-
98
- extended : function() {
99
- return true;
100
- },
101
-
102
- findAll: function(iterator, context) {
103
- var results = $.protify([]);
104
- this.each(function(value, index) {
105
- if (iterator.call(context, value, index)) {
106
- results.push(value);
107
- }
108
- });
109
- return results;
110
- },
111
-
112
- flatten: function() {
113
- return this.inject([], function(array, value) {
114
- $.protify(value);
115
- return $.protify(array.concat($.isArray(value) ?
116
- value.flatten() : [value]));
117
- });
118
- },
119
-
120
- first: function() {
121
- return this[0];
122
- },
123
-
124
- grep: function(filter, iterator, context) {
125
- iterator = iterator || function(x) { return x; };
126
- var results = $.protify([]);
127
- if (typeof filter === 'string') {
128
- filter = new RegExp(filter);
129
- }
130
-
131
- this.each(function(value, index) {
132
- if (filter.test(value)) {
133
- results.push(iterator.call(context, value, index));
134
- }
135
- });
136
- return results;
137
- },
138
-
139
- include: function(object) {
140
- if ($.isFunction(this.indexOf)) {
141
- if (this.indexOf(object) != -1) {
142
- return true;
143
- }
144
- }
145
-
146
- var found = false;
147
- this.each(function(value) {
148
- if (value == object) {
149
- found = true;
150
- throw $break;
151
- }
152
- });
153
- return found;
154
- },
155
-
156
- indexOf: function(item, i) {
157
- i || (i = 0);
158
- var length = this.length;
159
- if (i < 0) i = length + i;
160
- for (; i < length; i++)
161
- if (this[i] === item) return i;
162
- return -1;
163
- },
164
-
165
- inGroupsOf: function(number, fillWith) {
166
- fillWith = fillWith ? null : fillWith;
167
- return this.eachSlice(number, function(slice) {
168
- while(slice.length < number) { slice.push(fillWith); }
169
- return slice;
170
- });
171
- },
172
-
173
- inject: function(memo, iterator, context) {
174
- this.each(function(value, index) {
175
- memo = iterator.call(context, memo, value, index);
176
- });
177
- return memo;
178
- },
179
-
180
- inspect: function() {
181
- return '[' + this.map($.inspect).join(', ') + ']';
182
- },
183
-
184
- intersect: function(array) {
185
- $.protify(array);
186
- return this.uniq().findAll(function(item) {
187
- return array.detect(function(value) { return item === value; });
188
- });
189
- },
190
-
191
- invoke: function(method) {
192
- var args = $.makeArray(arguments).slice(1);
193
- return this.map(function(value) {
194
- return value[method].apply(value, args);
195
- });
196
- },
197
-
198
- last: function() {
199
- return this[this.length - 1];
200
- },
201
-
202
- lastIndexOf : function(item, i) {
203
- i = isNaN(i) ? this.length : (i < 0 ? this.length + i : i) + 1;
204
- var n = $.protify(this.slice(0, i).reverse()).indexOf(item);
205
- return (n < 0) ? n : i - n - 1;
206
- },
207
- max: function(iterator, context) {
208
- iterator = iterator || function(x) { return x; };
209
- var result;
210
- this.each(function(value, index) {
211
- value = iterator.call(context, value, index);
212
- if (result == null || value >= result) {
213
- result = value;
214
- }
215
- });
216
- return result;
217
- },
218
-
219
- min: function(iterator, context) {
220
- iterator = iterator || function(x) { return x; };
221
- var result;
222
- this.each(function(value, index) {
223
- value = iterator.call(context, value, index);
224
- if (result == null || value < result) {
225
- result = value;
226
- }
227
- });
228
- return result;
229
- },
230
-
231
- partition: function(iterator, context) {
232
- iterator = iterator || function(x) { return x; };
233
- var trues = [], falses = [];
234
- this.each(function(value, index) {
235
- (iterator.call(context, value, index) ? trues : falses).push(value);
236
- });
237
- return [trues, falses];
238
- },
239
-
240
- pluck: function(property) {
241
- var results = $.protify([]);
242
- this.each(function(value) {
243
- results.push(value[property]);
244
- });
245
- return results;
246
- },
247
-
248
- purge: function () {
249
- return [].concat(this);
250
- },
251
-
252
- reduce: function() {
253
- return this.length > 1 ? this : this[0];
254
- },
255
-
256
- reject: function(iterator, context) {
257
- var results = $.protify([]);
258
- this.each(function(value, index) {
259
- if (!iterator.call(context, value, index)) {
260
- results.push(value);
261
- }
262
- });
263
- return results;
264
- },
265
-
266
- size: function() {
267
- return this.length;
268
- },
269
-
270
- sortBy: function(iterator, context) {
271
- return this.map(function(value, index) {
272
- return {
273
- value: value,
274
- criteria: iterator.call(context, value, index)
275
- };
276
- }).sort(function(left, right) {
277
- var a = left.criteria, b = right.criteria;
278
- return a < b ? -1 : a > b ? 1 : 0;
279
- }).pluck('value');
280
- },
281
-
282
- toArray: function() {
283
- return $.protify(this.map());
284
- },
285
-
286
- // toJSON: function() {
287
- // var results = [];
288
- // this.each(function(object) {
289
- // var value = Object.toJSON(object);
290
- // if (!Object.isUndefined(value)) results.push(value);
291
- // });
292
- // return '[' + results.join(', ') + ']';
293
- //},
294
-
295
- uniq: function(sorted) {
296
- return $.protify(this.inject([], function(array, value, index) {
297
- $.protify(array, true);
298
- if (0 === index || (sorted ? array.last() != value : !array.include(value))) {
299
- array.push(value);
300
- }
301
- return array;
302
- }));
303
- },
304
-
305
- without: function() {
306
- var values = $.protify($.makeArray(arguments));
307
- return $.protify(this.select(function(value) {
308
- return !values.include(value);
309
- }));
310
- },
311
-
312
- zip: function() {
313
- var iterator = function(x) { return x; }, args = $.protify($.makeArray(arguments));
314
- if ($.isFunction(args.last())) {
315
- iterator = args.pop();
316
- }
317
-
318
- var collections = $.protify([this].concat(args)).map();
319
- return this.map(function(value, index) {
320
- return iterator(collections.pluck(index));
321
- });
322
- }
323
- };
324
-
325
- $.extend(arrayFunc, {
326
- map: arrayFunc.collect,
327
- find: arrayFunc.detect,
328
- select: arrayFunc.findAll,
329
- filter: arrayFunc.findAll,
330
- member: arrayFunc.include,
331
- entries: arrayFunc.toArray,
332
- every: arrayFunc.all,
333
- some: arrayFunc.any
334
- });
335
-
336
- $.protify = function(target, permanent) {
337
- if (permanent) {
338
- $.extend(target, arrayFunc);
339
- return target;
340
- }
341
- target = $.extend(target.slice(), arrayFunc);
342
- return target;
343
- };
344
-
345
- })(jQuery);
@@ -1,118 +0,0 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper.rb')
2
-
3
- describe ApplicationController do
4
-
5
- describe "#jelly_callback" do
6
- before do
7
- @controller.stub!(:render)
8
- end
9
-
10
- it "have the method included" do
11
- @controller.respond_to?(:jelly_callback).should be_true
12
- end
13
-
14
- it "should render inline the return of jelly_callback_erb" do
15
- block = lambda{'foo yo'}
16
- mock_erb = "whatever"
17
- @controller.should_receive(:jelly_callback_erb).with("on_foo", {}, block).and_return(mock_erb)
18
- @controller.should_receive(:render).with(:inline => mock_erb)
19
- @controller.send(:jelly_callback, "foo", &block)
20
- end
21
-
22
- describe "#jelly_callback_erb" do
23
- before do
24
- request.stub!(:xhr?).and_return(true)
25
- end
26
-
27
- context "with options" do
28
- it "should work with a block" do
29
- erb = @controller.send(:jelly_callback_erb, 'foo', {'bar' => 'baz'}, lambda{'grape'})
30
- JSON.parse(ERB.new(erb).result(@controller.send(:binding))).should == {
31
- 'method' => 'foo',
32
- 'arguments' => ['grape'],
33
- 'bar' => 'baz'
34
- }
35
- end
36
-
37
- it "should work without a block" do
38
- erb = @controller.send(:jelly_callback_erb, 'foo', {'bar' => 'baz'}, nil)
39
- JSON.parse(ERB.new(erb).result(@controller.send(:binding))).should == {
40
- 'method' => 'foo',
41
- 'arguments' => [],
42
- 'bar' => 'baz'
43
- }
44
- end
45
-
46
- it "should work if options are passed with symbol keys" do
47
- erb = @controller.send(:jelly_callback_erb, 'foo', {:bar => 'baz'}, nil)
48
- JSON.parse(ERB.new(erb).result(@controller.send(:binding))).should == {
49
- 'method' => 'foo',
50
- 'arguments' => [],
51
- 'bar' => 'baz'
52
- }
53
- end
54
- end
55
-
56
- context "without options" do
57
- it "should work with a block" do
58
- erb = @controller.send(:jelly_callback_erb, 'foo', {}, lambda{'grape'})
59
- JSON.parse(ERB.new(erb).result(@controller.send(:binding))).should == {
60
- 'method' => 'foo',
61
- 'arguments' => ['grape']
62
- }
63
- end
64
-
65
- it "should work with a block of more than one thing" do
66
- erb = @controller.send(:jelly_callback_erb, 'foo', {}, lambda{['grape','tangerine']})
67
- JSON.parse(ERB.new(erb).result(@controller.send(:binding))).should == {
68
- 'method' => 'foo',
69
- 'arguments' => ['grape','tangerine']
70
- }
71
- end
72
-
73
- it "should work without a block" do
74
- erb = @controller.send(:jelly_callback_erb, 'foo', {}, nil)
75
- JSON.parse(ERB.new(erb).result(@controller.send(:binding))).should == {
76
- 'method' => 'foo',
77
- 'arguments' => []
78
- }
79
- end
80
- end
81
-
82
- it "should escape html in the arguments" do
83
- block = lambda{'<div class="foo"></div>'}
84
- erb = @controller.send(:jelly_callback_erb, 'foo', {}, block)
85
- JSON.parse(ERB.new(erb).result(@controller.send(:binding))).should == {
86
- 'method' => 'foo',
87
- 'arguments' => ['<div class="foo"></div>']
88
- }
89
- end
90
-
91
- context "when the request is not an XHR" do
92
- before do
93
- request.stub!(:xhr?).and_return(false)
94
- end
95
-
96
- it "should wrap json response in a textarea tag to support File Uploads in an iframe target (see: http://malsup.com/jquery/form/#code-samples)" do
97
- erb = @controller.send(:jelly_callback_erb, 'foo', {'bar' => 'baz'}, lambda{'grape'})
98
- result = ERB.new(erb).result(@controller.send(:binding))
99
- result.should =~ /^<textarea>/
100
- result.should =~ /<\/textarea>$/
101
- end
102
- end
103
-
104
- context "when the request is an XHR" do
105
- before do
106
- request.stub!(:xhr?).and_return(true)
107
- end
108
-
109
- it "should not do the textarea nonsense" do
110
- erb = @controller.send(:jelly_callback_erb, 'foo', {'bar' => 'baz'}, lambda{'grape'})
111
- ERB.new(erb).result(@controller.send(:binding)).should_not =~ /textarea/
112
- end
113
-
114
- end
115
-
116
- end
117
- end
118
- end