puffer 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (105) hide show
  1. data/.rspec +1 -0
  2. data/Gemfile +2 -1
  3. data/Gemfile.lock +12 -0
  4. data/VERSION +1 -1
  5. data/app/cells/puffer/base/additional.html.erb +17 -0
  6. data/app/cells/puffer/base_cell.rb +25 -0
  7. data/app/controllers/admin/dashboard_controller.rb +12 -0
  8. data/app/views/admin/dashboard/index.html.erb +1 -0
  9. data/app/views/layouts/puffer.html.erb +41 -23
  10. data/app/views/puffer/_form.html.erb +3 -11
  11. data/app/views/puffer/edit.html.erb +6 -4
  12. data/app/views/puffer/index.html.erb +11 -38
  13. data/app/views/puffer/new.html.erb +5 -2
  14. data/app/views/puffer/show.html.erb +4 -4
  15. data/config/routes.rb +7 -0
  16. data/lib/generators/puffer/controller/controller_generator.rb +1 -1
  17. data/lib/generators/puffer/install/templates/puffer/javascripts/rails-src.js +399 -0
  18. data/lib/generators/puffer/install/templates/puffer/javascripts/rails.js +14 -175
  19. data/lib/generators/puffer/install/templates/puffer/javascripts/right-calendar-src.js +1461 -0
  20. data/lib/generators/puffer/install/templates/puffer/javascripts/right-calendar.js +36 -0
  21. data/lib/generators/puffer/install/templates/puffer/javascripts/right-calendar.js.gz +0 -0
  22. data/lib/generators/puffer/install/templates/puffer/javascripts/right-in-edit-src.js +369 -0
  23. data/lib/generators/puffer/install/templates/puffer/javascripts/right-in-edit.js +13 -0
  24. data/lib/generators/puffer/install/templates/puffer/javascripts/right-in-edit.js.gz +0 -0
  25. data/lib/generators/puffer/install/templates/puffer/javascripts/right-lightbox-src.js +905 -0
  26. data/lib/generators/puffer/install/templates/puffer/javascripts/right-lightbox.js +24 -0
  27. data/lib/generators/puffer/install/templates/puffer/javascripts/right-lightbox.js.gz +0 -0
  28. data/lib/generators/puffer/install/templates/puffer/javascripts/right-sortable-src.js +428 -0
  29. data/lib/generators/puffer/install/templates/puffer/javascripts/right-sortable.js +17 -0
  30. data/lib/generators/puffer/install/templates/puffer/javascripts/right-sortable.js.gz +0 -0
  31. data/lib/generators/puffer/install/templates/puffer/javascripts/right-src.js +5892 -0
  32. data/lib/generators/puffer/install/templates/puffer/javascripts/right-tabs-src.js +1145 -0
  33. data/lib/generators/puffer/install/templates/puffer/javascripts/right-tabs.js +29 -0
  34. data/lib/generators/puffer/install/templates/puffer/javascripts/right-tabs.js.gz +0 -0
  35. data/lib/generators/puffer/install/templates/puffer/javascripts/right.js +95 -0
  36. data/lib/generators/puffer/install/templates/puffer/javascripts/right.js.gz +0 -0
  37. data/lib/generators/puffer/install/templates/puffer/stylesheets/puffer.css +168 -0
  38. data/lib/generators/puffer/install/templates/puffer/stylesheets/reset.css +60 -0
  39. data/lib/puffer.rb +2 -1
  40. data/lib/puffer/base.rb +15 -14
  41. data/lib/puffer/controller/config.rb +52 -16
  42. data/lib/puffer/controller/dsl.rb +27 -29
  43. data/lib/puffer/controller/helpers.rb +54 -9
  44. data/lib/puffer/controller/mutate.rb +4 -22
  45. data/lib/puffer/engine.rb +9 -0
  46. data/lib/puffer/extensions/controller.rb +5 -3
  47. data/lib/puffer/extensions/form.rb +14 -0
  48. data/lib/puffer/extensions/mapper.rb +36 -0
  49. data/lib/puffer/fields.rb +21 -0
  50. data/lib/puffer/fields/field.rb +8 -3
  51. data/lib/puffer/inputs.rb +23 -0
  52. data/lib/puffer/inputs/association.rb +11 -0
  53. data/lib/puffer/inputs/base.rb +39 -0
  54. data/lib/puffer/inputs/boolean.rb +19 -0
  55. data/lib/puffer/inputs/collection_association.rb +11 -0
  56. data/lib/puffer/inputs/date_time.rb +16 -0
  57. data/lib/puffer/inputs/file.rb +11 -0
  58. data/lib/puffer/inputs/password.rb +11 -0
  59. data/lib/puffer/inputs/select.rb +11 -0
  60. data/lib/puffer/inputs/text.rb +11 -0
  61. data/lib/puffer/path_set.rb +17 -0
  62. data/lib/puffer/resource.rb +14 -14
  63. data/puffer.gemspec +75 -8
  64. data/spec/dummy/app/controllers/admin/categories_controller.rb +4 -0
  65. data/spec/dummy/app/controllers/admin/posts_controller.rb +4 -0
  66. data/spec/dummy/app/controllers/admin/profiles_controller.rb +5 -0
  67. data/spec/dummy/app/controllers/admin/users_controller.rb +4 -0
  68. data/spec/dummy/app/models/friendship.rb +4 -0
  69. data/spec/dummy/app/models/profile.rb +2 -0
  70. data/spec/dummy/app/models/user.rb +7 -0
  71. data/spec/dummy/app/views/admin/users/index.html.erb +1 -0
  72. data/spec/dummy/config/puffer.rb +0 -0
  73. data/spec/dummy/db/migrate/20110107082706_create_friendships.rb +15 -0
  74. data/spec/dummy/db/schema.rb +9 -1
  75. data/spec/dummy/public/puffer/javascripts/rails-src.js +399 -0
  76. data/spec/dummy/public/puffer/javascripts/rails.js +14 -0
  77. data/spec/dummy/public/puffer/javascripts/right-calendar-src.js +1461 -0
  78. data/spec/dummy/public/puffer/javascripts/right-calendar.js +36 -0
  79. data/spec/dummy/public/puffer/javascripts/right-calendar.js.gz +0 -0
  80. data/spec/dummy/public/puffer/javascripts/right-in-edit-src.js +369 -0
  81. data/spec/dummy/public/puffer/javascripts/right-in-edit.js +13 -0
  82. data/spec/dummy/public/puffer/javascripts/right-in-edit.js.gz +0 -0
  83. data/spec/dummy/public/puffer/javascripts/right-lightbox-src.js +905 -0
  84. data/spec/dummy/public/puffer/javascripts/right-lightbox.js +24 -0
  85. data/spec/dummy/public/puffer/javascripts/right-lightbox.js.gz +0 -0
  86. data/spec/dummy/public/puffer/javascripts/right-sortable-src.js +428 -0
  87. data/spec/dummy/public/puffer/javascripts/right-sortable.js +17 -0
  88. data/spec/dummy/public/puffer/javascripts/right-sortable.js.gz +0 -0
  89. data/spec/dummy/public/puffer/javascripts/right-src.js +5892 -0
  90. data/spec/dummy/public/puffer/javascripts/right-tabs-src.js +1145 -0
  91. data/spec/dummy/public/puffer/javascripts/right-tabs.js +29 -0
  92. data/spec/dummy/public/puffer/javascripts/right-tabs.js.gz +0 -0
  93. data/spec/dummy/public/puffer/javascripts/right.js +95 -0
  94. data/spec/dummy/public/puffer/javascripts/right.js.gz +0 -0
  95. data/spec/dummy/public/puffer/stylesheets/puffer.css +168 -0
  96. data/spec/dummy/public/puffer/stylesheets/reset.css +60 -0
  97. data/spec/lib/fields_spec.rb +2 -0
  98. data/spec/lib/params_spec.rb +55 -54
  99. metadata +114 -23
  100. data/lib/generators/puffer/install/templates/puffer/javascripts/application.js +0 -2
  101. data/lib/generators/puffer/install/templates/puffer/javascripts/controls.js +0 -965
  102. data/lib/generators/puffer/install/templates/puffer/javascripts/dragdrop.js +0 -974
  103. data/lib/generators/puffer/install/templates/puffer/javascripts/effects.js +0 -1123
  104. data/lib/generators/puffer/install/templates/puffer/javascripts/prototype.js +0 -6001
  105. data/lib/puffer/railtie.rb +0 -5
