vinted-raty 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (46) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE.md +31 -0
  3. data/README.md +59 -0
  4. data/Rakefile +212 -0
  5. data/lib/tasks/vinted-raty_tasks.rake +4 -0
  6. data/lib/vinted-raty.rb +4 -0
  7. data/lib/vinted-raty/engine.rb +7 -0
  8. data/lib/vinted-raty/version.rb +3 -0
  9. data/test/dummy/README.rdoc +261 -0
  10. data/test/dummy/Rakefile +7 -0
  11. data/test/dummy/app/assets/javascripts/application.js +15 -0
  12. data/test/dummy/app/assets/stylesheets/application.css +13 -0
  13. data/test/dummy/app/controllers/application_controller.rb +3 -0
  14. data/test/dummy/app/helpers/application_helper.rb +2 -0
  15. data/test/dummy/app/views/layouts/application.html.erb +14 -0
  16. data/test/dummy/config.ru +4 -0
  17. data/test/dummy/config/application.rb +56 -0
  18. data/test/dummy/config/boot.rb +10 -0
  19. data/test/dummy/config/database.yml +25 -0
  20. data/test/dummy/config/environment.rb +5 -0
  21. data/test/dummy/config/environments/development.rb +37 -0
  22. data/test/dummy/config/environments/production.rb +67 -0
  23. data/test/dummy/config/environments/test.rb +37 -0
  24. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  25. data/test/dummy/config/initializers/inflections.rb +15 -0
  26. data/test/dummy/config/initializers/mime_types.rb +5 -0
  27. data/test/dummy/config/initializers/secret_token.rb +7 -0
  28. data/test/dummy/config/initializers/session_store.rb +8 -0
  29. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  30. data/test/dummy/config/locales/en.yml +5 -0
  31. data/test/dummy/config/routes.rb +58 -0
  32. data/test/dummy/public/404.html +26 -0
  33. data/test/dummy/public/422.html +26 -0
  34. data/test/dummy/public/500.html +25 -0
  35. data/test/dummy/public/favicon.ico +0 -0
  36. data/test/dummy/script/rails +6 -0
  37. data/test/integration/vinted_raty_integration_test.rb +27 -0
  38. data/test/test_helper.rb +16 -0
  39. data/vendor/assets/images/jquery.raty/cancel-off.png +0 -0
  40. data/vendor/assets/images/jquery.raty/cancel-on.png +0 -0
  41. data/vendor/assets/images/jquery.raty/star-half.png +0 -0
  42. data/vendor/assets/images/jquery.raty/star-off.png +0 -0
  43. data/vendor/assets/images/jquery.raty/star-on.png +0 -0
  44. data/vendor/assets/javascripts/jquery.raty.js +474 -0
  45. data/vendor/assets/javascripts/jquery.raty.min.js +12 -0
  46. metadata +243 -0
