jelly 0.5.4

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 (38) hide show
  1. data/.gitignore +3 -0
  2. data/MIT-LICENSE +21 -0
  3. data/README.markdown +112 -0
  4. data/Rakefile +39 -0
  5. data/VERSION +1 -0
  6. data/VERSION.yml +4 -0
  7. data/generators/jelly/USAGE +11 -0
  8. data/generators/jelly/jelly_generator.rb +12 -0
  9. data/generators/jelly/templates/javascripts/ajax_with_jelly.js +32 -0
  10. data/generators/jelly/templates/javascripts/jelly.js +81 -0
  11. data/generators/jelly/templates/javascripts/jquery/jquery-1.3.2.js +4376 -0
  12. data/generators/jelly/templates/javascripts/jquery/jquery.protify-0.3.js +345 -0
  13. data/install.rb +1 -0
  14. data/jelly.gemspec +77 -0
  15. data/lib/jelly.rb +16 -0
  16. data/lib/jelly/jelly_controller.rb +23 -0
  17. data/lib/jelly/jelly_helper.rb +42 -0
  18. data/spec/controllers/jelly_controller_spec.rb +118 -0
  19. data/spec/helpers/jelly_helper_spec.rb +54 -0
  20. data/spec/rails_root/app/controllers/application_controller.rb +10 -0
  21. data/spec/rails_root/app/helpers/application_helper.rb +3 -0
  22. data/spec/rails_root/config/boot.rb +110 -0
  23. data/spec/rails_root/config/environment.rb +41 -0
  24. data/spec/rails_root/config/environments/development.rb +17 -0
  25. data/spec/rails_root/config/environments/production.rb +28 -0
  26. data/spec/rails_root/config/environments/test.rb +28 -0
  27. data/spec/rails_root/config/initializers/backtrace_silencers.rb +7 -0
  28. data/spec/rails_root/config/initializers/inflections.rb +10 -0
  29. data/spec/rails_root/config/initializers/mime_types.rb +5 -0
  30. data/spec/rails_root/config/initializers/new_rails_defaults.rb +19 -0
  31. data/spec/rails_root/config/initializers/session_store.rb +15 -0
  32. data/spec/rails_root/config/routes.rb +43 -0
  33. data/spec/rails_root/test/performance/browsing_test.rb +9 -0
  34. data/spec/rails_root/test/test_helper.rb +38 -0
  35. data/spec/spec_helper.rb +22 -0
  36. data/tasks/jelly_tasks.rake +4 -0
  37. data/uninstall.rb +1 -0
  38. metadata +99 -0