@@ -0,0 +1,4 @@
1
+ class Friendship < ActiveRecord::Base
2
+ belongs_to :user
3
+ belongs_to :friend, :class_name => 'User', :foreign_key => 'friend_id'
4
+ end
@@ -2,4 +2,6 @@ class Profile < ActiveRecord::Base
2
2
  belongs_to :user
3
3
  has_many :taggings, :as => :taggable
4
4
  has_many :tags, :through => :taggings
5
+
6
+ validates_presence_of :name, :surname
5
7
  end
@@ -1,4 +1,11 @@
1
1
  class User < ActiveRecord::Base
2
2
  has_one :profile
3
3
  has_many :posts
4
+
5
+ has_many :friendships
6
+ has_many :friendship_requests, :source => :friend, :through => :friendships, :conditions => {:state => 'requested'}
7
+ has_many :friends, :through => :friendships, :conditions => {:state => 'accepted'}
8
+
9
+ validates_presence_of :email, :password
10
+ validates_length_of :password, :minimum => 6
4
11
  end
@@ -0,0 +1 @@
1
+ HELO!!!
File without changes
@@ -0,0 +1,15 @@
1
+ class CreateFriendships < ActiveRecord::Migration
2
+ def self.up
3
+ create_table :friendships do |t|
4
+ t.integer :user_id
5
+ t.integer :friend_id
6
+ t.string :state
7
+
8
+ t.timestamps
9
+ end
10
+ end
11
+
12
+ def self.down
13
+ drop_table :friendships
14
+ end
15
+ end
@@ -10,7 +10,7 @@
10
10
  #