@@ -0,0 +1,26 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>The page you were looking for doesn't exist (404)</title>
5
+ <style type="text/css">
6
+ body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
7
+ div.dialog {
8
+ width: 25em;
9
+ padding: 0 4em;
10
+ margin: 4em auto 0 auto;
11
+ border: 1px solid #ccc;
12
+ border-right-color: #999;
13
+ border-bottom-color: #999;
14
+ }
15
+ h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
16
+ </style>
17
+ </head>
18
+
19
+ <body>
20
+ <!-- This file lives in public/404.html -->
21
+ <div class="dialog">
22
+ <h1>The page you were looking for doesn't exist.</h1>
23
+ <p>You may have mistyped the address or the page may have moved.</p>
24
+ </div>
25
+ </body>
26
+ </html>
@@ -0,0 +1,26 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>The change you wanted was rejected (422)</title>
5
+ <style type="text/css">
6
+ body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
7
+ div.dialog {
8
+ width: 25em;
9
+ padding: 0 4em;
10
+ margin: 4em auto 0 auto;
11
+ border: 1px solid #ccc;
12
+ border-right-color: #999;
13
+ border-bottom-color: #999;
14
+ }
15
+ h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
16
+ </style>
17
+ </head>
18
+
19
+ <body>
20
+ <!-- This file lives in public/422.html -->
21
+ <div class="dialog">
22
+ <h1>The change you wanted was rejected.</h1>
23
+ <p>Maybe you tried to change something you didn't have access to.</p>
24
+ </div>
25
+ </body>
26
+ </html>
@@ -0,0 +1,25 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>We're sorry, but something went wrong (500)</title>
5
+ <style type="text/css">
6
+ body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
7
+ div.dialog {
8
+ width: 25em;
9
+ padding: 0 4em;
10
+ margin: 4em auto 0 auto;
11
+ border: 1px solid #ccc;
12
+ border-right-color: #999;
13
+ border-bottom-color: #999;
14
+ }
15
+ h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
16
+ </style>
17
+ </head>
18
+
19
+ <body>
20
+ <!-- This file lives in public/500.html -->
21
+ <div class="dialog">
22
+ <h1>We're sorry, but something went wrong.</h1>
23
+ </div>
24
+ </body>
25
+ </html>
File without changes
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+ # This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
3
+
4
+ APP_PATH = File.expand_path('../../config/application', __FILE__)
5
+ require File.expand_path('../../config/boot', __FILE__)
6
+ require 'rails/commands'
@@ -0,0 +1,27 @@
1
+ require 'test_helper'
2
+
3
+ describe "jQuery Raty integration" do
4
+ it "pulls in jquery.raty.js" do
5
+ visit '/assets/jquery.raty.js'
6
+ page.status_code.must_equal 200
7
+ page.text.must_include "$.fn.raty.defaults"
8
+ end
9
+
10
+ it "pulls in jquery.raty.min.js" do
11
+ visit '/assets/jquery.raty.min.js'
12
+ page.status_code.must_equal 200
13
+ page.text.must_include "/* Minified"
14
+ end
15
+
16
+ it "pulls in various images" do
17
+ root = File.expand_path('../../..', __FILE__)
18
+ images = Dir.glob("#{root}/vendor/**/*.png")
19
+ images.length.must_be :>, 0
20
+
21
+ images.each do |image|
22
+ visit "/assets/jquery.raty/#{File.basename image}"
23
+ page.status_code.must_equal 200
24
+ end
25
+ end
26
+
27
+ end
@@ -0,0 +1,16 @@
1
+ # Configure Rails Environment
2
+ ENV["RAILS_ENV"] = "test"
3
+
4
+ require File.expand_path("../dummy/config/environment.rb", __FILE__)
5
+ require "rails/test_help"
6
+ require 'minitest/autorun'
7
+ require 'minitest/spec'
8
+ require 'capybara/rails'
9
+
10
+ Rails.backtrace_cleaner.remove_silencers!
11
+
12
+ class IntegrationTest < MiniTest::Spec
13
+ include Capybara::DSL
14
+
15
+ register_spec_type(/integration$/, self)
16
+ end
@@ -0,0 +1,474 @@
1
+ /*!
2
+ * jQuery Raty - A Star Rating Plugin
3
+ * ------------------------------------------------------------------
4
+ *
5
+ * jQuery Raty is a plugin that generates a customizable star rating.
6
+ *
7
+ * Licensed under The MIT License
8
+ *
9
+ * @version 2.5.2
10
+ * @since 2010.06.11
11
+ * @author Washington Botelho
12
+ * @documentation wbotelhos.com/raty
13
+ *
14
+ * ------------------------------------------------------------------
15
+ *
16
+ * <div id="star"></div>
17
+ *
18
+ * $('#star').raty();
19
+ *
20
+ */
21
+
22
+ ;(function($) {
23
+
24
+ var methods = {
25
+ init: function(settings) {
26
+ return this.each(function() {
27
+ methods.destroy.call(this);
28
+
29
+ this.opt = $.extend(true, {}, $.fn.raty.defaults, settings);
30
+
31
+ var that = $(this),
32
+ inits = ['number', 'readOnly', 'score', 'scoreName'];
33
+
34
+ methods._callback.call(this, inits);
35
+
36
+ if (this.opt.precision) {
37
+ methods._adjustPrecision.call(this);
38
+ }
39
+
40
+ this.opt.number = methods._between(this.opt.number, 0, this.opt.numberMax);
41
+
42
+ this.opt.path = this.opt.path || '';
43
+
44
+ if (this.opt.path && this.opt.path.charAt( this.opt.path.length - 1 ) !== '/') {
45
+ this.opt.path += '/';
46
+ }
47
+
48
+ this.stars = methods._createStars.call(this);
49
+ this.score = methods._createScore.call(this);
50
+
51
+ methods._apply.call(this, this.opt.score);
52
+
53
+ var space = this.opt.space ? 4 : 0,
54
+ width = this.opt.width || (this.opt.number * this.opt.size + this.opt.number * space);
55
+
56
+ if (this.opt.cancel) {
57
+ this.cancel = methods._createCancel.call(this);
58
+
59
+ width += (this.opt.size + space);
60
+ }
61
+
62
+ if (this.opt.readOnly) {
63
+ methods._lock.call(this);
64
+ } else {
65
+ that.css('cursor', 'pointer');
66
+ methods._binds.call(this);
67
+ }
68
+
69
+ if (this.opt.width !== false) {
70
+ that.css('width', width);
71
+ }
72
+
73
+ methods._target.call(this, this.opt.score);
74
+
75
+ that.data({ 'settings': this.opt, 'raty': true });
76
+ });
77
+ }, _adjustPrecision: function() {
78
+ this.opt.targetType = 'score';
79
+ this.opt.half = true;
80
+ }, _apply: function(score) {
81
+ if (score && score > 0) {
82
+ score = methods._between(score, 0, this.opt.number);
83
+ this.score.val(score);
84
+ }
85
+
86
+ methods._fill.call(this, score);
87
+
88
+ if (score) {
89
+ methods._roundStars.call(this, score);
90
+ }
91
+ }, _between: function(value, min, max) {
92
+ return Math.min(Math.max(parseFloat(value), min), max);
93
+ }, _binds: function() {
94
+ if (this.cancel) {
95
+ methods._bindCancel.call(this);
96
+ }
97
+
98
+ methods._bindClick.call(this);
99
+ methods._bindOut.call(this);
100
+ methods._bindOver.call(this);
101
+ }, _bindCancel: function() {
102
+ methods._bindClickCancel.call(this);
103
+ methods._bindOutCancel.call(this);
104
+ methods._bindOverCancel.call(this);
105
+ }, _bindClick: function() {
106
+ var self = this,
107
+ that = $(self);
108
+
109
+ self.stars.on('click.raty', function(evt) {
110
+ self.score.val((self.opt.half || self.opt.precision) ? that.data('score') : this.alt);
111
+
112
+ if (self.opt.click) {
113
+ self.opt.click.call(self, parseFloat(self.score.val()), evt);
114
+ }
115
+ });
116
+ }, _bindClickCancel: function() {
117
+ var self = this;
118
+
119
+ self.cancel.on('click.raty', function(evt) {
120
+ self.score.removeAttr('value');
121
+
122
+ if (self.opt.click) {
123
+ self.opt.click.call(self, null, evt);
124
+ }
125
+ });
126
+ }, _bindOut: function() {
127
+ var self = this;
128
+
129
+ $(this).on('mouseleave.raty', function(evt) {
130
+ var score = parseFloat(self.score.val()) || undefined;
131
+
132
+ methods._apply.call(self, score);
133
+ methods._target.call(self, score, evt);
134
+
135
+ if (self.opt.mouseout) {
136
+ self.opt.mouseout.call(self, score, evt);
137
+ }
138
+ });
139
+ }, _bindOutCancel: function() {
140
+ var self = this;
141
+
142
+ self.cancel.on('mouseleave.raty', function(evt) {
143
+ $(this).attr('src', self.opt.path + self.opt.cancelOff);
144
+
145
+ if (self.opt.mouseout) {
146
+ self.opt.mouseout.call(self, self.score.val() || null, evt);
147
+ }
148
+ });
149
+ }, _bindOverCancel: function() {
150
+ var self = this;
151
+
152
+ self.cancel.on('mouseover.raty', function(evt) {
153
+ $(this).attr('src', self.opt.path + self.opt.cancelOn);
154
+
155
+ self.stars.attr('src', self.opt.path + self.opt.starOff);
156
+
157
+ methods._target.call(self, null, evt);
158
+
159
+ if (self.opt.mouseover) {
160
+ self.opt.mouseover.call(self, null);
161
+ }
162
+ });
163
+ }, _bindOver: function() {
164
+ var self = this,
165
+ that = $(self),
166
+ action = self.opt.half ? 'mousemove.raty' : 'mouseover.raty';
167
+
168
+ self.stars.on(action, function(evt) {
169
+ var score = parseInt(this.alt, 10);
170
+
171
+ if (self.opt.half) {
172
+ var position = parseFloat((evt.pageX - $(this).offset().left) / self.opt.size),
173
+ plus = (position > .5) ? 1 : .5;
174
+
175
+ score = score - 1 + plus;
176
+
177
+ methods._fill.call(self, score);
178
+
179
+ if (self.opt.precision) {
180
+ score = score - plus + position;
181
+ }
182
+
183
+ methods._roundStars.call(self, score);
184
+
185
+ that.data('score', score);
186
+ } else {
187
+ methods._fill.call(self, score);
188
+ }
189
+
190
+ methods._target.call(self, score, evt);
191
+
192
+ if (self.opt.mouseover) {
193
+ self.opt.mouseover.call(self, score, evt);
194
+ }
195
+ });
196
+ }, _callback: function(options) {
197
+ for (var i in options) {
198
+ if (typeof this.opt[options[i]] === 'function') {
199
+ this.opt[options[i]] = this.opt[options[i]].call(this);
200
+ }
201
+ }
202
+ }, _createCancel: function() {
203
+ var that = $(this),
204
+ icon = this.opt.path + this.opt.cancelOff,
205
+ cancel = $('<img />', { src: icon, alt: 'x', title: this.opt.cancelHint, 'class': 'raty-cancel' });
206
+
207
+ if (this.opt.cancelPlace == 'left') {
208
+ that.prepend('&#160;').prepend(cancel);
209
+ } else {
210
+ that.append('&#160;').append(cancel);
211
+ }
212
+
213
+ return cancel;
214
+ }, _createScore: function() {
215
+ return $('<input />', { type: 'hidden', name: this.opt.scoreName }).appendTo(this);
216
+ }, _createStars: function() {
217
+ var that = $(this);
218
+
219
+ for (var i = 1; i <= this.opt.number; i++) {
220
+ var title = methods._getHint.call(this, i),
221
+ icon = (this.opt.score && this.opt.score >= i) ? 'starOn' : 'starOff';
222
+
223
+ icon = this.opt.path + this.opt[icon];
224
+
225
+ $('<img />', { src : icon, alt: i, title: title }).appendTo(this);
226
+
227
+ if (this.opt.space) {
228
+ that.append((i < this.opt.number) ? '&#160;' : '');
229
+ }
230
+ }
231
+
232
+ return that.children('img');
233
+ }, _error: function(message) {
234
+ $(this).html(message);
235
+
236
+ $.error(message);
237
+ }, _fill: function(score) {
238
+ var self = this,
239
+ hash = 0;
240
+
241
+ for (var i = 1; i <= self.stars.length; i++) {
242
+ var star = self.stars.eq(i - 1),
243
+ select = self.opt.single ? (i == score) : (i <= score);
244
+
245
+ if (self.opt.iconRange && self.opt.iconRange.length > hash) {
246
+ var irange = self.opt.iconRange[hash],
247
+ on = irange.on || self.opt.starOn,
248
+ off = irange.off || self.opt.starOff,
249
+ icon = select ? on : off;
250
+
251
+ if (i <= irange.range) {
252
+ star.attr('src', self.opt.path + icon);
253
+ }
254
+
255
+ if (i == irange.range) {
256
+ hash++;
257
+ }
258
+ } else {
259
+ var icon = select ? 'starOn' : 'starOff';
260
+
261
+ star.attr('src', this.opt.path + this.opt[icon]);
262
+ }
263
+ }
264
+ }, _getHint: function(score) {
265
+ var hint = this.opt.hints[score - 1];
266
+ return (hint === '') ? '' : (hint || score);
267
+ }, _lock: function() {
268
+ var score = parseInt(this.score.val(), 10), // TODO: 3.1 >> [['1'], ['2'], ['3', '.1', '.2']]
269
+ hint = score ? methods._getHint.call(this, score) : this.opt.noRatedMsg;
270
+
271
+ $(this).data('readonly', true).css('cursor', '').attr('title', hint);
272
+
273
+ this.score.attr('readonly', 'readonly');
274
+ this.stars.attr('title', hint);
275
+
276
+ if (this.cancel) {
277
+ this.cancel.hide();
278
+ }
279
+ }, _roundStars: function(score) {
280
+ var rest = (score - Math.floor(score)).toFixed(2);
281
+
282
+ if (rest > this.opt.round.down) {
283
+ var icon = 'starOn'; // Up: [x.76 .. x.99]
284
+
285
+ if (this.opt.halfShow && rest < this.opt.round.up) { // Half: [x.26 .. x.75]
286
+ icon = 'starHalf';
287
+ } else if (rest < this.opt.round.full) { // Down: [x.00 .. x.5]
288
+ icon = 'starOff';
289
+ }
290
+
291
+ this.stars.eq(Math.ceil(score) - 1).attr('src', this.opt.path + this.opt[icon]);
292
+ } // Full down: [x.00 .. x.25]
293
+ }, _target: function(score, evt) {
294
+ if (this.opt.target) {
295
+ var target = $(this.opt.target);
296
+
297
+ if (target.length === 0) {
298
+ methods._error.call(this, 'Target selector invalid or missing!');
299
+ }
300
+
301
+ if (this.opt.targetFormat.indexOf('{score}') < 0) {
302
+ methods._error.call(this, 'Template "{score}" missing!');
303
+ }
304
+
305
+ var mouseover = evt && evt.type == 'mouseover';
306
+
307
+ if (score === undefined) {
308
+ score = this.opt.targetText;
309
+ } else if (score === null) {
310
+ score = mouseover ? this.opt.cancelHint : this.opt.targetText;
311
+ } else {
312
+ if (this.opt.targetType == 'hint') {
313
+ score = methods._getHint.call(this, Math.ceil(score));
314
+ } else if (this.opt.precision) {
315
+ score = parseFloat(score).toFixed(1);
316
+ }
317
+
318
+ if (!mouseover && !this.opt.targetKeep) {
319
+ score = this.opt.targetText;
320
+ }
321
+ }
322
+
323
+ if (score) {
324
+ score = this.opt.targetFormat.toString().replace('{score}', score);
325
+ }
326
+
327
+ if (target.is(':input')) {
328
+ target.val(score);
329
+ } else {
330
+ target.html(score);
331
+ }
332
+ }
333
+ }, _unlock: function() {
334
+ $(this).data('readonly', false).css('cursor', 'pointer').removeAttr('title');
335
+
336
+ this.score.removeAttr('readonly', 'readonly');
337
+
338
+ for (var i = 0; i < this.opt.number; i++) {
339
+ this.stars.eq(i).attr('title', methods._getHint.call(this, i + 1));
340
+ }
341
+
342
+ if (this.cancel) {
343
+ this.cancel.css('display', '');
344
+ }
345
+ }, cancel: function(click) {
346
+ return this.each(function() {
347
+ if ($(this).data('readonly') !== true) {
348
+ methods[click ? 'click' : 'score'].call(this, null);
349
+ this.score.removeAttr('value');
350
+ }
351
+ });
352
+ }, click: function(score) {
353
+ return $(this).each(function() {
354
+ if ($(this).data('readonly') !== true) {
355
+ methods._apply.call(this, score);
356
+
357
+ if (!this.opt.click) {
358
+ methods._error.call(this, 'You must add the "click: function(score, evt) { }" callback.');
359
+ }
360
+
361
+
362
+ this.opt.click.call(this, score, $.Event('click'));
363
+
364
+ methods._target.call(this, score);
365
+ }
366
+ });
367
+ }, destroy: function() {
368
+ return $(this).each(function() {
369
+ var that = $(this),
370
+ raw = that.data('raw');
371
+
372
+ if (raw) {
373
+ that.off('.raty').empty().css({ cursor: raw.style.cursor, width: raw.style.width }).removeData('readonly');
374
+ } else {
375
+ that.data('raw', that.clone()[0]);
376
+ }
377
+ });
378
+ }, getScore: function() {
379
+ var score = [],
380
+ value ;
381
+
382
+ $(this).each(function() {
383
+ value = this.score.val();
384
+
385
+ score.push(value ? parseFloat(value) : undefined);
386
+ });
387
+
388
+ return (score.length > 1) ? score : score[0];
389
+ }, readOnly: function(readonly) {
390
+ return this.each(function() {
391
+ var that = $(this);
392
+
393
+ if (that.data('readonly') !== readonly) {
394
+ if (readonly) {
395
+ that.off('.raty').children('img').off('.raty');
396
+
397
+ methods._lock.call(this);
398
+ } else {
399
+ methods._binds.call(this);
400
+ methods._unlock.call(this);
401
+ }
402
+
403
+ that.data('readonly', readonly);
404
+ }
405
+ });
406
+ }, reload: function() {
407
+ return methods.set.call(this, {});
408
+ }, score: function() {
409
+ return arguments.length ? methods.setScore.apply(this, arguments) : methods.getScore.call(this);
410
+ }, set: function(settings) {
411
+ return this.each(function() {
412
+ var that = $(this),
413
+ actual = that.data('settings'),
414
+ news = $.extend({}, actual, settings);
415
+
416
+ that.raty(news);
417
+ });
418
+ }, setScore: function(score) {
419
+ return $(this).each(function() {
420
+ if ($(this).data('readonly') !== true) {
421
+ methods._apply.call(this, score);
422
+ methods._target.call(this, score);
423
+ }
424
+ });
425
+ }
426
+ };
427
+
428
+ $.fn.raty = function(method) {
429
+ if (methods[method]) {
430
+ return methods[method].apply(this, Array.prototype.slice.call(arguments, 1));
431
+ } else if (typeof method === 'object' || !method) {
432
+ return methods.init.apply(this, arguments);
433
+ } else {
434
+ $.error('Method ' + method + ' does not exist!');
435
+ }
436
+ };
437
+
438
+ $.fn.raty.defaults = {
439
+ cancel : false,
440
+ cancelHint : 'Cancel this rating!',
441
+ cancelOff : 'cancel-off.png',
442
+ cancelOn : 'cancel-on.png',
443
+ cancelPlace : 'left',
444
+ click : undefined,
445
+ half : false,
446
+ halfShow : true,
447
+ hints : ['bad', 'poor', 'regular', 'good', 'gorgeous'],
448
+ iconRange : undefined,
449
+ mouseout : undefined,
450
+ mouseover : undefined,
451
+ noRatedMsg : 'Not rated yet!',
452
+ number : 5,
453
+ numberMax : 20,
454
+ path :'/assets/jquery.raty/',
455
+ precision : false,
456
+ readOnly : false,
457
+ round : { down: .25, full: .6, up: .76 },
458
+ score : undefined,
459
+ scoreName : 'score',
460
+ single : false,
461
+ size : 16,
462
+ space : true,
463
+ starHalf : 'star-half.png',
464
+ starOff : 'star-off.png',
465
+ starOn : 'star-on.png',
466
+ target : undefined,
467
+ targetFormat : '{score}',
468
+ targetKeep : false,
469
+ targetText : '',
470
+ targetType : 'hint',
471
+ width : undefined
472
+ };
473
+
474
+ })(jQuery);