@@ -0,0 +1,345 @@
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);
@@ -0,0 +1 @@
1
+ # Install hook code here
@@ -0,0 +1,77 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run `rake gemspec`
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{jelly}
8
+ s.version = "0.5.4"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Pivotal Labs, Inc"]
12
+ s.date = %q{2009-09-28}
13
+ s.description = %q{Jelly provides a set of tools and conventions for creating rich ajax/javascript web applications with jQuery and Ruby on Rails.}
14
+ s.email = %q{opensource@pivotallabs.com}
15
+ s.extra_rdoc_files = [
16
+ "README.markdown"
17
+ ]
18
+ s.files = [
19
+ ".gitignore",
20
+ "MIT-LICENSE",
21
+ "README.markdown",
22
+ "Rakefile",
23
+ "VERSION",
24
+ "VERSION.yml",
25
+ "generators/jelly/USAGE",
26
+ "generators/jelly/jelly_generator.rb",
27
+ "generators/jelly/templates/javascripts/ajax_with_jelly.js",
28
+ "generators/jelly/templates/javascripts/jelly.js",
29
+ "generators/jelly/templates/javascripts/jquery/jquery-1.3.2.js",
30
+ "generators/jelly/templates/javascripts/jquery/jquery.protify-0.3.js",
31
+ "install.rb",
32
+ "jelly.gemspec",
33
+ "lib/jelly.rb",
34
+ "lib/jelly/jelly_controller.rb",
35
+ "lib/jelly/jelly_helper.rb",
36
+ "tasks/jelly_tasks.rake",
37
+ "uninstall.rb"
38
+ ]
39
+ s.homepage = %q{http://github.com/pivotal/jelly}
40
+ s.rdoc_options = ["--charset=UTF-8"]
41
+ s.require_paths = ["lib"]
42
+ s.rubygems_version = %q{1.3.5}
43
+ s.summary = %q{a sweet unobtrusive javascript framework for jQuery and Rails}
44
+ s.test_files = [
45
+ "spec/controllers/jelly_controller_spec.rb",
46
+ "spec/helpers/jelly_helper_spec.rb",
47
+ "spec/rails_root/app/controllers/application_controller.rb",
48
+ "spec/rails_root/app/helpers/application_helper.rb",
49
+ "spec/rails_root/config/boot.rb",
50
+ "spec/rails_root/config/environment.rb",
51
+ "spec/rails_root/config/environments/development.rb",
52
+ "spec/rails_root/config/environments/production.rb",
53
+ "spec/rails_root/config/environments/test.rb",
54
+ "spec/rails_root/config/initializers/backtrace_silencers.rb",
55
+ "spec/rails_root/config/initializers/inflections.rb",
56
+ "spec/rails_root/config/initializers/mime_types.rb",
57
+ "spec/rails_root/config/initializers/new_rails_defaults.rb",
58
+ "spec/rails_root/config/initializers/session_store.rb",
59
+ "spec/rails_root/config/routes.rb",
60
+ "spec/rails_root/test/performance/browsing_test.rb",
61
+ "spec/rails_root/test/test_helper.rb",
62
+ "spec/spec_helper.rb"
63
+ ]
64
+
65
+ if s.respond_to? :specification_version then
66
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
67
+ s.specification_version = 3
68
+
69
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
70
+ s.add_runtime_dependency(%q<rails>, [">= 2.3.0"])
71
+ else
72
+ s.add_dependency(%q<rails>, [">= 2.3.0"])
73
+ end
74
+ else
75
+ s.add_dependency(%q<rails>, [">= 2.3.0"])
76
+ end
77
+ end
@@ -0,0 +1,16 @@
1
+ raise "Jelly must be used in a Rails environment." unless defined?(ActionController)
2
+
3
+ require 'jelly/jelly_controller'
4
+ require 'jelly/jelly_helper'
5
+
6
+ ActionController::Base.class_eval do
7
+ include JellyController
8
+ end
9
+
10
+ ActionView::Base.class_eval do
11
+ include JellyHelper
12
+ end
13
+
14
+ ActionView::Helpers::AssetTagHelper.register_javascript_expansion :jelly => ["jquery/jquery-1.3.2", "jquery/jquery.protify-0.3",
15
+ "ajax_with_jelly", "jelly"]
16
+ ActionView::Helpers::AssetTagHelper.register_javascript_expansion :only_jelly => ["jquery/jquery.protify-0.3", "jelly", "ajax_with_jelly"]
@@ -0,0 +1,23 @@
1
+ module JellyController
2
+ protected
3
+
4
+ def jelly_callback(callback_base_name = @action_name, options = {}, &block)
5
+ render :inline => jelly_callback_erb("on_#{callback_base_name}", options, block)
6
+ end
7
+
8
+ def jelly_callback_erb(callback_name, options, block)
9
+ @callback_name = callback_name
10
+ @options = options
11
+ @block = block
12
+ erb = <<-ERB
13
+ <%= begin
14
+ args = @block ? instance_eval(&@block) : []
15
+ args = [args] unless args.is_a?(Array)
16
+ {"method" => @callback_name, "arguments" => args}.reverse_merge(@options).to_json
17
+ end %>
18
+ ERB
19
+ request.xhr? ? erb : "<textarea>#{erb}</textarea>"
20
+ end
21
+
22
+
23
+ end