11
11
  # It's strongly recommended to check this file into your version control system.
12
12
 
13
- ActiveRecord::Schema.define(:version => 20101011160326) do
13
+ ActiveRecord::Schema.define(:version => 20110107082706) do
14
14
 
15
15
  create_table "categories", :force => true do |t|
16
16
  t.string "title"
@@ -18,6 +18,14 @@ ActiveRecord::Schema.define(:version => 20101011160326) do
18
18
  t.datetime "updated_at"
19
19
  end
20
20
 
21
+ create_table "friendships", :force => true do |t|
22
+ t.integer "user_id"
23
+ t.integer "friend_id"
24
+ t.string "state"
25
+ t.datetime "created_at"
26
+ t.datetime "updated_at"
27
+ end
28
+
21
29
  create_table "post_categories", :force => true do |t|
22
30
  t.integer "post_id"
23
31
  t.integer "category_id"
@@ -0,0 +1,399 @@
1
+ /**
2
+ * The Ruby On Rails plugin for RightJS
3
+ * http://github.com/MadRabbit/right-rails
4
+ *
5
+ * Copyright (C) 2009-2010 Nikolay Nemshilov
6
+ */
7
+ (function(window, document, RightJS) {
8
+ /**
9
+ * Underscored aliases for Ruby On Rails
10
+ *
11
+ * Copyright (C) 2009-2010 Nikolay Nemshilov
12
+ */
13
+
14
+ /**
15
+ * The Rails plugin initialization script
16
+ *
17
+ * Copyright (C) 2010 Nikolay Nemshilov
18
+ */
19
+
20
+ var R = RightJS,
21
+ $ = RightJS.$,
22
+ $$ = RightJS.$$,
23
+ $E = RightJS.$E,
24
+ Xhr = RightJS.Xhr,
25
+ Object = RightJS.Object;
26
+
27
+
28
+
29
+ // the language and window level aliases
30
+ R([
31
+ RightJS.String.prototype,
32
+ RightJS.Array.prototype,
33
+ RightJS.Function.prototype,
34
+ RightJS.Object,
35
+ RightJS.Options,
36
+ RightJS.Observer,
37
+ RightJS.Observer.prototype,
38
+ window,
39
+ document
40
+ ]).each(function(object) {
41
+ for (var key in object) {
42
+ try { // some keys are not accessable
43
+
44
+ if (/[A-Z]/.test(key) && typeof(object[key]) === 'function') {
45
+ var u_key = R(key).underscored();
46
+ if (object[u_key] === null || object[u_key] === undefined) {
47
+ object[u_key] = object[key];
48
+ }
49
+ }
50
+ } catch (e) {}
51
+ }
52
+ });
53
+
54
+
55
+ // DOM package aliases
56
+ R([
57
+ RightJS.Element,
58
+ RightJS.Event,
59
+ RightJS.Form,
60
+ RightJS.Input
61
+ ]).each(function(object) {
62
+ if (!object) { return; }
63
+
64
+ var aliases = {}, methods = object.prototype;
65
+
66
+ for (var key in methods) {
67
+ if (/[A-Z]/.test(key) && typeof(methods[key]) === 'function') {
68
+ object.prototype[R(key).underscored()] = methods[key];
69
+ }
70
+ }
71
+ });
72
+
73
+ // various ruby-like method aliases
74
+ RightJS.$alias(RightJS.String.prototype, {
75
+ index_of: 'indexOf',
76
+ last_index_of: 'lastIndexOf',
77
+ to_f: 'toFloat',
78
+ to_i: 'toInt',
79
+ gsub: 'replace',
80
+ downcase: 'toLowerCase',
81
+ upcase: 'toUpperCase',
82
+ index: 'indexOf',
83
+ rindex: 'lastIndexOf',
84
+ strip: 'trim'
85
+ });
86
+
87
+ RightJS.$alias(RightJS.Array.prototype, {
88
+ collect: 'map',
89
+ detect: 'filter',
90
+ index_of: 'indexOf',
91
+ last_index_of: 'lastIndexOf',
92
+ index: 'indexOf',
93
+ rindex: 'lastIndexOf'
94
+ });
95
+
96
+ /**
97
+ * Rails 3 UJS support module
98
+ *
99
+ * Copyright (C) 2010 Nikolay Nemshilov
100
+ */
101
+ (function() {
102
+ // tries to cancel the event via confirmation
103
+ var user_cancels = function(event, element) {
104
+ var message = element.get('data-confirm');
105
+ if (message && !confirm(message)) {
106
+ event.stop();
107
+ return true;
108
+ }
109
+ };
110
+
111
+ // adds XHR events to the element
112
+ var add_xhr_events = function(element, options) {
113
+ return Object.merge({
114
+ onCreate: function() { element.fire('ajax:loading', this); },
115
+ onComplete: function() { element.fire('ajax:complete', this); },
116
+ onSuccess: function() { element.fire('ajax:success', this); },
117
+ onFailure: function() { element.fire('ajax:failure', this); }
118
+ }, options);
119
+ };
120
+
121
+ // processes link clicks
122
+ var try_link_submit = function(event) {
123
+ var link = event.target,
124
+ method = link.get('data-method'),
125
+ remote = link.get('data-remote'),
126
+ url = link.get('href');
127
+
128
+ if (user_cancels(event, link)) { return; }
129
+ if (method || remote) { event.stop(); }
130
+
131
+ if (remote) {
132
+ Xhr.load(url, add_xhr_events(link, {
133
+ method: method || 'get',
134
+ spinner: link.get('data-spinner')
135
+ }));
136
+
137
+ } else if (method) {
138
+ var param = $$('meta[name=csrf-param]')[0],
139
+ token = $$('meta[name=csrf-token]')[0],
140
+ form = $E('form', {action: url, method: 'post'});
141
+
142
+ if (param && token) {
143
+ form.insert('<input type="hidden" name="'+param.get('content')+'" value="'+token.get('content')+'" />');
144
+ }
145
+
146
+ form.insert('<input type="hidden" name="_method" value="'+method+'"/>')
147
+ .insertTo(document.body).submit();
148
+ }
149
+ };
150
+
151
+ // global events listeners
152
+ $(document).on({
153
+ click: function(event) {
154
+ var tag = event.target._.tagName;
155
+ if (tag === 'A' || tag === 'BUTTON') {
156
+ try_link_submit(event);
157
+ }
158
+ },
159
+
160
+ submit: function(event) {
161
+ var form = event.target;
162
+ if (form.has('data-remote') && !user_cancels(event, form)) {
163
+ event.stop();
164
+ form.send(add_xhr_events(form, {
165
+ spinner: form.get('data-spinner') || form.first('.spinner')
166
+ }));
167
+ }
168
+ }
169
+ });
170
+ })();
171
+
172
+
173
+ /**
174
+ * RR is the common ajax operations wrapper for ruby on rails
175
+ *
176
+ * Copyright (C) 2009-2010 Nikolay Nemshilov
177
+ */
178
+ var RR = {
179
+ /**
180
+ * Basic options
181
+ *
182
+ * NOTE: DO NOT CHANGE this hash right here
183
+ * Use your application.js file to alter the options
184
+ */
185
+ Options: {
186
+ format: 'js', // the working format for remote requests over the application
187
+
188
+ flashId: 'flashes', // the flashes element id
189
+ flashHideFx: 'slide', // use null if you don't want any fx in here
190
+ flashHideDelay: 3200, // use -1 to disable the flash element hidding
191
+
192
+ highlightUpdates: true,
193
+
194
+ removeFx: 'fade', // blocks removing fx
195
+ insertFx: 'fade', // blocks insertion fx
196
+
197
+ insertPosition: 'bottom', // default insert position
198
+
199
+ linkToAjaxEdit: '.ajax_edit',
200
+ linkToAjaxDelete: '.ajax_delete',
201
+
202
+ rescanWithScopes: true // if it should rescan only updated elements
203
+ },
204
+
205
+ /**
206
+ * Updates the flashes block with the source
207
+ *
208
+ * @param String new content
209
+ * @return RR this
210
+ */
211
+ update_flash: function(content) {
212
+ var element = $(this.Options.flashId);
213
+ if (element) {
214
+ this.replace(element, content).hide_flash();
215
+ }
216
+ return this;
217
+ },
218
+
219
+ /**
220
+ * Initializes the delayed flashes hide call
221
+ *
222
+ * @return RR this
223
+ */
224
+ hide_flash: function() {
225
+ if (this.Options.flashHideDelay > -1) {
226
+ var element = $(this.Options.flashId);
227
+ if (element && element.visible()) {
228
+ element.hide.bind(element, this.Options.flashHideFx).delay(this.Options.flashHideDelay);
229
+ }
230
+ }
231
+ return this;
232
+ },
233
+
234
+ /**
235
+ * Highlights the element according to the options
236
+ *
237
+ * @param String element id
238
+ * @return RR this
239
+ */
240
+ highlight: function(id) {
241
+ if ($(id) && this.Options.highlightUpdates) {
242
+ $(id).highlight();
243
+ }
244
+ return this;
245
+ },
246
+
247
+ /**
248
+ * Inserts the content into the given element
249
+ *
250
+ * @param destination String destination id
251
+ * @param content String content
252
+ * @param position String position
253
+ * @return RR this
254
+ */
255
+ insert: function(where, what, in_position) {
256
+ var position = in_position || this.Options.insertPosition, new_element,
257
+ container = $(where).insert(what, position);
258
+
259
+ // trying to find the new block
260
+ switch (position) {
261
+ case 'bottom': new_element = container.children().last(); break;
262
+ case 'top': new_element = container.first(); break;
263
+ case 'before': new_element = container.prev(); break;
264
+ case 'after': new_element = container.next(); break;
265
+ }
266
+
267
+ // necely displaying the new block
268
+ if (new_element && this.Options.insertFx) {
269
+ new_element.hide().show(this.Options.insertFx, {
270
+ onFinish: this.highlight.bind(this, new_element)
271
+ });
272
+ } else {
273
+ this.highlight(new_element);
274
+ }
275
+
276
+ return this.rescan(where);
277
+ },
278
+
279
+ /**
280
+ * Replaces the given element with a new content
281
+ *
282
+ * @param destination String destination id
283
+ * @param content String content
284
+ * @return RR this
285
+ */
286
+ replace: function(id, source) {
287
+ $(id).replace(source);
288
+ return this.highlight(id).rescan(id);
289
+ },
290
+
291
+ /**
292
+ * removes the element by id
293
+ *
294
+ * @param String element id
295
+ * @return RR this
296
+ */
297
+ remove: function(id) {
298
+ if ($(id)) {
299
+ $(id).remove(this.Options.removeFx);
300
+ }
301
+ },
302
+
303
+ /**
304
+ * Makes a remote form out of the form
305
+ *
306
+ * @param String form id
307
+ * @return RR this
308
+ */
309
+ remotize_form: function(id) {
310
+ var form = $(id);
311
+ if (form) {
312
+ form.remotize().enable()._.action += '.'+this.Options.format;
313
+ }
314
+ return this;
315
+ },
316
+
317
+ /**
318
+ * Replaces the form with new content and makes it remote
319
+ *
320
+ * @param form id String form id
321
+ * @param content String content
322
+ * @return RR this
323
+ */
324
+ replace_form: function(id, source) {
325
+ var form = $(id);
326
+ if (form) {
327
+ form.replace(source);
328
+ this.remotize_form(id);
329
+ }
330
+
331
+ return this.rescan(id);
332
+ },
333
+
334
+ /**
335
+ * Inserts the form source into the given element
336
+ *
337
+ * @param target id String target id
338
+ * @param source String form source
339
+ * @return RR this
340
+ */
341
+ show_form_for: function(id, source) {
342
+ $(id).select('form').each('remove'); // removing old forms
343
+ $(id).insert(source);
344
+
345
+ return this.remotize_form($(id).first('form')).rescan(id);
346
+ },
347
+
348
+ /**
349
+ * watches link clicks and processes the ajax edit/delete operations
350
+ *
351
+ * @param Event event
352
+ */
353
+ process_click: function(event) {
354
+ var link;
355
+
356
+ if ((link = event.find('a'+ this.Options.linkToAjaxEdit))) {
357
+ event.stop();
358
+ Xhr.load(link.get('href') + '.' + this.Options.format);
359
+ } else if ((link = event.find('a'+ this.Options.linkToAjaxDelete)) && link.has('onclick')) {
360
+ event.stop();
361
+ eval('({f:'+ link.onclick.toString().replace('.submit', '.send')+'})').f.call(link);
362
+ }
363
+ },
364
+
365
+ /**
366
+ * Scans for updated elements
367
+ *
368
+ * @return RR this
369
+ */
370
+ rescan: function(scope) {
371
+ $w('Draggable Droppable Tabs Slider Selectable').each(function(name) {
372
+ if (name in window) {
373
+ window[name].rescan(this.Options.rescanWithScopes ? scope : null);
374
+ }
375
+ }, this);
376
+
377
+
378
+ return this;
379
+ }
380
+ };
381
+
382
+
383
+ /**
384
+ * the document onload hooks
385
+ *
386
+ * Copyright (C) 2010 Nikolay Nemshilov
387
+ */
388
+ $(document).on({
389
+ ready: function() {
390
+ RR.hide_flash();
391
+ },
392
+
393
+ click: function(event) {
394
+ RR.process_click(event);
395
+ }
396
+ });
397
+
398
+ window.RR = RR;
399
+ })(window, document, RightJS);