ratyrate 1.2.0.alpha
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +3 -0
- data/.travis.yml +5 -0
- data/Gemfile +8 -0
- data/Gemfile.lock +51 -0
- data/README.md +169 -0
- data/Rakefile +12 -0
- data/lib/generators/ratyrate/USAGE +0 -0
- data/lib/generators/ratyrate/ratyrate_generator.rb +56 -0
- data/lib/generators/ratyrate/templates/average_cache_migration.rb +17 -0
- data/lib/generators/ratyrate/templates/average_cache_model.rb +4 -0
- data/lib/generators/ratyrate/templates/big-star.png +0 -0
- data/lib/generators/ratyrate/templates/cache_migration.rb +19 -0
- data/lib/generators/ratyrate/templates/cache_model.rb +3 -0
- data/lib/generators/ratyrate/templates/cancel-off.png +0 -0
- data/lib/generators/ratyrate/templates/cancel-on.png +0 -0
- data/lib/generators/ratyrate/templates/jquery.raty.js +464 -0
- data/lib/generators/ratyrate/templates/mid-star.png +0 -0
- data/lib/generators/ratyrate/templates/migration.rb +20 -0
- data/lib/generators/ratyrate/templates/model.rb +7 -0
- data/lib/generators/ratyrate/templates/overall_average_migration.rb +16 -0
- data/lib/generators/ratyrate/templates/overall_average_model.rb +4 -0
- data/lib/generators/ratyrate/templates/rater_controller.rb +13 -0
- data/lib/generators/ratyrate/templates/ratyrate.js.erb +59 -0
- data/lib/generators/ratyrate/templates/star-half.png +0 -0
- data/lib/generators/ratyrate/templates/star-off.png +0 -0
- data/lib/generators/ratyrate/templates/star-on.png +0 -0
- data/lib/ratyrate/helpers.rb +144 -0
- data/lib/ratyrate/model.rb +153 -0
- data/lib/ratyrate/version.rb +3 -0
- data/lib/ratyrate.rb +7 -0
- data/ratyrate.gemspec +24 -0
- metadata +76 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: afb9049229e09fc34ff2b76ce661361b05914316
|
4
|
+
data.tar.gz: 97b29e7fd7793f1355e76ebdb8480dc7b2b804c7
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 137685240d3d6f07ec47aed48a9790ee7e8cbcd48133d6194fc1e416c0ebc8a717451ab8ecac41510c19b870db8c88d010533746e927d601ab3203b226d017e0
|
7
|
+
data.tar.gz: 5cd42119f1040208e7fb3c5b59ac926fc5712d03935d8fd8e794f808e09803778f0010c5480155af15de93984fe8e8dc1245e6f362daf9fd099ff8f2a2c7167a
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
ratyrate (1.0.9)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: http://rubygems.org/
|
8
|
+
specs:
|
9
|
+
actionpack (4.1.4)
|
10
|
+
actionview (= 4.1.4)
|
11
|
+
activesupport (= 4.1.4)
|
12
|
+
rack (~> 1.5.2)
|
13
|
+
rack-test (~> 0.6.2)
|
14
|
+
actionview (4.1.4)
|
15
|
+
activesupport (= 4.1.4)
|
16
|
+
builder (~> 3.1)
|
17
|
+
erubis (~> 2.7.0)
|
18
|
+
activesupport (4.1.4)
|
19
|
+
i18n (~> 0.6, >= 0.6.9)
|
20
|
+
json (~> 1.7, >= 1.7.7)
|
21
|
+
minitest (~> 5.1)
|
22
|
+
thread_safe (~> 0.1)
|
23
|
+
tzinfo (~> 1.1)
|
24
|
+
builder (3.2.2)
|
25
|
+
erubis (2.7.0)
|
26
|
+
i18n (0.6.11)
|
27
|
+
jquery-rails (3.1.1)
|
28
|
+
railties (>= 3.0, < 5.0)
|
29
|
+
thor (>= 0.14, < 2.0)
|
30
|
+
json (1.8.1)
|
31
|
+
minitest (5.4.0)
|
32
|
+
rack (1.5.2)
|
33
|
+
rack-test (0.6.2)
|
34
|
+
rack (>= 1.0)
|
35
|
+
railties (4.1.4)
|
36
|
+
actionpack (= 4.1.4)
|
37
|
+
activesupport (= 4.1.4)
|
38
|
+
rake (>= 0.8.7)
|
39
|
+
thor (>= 0.18.1, < 2.0)
|
40
|
+
rake (10.3.2)
|
41
|
+
thor (0.19.1)
|
42
|
+
thread_safe (0.3.4)
|
43
|
+
tzinfo (1.2.1)
|
44
|
+
thread_safe (~> 0.1)
|
45
|
+
|
46
|
+
PLATFORMS
|
47
|
+
ruby
|
48
|
+
|
49
|
+
DEPENDENCIES
|
50
|
+
jquery-rails (>= 3.1.1)
|
51
|
+
ratyrate!
|
data/README.md
ADDED
@@ -0,0 +1,169 @@
|
|
1
|
+
# RatyRate Stars Rating Gem [![endorse](http://api.coderwall.com/wazery/endorsecount.png)](http://coderwall.com/wazery)
|
2
|
+
|
3
|
+
A Ruby Gem that wrap the functionality of [jQuery Raty](https://github.com/wbotelhos/raty) library, and provides optional IMDB style rating.
|
4
|
+
|
5
|
+
[![Gem Version](https://badge.fury.io/rb/money-rails.png)](http://badge.fury.io/rb/money-rails)
|
6
|
+
[![Build Status](https://travis-ci.org/wazery/ratyrate.svg)](http://travis-ci.org/wazery/ratyrate)
|
7
|
+
[![Dependency Status](https://gemnasium.com/wazery/ratyrate.svg)](https://gemnasium.com/wazery/ratyrate)
|
8
|
+
[![Code Climate](https://codeclimate.com/github/wazery/ratyrate.png)](https://codeclimate.com/github/wazery/ratyrate)
|
9
|
+
[![License](http://img.shields.io/license/MIT.png?color=green)](http://opensource.org/licenses/MIT)
|
10
|
+
[![Support jQuery Raty](http://img.shields.io/gittip/wbotelhos.svg)](https://www.gittip.com/wazery "Git Tip")
|
11
|
+
|
12
|
+
## Repository
|
13
|
+
|
14
|
+
This is a fork against the repository [muratguzel/ratyrate](https://github.com/muratguzel/ratyrate), the aim of this fork is to refresh the development in this Gem with a new scope and features, so please if you have any pull request issue it here, also I imported all the issues in the original repo.
|
15
|
+
|
16
|
+
## Changelog from the main repository
|
17
|
+
|
18
|
+
1. Exposed a lot of jQuery Raty plugin [features](http://wbotelhos.com/raty)
|
19
|
+
1. Added cancel button that can be customized and inserted to left or right
|
20
|
+
2. Added the ability to set custom star images for on, half or off state
|
21
|
+
3. Added the ability to set a custom path for the images
|
22
|
+
4. Added the ability to enable/disable half stars
|
23
|
+
5. Added the ability to turn on/off half star
|
24
|
+
2. Their is a new option now to disable or enable the rating after the first rate
|
25
|
+
3. Added a star style to show just the score of the dimension, but this star is not editable
|
26
|
+
4. Added an overall average star just like IMDB style
|
27
|
+
3. Nothing else
|
28
|
+
4. :wq
|
29
|
+
|
30
|
+
## TODO
|
31
|
+
|
32
|
+
1. Write RSpec tests for this Gem
|
33
|
+
2. Create a Heroku app to illustrate this Gem's purpose and features (MovieStore)
|
34
|
+
3. Add option to show the number of users who gave rates
|
35
|
+
4. Add a share helper to Facebook, Twitter
|
36
|
+
|
37
|
+
## Detailed view of the new features
|
38
|
+
|
39
|
+
![Detailed view of the new featurews](https://dl.dropboxusercontent.com/u/71605080/RatyRate%20Features.png)
|
40
|
+
|
41
|
+
## Instructions
|
42
|
+
|
43
|
+
### Install
|
44
|
+
|
45
|
+
Add the ratyrate gem into your Gemfile
|
46
|
+
|
47
|
+
```ruby
|
48
|
+
gem 'ratyrate'
|
49
|
+
```
|
50
|
+
|
51
|
+
### Generate
|
52
|
+
|
53
|
+
```
|
54
|
+
rails g ratyrate User
|
55
|
+
```
|
56
|
+
|
57
|
+
The generator takes one argument which is the name of your existing devise user model UserModelName. This is necessary to bind the user and rating datas.
|
58
|
+
Also the generator copies necessary files (jQuery Raty plugin files, star icons and JavaScript files)
|
59
|
+
|
60
|
+
Example:
|
61
|
+
|
62
|
+
Suppose you will have a devise user model which name is User. The devise generator and ratyrate generator should be like below
|
63
|
+
|
64
|
+
```
|
65
|
+
rails g devise:install
|
66
|
+
rails g devise user
|
67
|
+
|
68
|
+
rails g ratyrate user # => user is the model generated by devise
|
69
|
+
```
|
70
|
+
|
71
|
+
This generator will create Rate and RatingCache models and link to your user model.
|
72
|
+
|
73
|
+
### Prepare
|
74
|
+
|
75
|
+
I suppose you have a car model
|
76
|
+
|
77
|
+
```
|
78
|
+
rails g model car name:string
|
79
|
+
```
|
80
|
+
|
81
|
+
You should add the ratyrate_rateable function with its dimensions option. You can add multiple dimensions.
|
82
|
+
|
83
|
+
```ruby
|
84
|
+
class Car < ActiveRecord::Base
|
85
|
+
ratyrate_rateable "speed", "engine", "price"
|
86
|
+
end
|
87
|
+
```
|
88
|
+
|
89
|
+
Then you need to add a call ratyrate_rater in the user model.
|
90
|
+
|
91
|
+
```ruby
|
92
|
+
class User < ActiveRecord::Base
|
93
|
+
ratyrate_rater
|
94
|
+
end
|
95
|
+
```
|
96
|
+
|
97
|
+
### Using
|
98
|
+
|
99
|
+
There is a helper method which name is rating_for to add the star links. By default rating_for will display the average rating and accept the
|
100
|
+
new rating value from authenticated user.
|
101
|
+
|
102
|
+
```erb
|
103
|
+
<%# show.html.erb -> /cars/1 %>
|
104
|
+
|
105
|
+
Speed : <%= rating_for @car, "speed" %>
|
106
|
+
Engine : <%= rating_for @car, "engine" %>
|
107
|
+
Price : <%= rating_for @car, "price" %>
|
108
|
+
```
|
109
|
+
|
110
|
+
### Available Options
|
111
|
+
|
112
|
+
1- If you need to change the star number, you should use star option like below.
|
113
|
+
```erb
|
114
|
+
Speed : <%= rating_for @car, "speed", :star => 10 %>
|
115
|
+
Speed : <%= rating_for @car, "engine", :star => 7 %>
|
116
|
+
Speed : <%= rating_for @car, "price" %>
|
117
|
+
```
|
118
|
+
2- To enable half stars use the option *enable_half*
|
119
|
+
```erb
|
120
|
+
Speed : <%= rating_for @car, "speed", :enable_half => true %>
|
121
|
+
```
|
122
|
+
3- To show or hide the half stars use *half_show*
|
123
|
+
```erb
|
124
|
+
Speed : <%= rating_for @car, "speed", :half_show => true %>
|
125
|
+
```
|
126
|
+
4- To change the path in which the star images (star-on.png, star-off.png, star-half.png, ..etc) are located use
|
127
|
+
```erb
|
128
|
+
Speed : <%= rating_for @car, "speed", :star_path => true %>
|
129
|
+
```
|
130
|
+
|
131
|
+
To just change one of the star images choose from these options (star_on, star_off, star_half)
|
132
|
+
|
133
|
+
5- To add the cancel button to the left, or right of the stars use **(default is false)**
|
134
|
+
```erb
|
135
|
+
Speed : <%= rating_for @car, "speed", :cancel => true %>
|
136
|
+
```
|
137
|
+
6- To change the place of the cancel button (left, or right) use **(default is left)**
|
138
|
+
```erb
|
139
|
+
Speed : <%= rating_for @car, "speed", :cancel_place => left %>
|
140
|
+
```
|
141
|
+
7- To change the hint on the cancel button use **(default is "Cancel current rating!" )**
|
142
|
+
```erb
|
143
|
+
Speed : <%= rating_for @car, "speed", :cancel_hint => "Cancel this rating!" %>
|
144
|
+
```
|
145
|
+
8- To change the image of the cancel on button use
|
146
|
+
```erb
|
147
|
+
Speed : <%= rating_for @car, "speed", :cancel_on => "cancel-on2.png" %>
|
148
|
+
```
|
149
|
+
9- To change the image of the cancel off use
|
150
|
+
```erb
|
151
|
+
Speed : <%= rating_for @car, "speed", :cancel_off => "cancel-off2.png" %>
|
152
|
+
```
|
153
|
+
### Other Helpers
|
154
|
+
|
155
|
+
You can use the *rating_for_user* helper method to show the star rating for the user.
|
156
|
+
|
157
|
+
```erb
|
158
|
+
Speed : <%= rating_for_user @car, current_user, "speed", :star => 10 %>
|
159
|
+
```
|
160
|
+
|
161
|
+
And you can use the *imdb_style_rating_for* to show a similar to IMDB rating style.
|
162
|
+
|
163
|
+
```erb
|
164
|
+
Speed : <%= imdb_style_rating_for @car, current_user %>
|
165
|
+
```
|
166
|
+
|
167
|
+
## Feedback
|
168
|
+
If you find bugs please open a ticket at [https://github.com/wazery/ratyrate/issues](https://github.com/wazery/ratyrate/issues)
|
169
|
+
|
data/Rakefile
ADDED
File without changes
|
@@ -0,0 +1,56 @@
|
|
1
|
+
require 'rails/generators/migration'
|
2
|
+
require 'rails/generators/active_record'
|
3
|
+
class RatyrateGenerator < ActiveRecord::Generators::Base
|
4
|
+
include Rails::Generators::Migration
|
5
|
+
|
6
|
+
source_root File.expand_path('../templates', __FILE__)
|
7
|
+
|
8
|
+
desc "copying jquery.raty files to assets directory ..."
|
9
|
+
def copying
|
10
|
+
copy_file 'jquery.raty.js', 'app/assets/javascripts/jquery.raty.js'
|
11
|
+
copy_file 'star-on.png', 'app/assets/images/star-on.png'
|
12
|
+
copy_file 'star-off.png', 'app/assets/images/star-off.png'
|
13
|
+
copy_file 'star-half.png', 'app/assets/images/star-half.png'
|
14
|
+
copy_file 'mid-star.png', 'app/assets/images/mid-star.png'
|
15
|
+
copy_file 'big-star.png', 'app/assets/images/big-star.png'
|
16
|
+
copy_file 'cancel-on.png', 'app/assets/images/cancel-on.png'
|
17
|
+
copy_file 'cancel-off.png', 'app/assets/images/cancel-off.png'
|
18
|
+
copy_file 'ratyrate.js.erb', 'app/assets/javascripts/ratyrate.js.erb'
|
19
|
+
copy_file 'rater_controller.rb', 'app/controllers/rater_controller.rb'
|
20
|
+
end
|
21
|
+
|
22
|
+
desc "model is creating..."
|
23
|
+
def create_model
|
24
|
+
model_file = File.join('app/models', "#{file_path}.rb")
|
25
|
+
raise "User model (#{model_file}) must exits." unless File.exists?(model_file)
|
26
|
+
class_collisions 'Rate'
|
27
|
+
template 'model.rb', File.join('app/models', "rate.rb")
|
28
|
+
template 'cache_model.rb', File.join('app/models', "rating_cache.rb")
|
29
|
+
template 'average_cache_model.rb', File.join('app/models', "average_cache.rb")
|
30
|
+
template 'overall_average_model.rb', File.join('app/models', "overall_average.rb")
|
31
|
+
end
|
32
|
+
|
33
|
+
def add_rate_path_to_route
|
34
|
+
route "post '/rate' => 'rater#create', :as => 'rate'"
|
35
|
+
end
|
36
|
+
|
37
|
+
desc "cacheable rating average migration is creating ..."
|
38
|
+
def create_cacheable_migration
|
39
|
+
migration_template "cache_migration.rb", "db/migrate/create_rating_caches.rb"
|
40
|
+
end
|
41
|
+
|
42
|
+
desc "migration is creating ..."
|
43
|
+
def create_ratyrate_migration
|
44
|
+
migration_template "migration.rb", "db/migrate/create_rates.rb"
|
45
|
+
end
|
46
|
+
|
47
|
+
desc "average caches migration is creating ..."
|
48
|
+
def create_average_caches_migration
|
49
|
+
migration_template "average_cache_migration.rb", "db/migrate/create_average_caches.rb"
|
50
|
+
end
|
51
|
+
|
52
|
+
desc "overall averages migration is creating ..."
|
53
|
+
def create_overall_averages_migration
|
54
|
+
migration_template "overall_average_migration.rb", "db/migrate/create_overall_averages.rb"
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
class CreateAverageCaches < ActiveRecord::Migration
|
2
|
+
|
3
|
+
def self.up
|
4
|
+
create_table :average_caches do |t|
|
5
|
+
t.belongs_to :rater
|
6
|
+
t.belongs_to :rateable, :polymorphic => true
|
7
|
+
t.float :avg, :null => false
|
8
|
+
t.timestamps
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.down
|
13
|
+
drop_table :average_caches
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
|
Binary file
|
@@ -0,0 +1,19 @@
|
|
1
|
+
class CreateRatingCaches < ActiveRecord::Migration
|
2
|
+
|
3
|
+
def self.up
|
4
|
+
create_table :rating_caches do |t|
|
5
|
+
t.belongs_to :cacheable, :polymorphic => true
|
6
|
+
t.float :avg, :null => false
|
7
|
+
t.integer :qty, :null => false
|
8
|
+
t.string :dimension
|
9
|
+
t.timestamps
|
10
|
+
end
|
11
|
+
|
12
|
+
add_index :rating_caches, [:cacheable_id, :cacheable_type]
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.down
|
16
|
+
drop_table :rating_caches
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
Binary file
|
Binary file
|