ajaxful_rating 2.2.8.2 → 2.2.9
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +1 -1
- data/ajaxful_rating.gemspec +8 -9
- data/generators/ajaxful_rating/templates/migration.rb +1 -1
- data/lib/axr/helpers.rb +5 -4
- data/lib/axr/locale.rb +6 -6
- data/lib/axr/model.rb +29 -12
- data/lib/axr/stars_builder.rb +13 -7
- metadata +6 -9
data/Rakefile
CHANGED
@@ -2,7 +2,7 @@ require 'rubygems'
|
|
2
2
|
require 'rake'
|
3
3
|
require 'echoe'
|
4
4
|
|
5
|
-
Echoe.new('ajaxful_rating', '2.2.
|
5
|
+
Echoe.new('ajaxful_rating', '2.2.9') do |p|
|
6
6
|
p.description = "Provides a simple way to add rating functionality to your application."
|
7
7
|
p.url = "http://github.com/edgarjs/ajaxful-rating"
|
8
8
|
p.author = "Edgar J. Suarez"
|
data/ajaxful_rating.gemspec
CHANGED
@@ -2,24 +2,23 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = %q{ajaxful_rating}
|
5
|
-
s.version = "2.2.
|
5
|
+
s.version = "2.2.9"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
|
8
|
-
s.authors = [
|
9
|
-
s.date = %q{
|
8
|
+
s.authors = [%q{Edgar J. Suarez}]
|
9
|
+
s.date = %q{2011-09-20}
|
10
10
|
s.description = %q{Provides a simple way to add rating functionality to your application.}
|
11
11
|
s.email = %q{edgar.js@gmail.com}
|
12
|
-
s.extra_rdoc_files = [
|
13
|
-
s.files = [
|
12
|
+
s.extra_rdoc_files = [%q{CHANGELOG}, %q{README.textile}, %q{lib/ajaxful_rating.rb}, %q{lib/axr/css_builder.rb}, %q{lib/axr/errors.rb}, %q{lib/axr/helpers.rb}, %q{lib/axr/locale.rb}, %q{lib/axr/model.rb}, %q{lib/axr/stars_builder.rb}]
|
13
|
+
s.files = [%q{CHANGELOG}, %q{Manifest}, %q{README.textile}, %q{Rakefile}, %q{ajaxful_rating.gemspec}, %q{generators/ajaxful_rating/USAGE}, %q{generators/ajaxful_rating/ajaxful_rating_generator.rb}, %q{generators/ajaxful_rating/templates/images/star.png}, %q{generators/ajaxful_rating/templates/images/star_small.png}, %q{generators/ajaxful_rating/templates/migration.rb}, %q{generators/ajaxful_rating/templates/model.rb}, %q{generators/ajaxful_rating/templates/style.css}, %q{init.rb}, %q{lib/ajaxful_rating.rb}, %q{lib/axr/css_builder.rb}, %q{lib/axr/errors.rb}, %q{lib/axr/helpers.rb}, %q{lib/axr/locale.rb}, %q{lib/axr/model.rb}, %q{lib/axr/stars_builder.rb}]
|
14
14
|
s.homepage = %q{http://github.com/edgarjs/ajaxful-rating}
|
15
|
-
s.rdoc_options = [
|
16
|
-
s.require_paths = [
|
15
|
+
s.rdoc_options = [%q{--line-numbers}, %q{--inline-source}, %q{--title}, %q{Ajaxful_rating}, %q{--main}, %q{README.textile}]
|
16
|
+
s.require_paths = [%q{lib}]
|
17
17
|
s.rubyforge_project = %q{ajaxful_rating}
|
18
|
-
s.rubygems_version = %q{1.
|
18
|
+
s.rubygems_version = %q{1.8.6}
|
19
19
|
s.summary = %q{Provides a simple way to add rating functionality to your application.}
|
20
20
|
|
21
21
|
if s.respond_to? :specification_version then
|
22
|
-
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
23
22
|
s.specification_version = 3
|
24
23
|
|
25
24
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
data/lib/axr/helpers.rb
CHANGED
@@ -20,6 +20,7 @@ module AjaxfulRating # :nodoc:
|
|
20
20
|
# * <tt>:show_user_rating</tt> Set to true if you want to display only the current user's rating, instead of the global average.
|
21
21
|
# * <tt>:dimension</tt> The dimension to show the ratings for.
|
22
22
|
# * <tt>:force_static</tt> Force static stars even when you're passing a user instance.
|
23
|
+
# * <tt>:to_nearest</tt> Allow stars to be set and averaged to nearest whatever. eg. 0.5 for the nearest half-star
|
23
24
|
#
|
24
25
|
# Example:
|
25
26
|
# <%= ratings_for @article, :wrap => false %> # => Will produce something like:
|
@@ -69,13 +70,13 @@ module AjaxfulRating # :nodoc:
|
|
69
70
|
#
|
70
71
|
# ajaxful_rating:
|
71
72
|
# helper:
|
72
|
-
# global_average: "Global rating average: {
|
73
|
-
# user_rating: "Your rating: {
|
74
|
-
# hover: "Rate {
|
73
|
+
# global_average: "Global rating average: %{value} out of %{max}"
|
74
|
+
# user_rating: "Your rating: %{value} out of %{max}"
|
75
|
+
# hover: "Rate %{value} out of %{max}" def ratings_for(*args)
|
75
76
|
def ratings_for(*args)
|
76
77
|
@axr_css ||= CSSBuilder.new
|
77
78
|
options = args.extract_options!.symbolize_keys.slice(:small, :remote_options,
|
78
|
-
:wrap, :show_user_rating, :dimension, :force_static, :current_user)
|
79
|
+
:wrap, :show_user_rating, :dimension, :force_static, :current_user, :disable_remote, :to_nearest)
|
79
80
|
remote_options = options.delete(:remote_options) || {}
|
80
81
|
rateable = args.shift
|
81
82
|
user = args.shift || (respond_to?(:current_user) ? current_user : raise(NoUserSpecified))
|
data/lib/axr/locale.rb
CHANGED
@@ -4,15 +4,15 @@ module AjaxfulRating # :nodoc:
|
|
4
4
|
#
|
5
5
|
# ajaxful_rating:
|
6
6
|
# helper:
|
7
|
-
# global_average: "Global rating average: {
|
8
|
-
# user_rating: "Your rating: {
|
9
|
-
# hover: "Rate {
|
7
|
+
# global_average: "Global rating average: %{value} out of %{max}"
|
8
|
+
# user_rating: "Your rating: %{value} out of %{max}"
|
9
|
+
# hover: "Rate %{value} out of %{max}"
|
10
10
|
module Locale
|
11
11
|
|
12
12
|
DEFAULTS = {
|
13
|
-
:user_rating => "Your rating: {
|
14
|
-
:global_average => "Global rating average: {
|
15
|
-
:hover => "Rate {
|
13
|
+
:user_rating => "Your rating: %{value} out of %{max}",
|
14
|
+
:global_average => "Global rating average: %{value} out of %{max}",
|
15
|
+
:hover => "Rate %{value} out of %{max}",
|
16
16
|
:no_ratings => "Not yet rated"
|
17
17
|
}
|
18
18
|
|
data/lib/axr/model.rb
CHANGED
@@ -12,6 +12,8 @@ module AjaxfulRating # :nodoc:
|
|
12
12
|
# * <tt>:stars</tt> Max number of stars that can be submitted.
|
13
13
|
# * <tt>:allow_update</tt> Set to true if you want users to be able to update their votes.
|
14
14
|
# * <tt>:cache_column</tt> Name of the column for storing the cached rating average.
|
15
|
+
# * <tt>:cache_column</tt> Name of the column for storing the cached rating average.
|
16
|
+
# * <tt>:to_nearest</tt> Allow stars to be set and averaged to nearest whatever . eg. 0.5 for the nearest half-star. May be overridden in the ratings_for
|
15
17
|
#
|
16
18
|
# Example:
|
17
19
|
# class Article < ActiveRecord::Base
|
@@ -146,11 +148,20 @@ module AjaxfulRating # :nodoc:
|
|
146
148
|
# Rating average for the object.
|
147
149
|
#
|
148
150
|
# Pass false as param to force the calculation if you are caching it.
|
149
|
-
def rate_average(cached = true, dimension = nil)
|
150
|
-
avg = if cached && self.class.caching_average?(dimension)
|
151
|
-
send(caching_column_name(dimension)).to_f
|
151
|
+
def rate_average(cached = true, dimension = nil, to_nearest = nil)
|
152
|
+
avg = if cached && self.class.caching_average?(dimension, to_nearest)
|
153
|
+
send(caching_column_name(dimension, to_nearest)).to_f
|
152
154
|
else
|
153
|
-
self.rates_sum(dimension).to_f / self.total_rates(dimension).to_f
|
155
|
+
avg = self.rates_sum(dimension).to_f / self.total_rates(dimension).to_f
|
156
|
+
avg.nan? ? 0.0 : avg
|
157
|
+
if avg > 0
|
158
|
+
to_nearest ||= axr_config[:to_nearest]
|
159
|
+
if to_nearest
|
160
|
+
notches = 1/to_nearest.to_f
|
161
|
+
avg = ((avg * notches).round)/notches
|
162
|
+
end
|
163
|
+
end
|
164
|
+
avg
|
154
165
|
end
|
155
166
|
avg.nan? ? 0.0 : avg
|
156
167
|
end
|
@@ -168,14 +179,14 @@ module AjaxfulRating # :nodoc:
|
|
168
179
|
end
|
169
180
|
|
170
181
|
# Returns the name of the cache column for the passed dimension.
|
171
|
-
def caching_column_name(dimension = nil)
|
172
|
-
self.class.caching_column_name(dimension)
|
182
|
+
def caching_column_name(dimension = nil, to_nearest = nil)
|
183
|
+
self.class.caching_column_name(dimension, to_nearest)
|
173
184
|
end
|
174
185
|
|
175
186
|
# Updates the cached average column in the rateable model.
|
176
|
-
def update_cached_average(dimension = nil)
|
177
|
-
if self.class.caching_average?(dimension)
|
178
|
-
update_attribute caching_column_name(dimension), self.rate_average(false, dimension)
|
187
|
+
def update_cached_average(dimension = nil, to_nearest = nil)
|
188
|
+
if self.class.caching_average?(dimension, to_nearest)
|
189
|
+
update_attribute caching_column_name(dimension, to_nearest), self.rate_average(false, dimension, to_nearest)
|
179
190
|
end
|
180
191
|
end
|
181
192
|
end
|
@@ -191,6 +202,11 @@ module AjaxfulRating # :nodoc:
|
|
191
202
|
axr_config[:stars]
|
192
203
|
end
|
193
204
|
|
205
|
+
# Allow stars to be set and averaged to nearest whatever. eg. 0.5 for the nearest half-star
|
206
|
+
def to_nearest
|
207
|
+
axr_config[:to_nearest] || 1
|
208
|
+
end
|
209
|
+
|
194
210
|
# Name of the class for the user model.
|
195
211
|
def user_class_name
|
196
212
|
Rate.reflect_on_association(:rater).options[:class_name]
|
@@ -246,14 +262,15 @@ module AjaxfulRating # :nodoc:
|
|
246
262
|
#
|
247
263
|
# ajaxful_rateable :cache_column => :my_custom_column
|
248
264
|
#
|
249
|
-
def caching_average?(dimension = nil)
|
250
|
-
column_names.include?(caching_column_name(dimension))
|
265
|
+
def caching_average?(dimension = nil, to_nearest = nil)
|
266
|
+
column_names.include?(caching_column_name(dimension, to_nearest))
|
251
267
|
end
|
252
268
|
|
253
269
|
# Returns the name of the cache column for the passed dimension.
|
254
|
-
def caching_column_name(dimension = nil)
|
270
|
+
def caching_column_name(dimension = nil, to_nearest = nil)
|
255
271
|
name = axr_config[:cache_column].to_s
|
256
272
|
name += "_#{dimension.to_s.underscore}" unless dimension.blank?
|
273
|
+
name += "_#{to_nearest.to_s.gsub('.', '_').underscore}" unless to_nearest.blank?
|
257
274
|
name
|
258
275
|
end
|
259
276
|
end
|
data/lib/axr/stars_builder.rb
CHANGED
@@ -30,6 +30,7 @@ module AjaxfulRating # :nodoc:
|
|
30
30
|
:wrap => true,
|
31
31
|
:small => false,
|
32
32
|
:show_user_rating => false,
|
33
|
+
:disable_remote => false,
|
33
34
|
:force_static => false,
|
34
35
|
:current_user => (@template.current_user if @template.respond_to?(:current_user))
|
35
36
|
}.merge(options)
|
@@ -37,7 +38,7 @@ module AjaxfulRating # :nodoc:
|
|
37
38
|
@options[:small] = @options[:small].to_s == 'true'
|
38
39
|
@options[:show_user_rating] = @options[:show_user_rating].to_s == 'true'
|
39
40
|
@options[:wrap] = @options[:wrap].to_s == 'true'
|
40
|
-
|
41
|
+
|
41
42
|
@remote_options = {
|
42
43
|
:url => nil,
|
43
44
|
:method => :post
|
@@ -64,8 +65,8 @@ module AjaxfulRating # :nodoc:
|
|
64
65
|
|
65
66
|
stars << @template.content_tag(:li, i18n(:current), :class => "show-value",
|
66
67
|
:style => "width: #{width}%")
|
67
|
-
stars += (1..rateable.class.max_stars).map do |i|
|
68
|
-
star_tag(i)
|
68
|
+
stars += (1..rateable.class.max_stars/rateable.class.to_nearest).map do |i|
|
69
|
+
star_tag(i*rateable.class.to_nearest)
|
69
70
|
end
|
70
71
|
# When using rails_xss plugin, it needs to render as HTML
|
71
72
|
stars = "".respond_to?(:html_safe) ? stars.join.html_safe : stars.join
|
@@ -74,10 +75,10 @@ module AjaxfulRating # :nodoc:
|
|
74
75
|
|
75
76
|
def star_tag(value)
|
76
77
|
already_rated = rateable.rated_by?(user, options[:dimension]) if user
|
77
|
-
css_class = "stars
|
78
|
+
css_class = "stars-%s" % [ value.to_s.gsub('.', '_') ]
|
78
79
|
@css_builder.rule(".ajaxful-rating .#{css_class}", {
|
79
80
|
:width => "#{(value / rateable.class.max_stars.to_f) * 100}%",
|
80
|
-
:zIndex => (rateable.class.max_stars + 2 - value)
|
81
|
+
:zIndex => "%.f" % ( (rateable.class.max_stars/rateable.class.to_nearest) + 2 - (value/rateable.class.to_nearest))
|
81
82
|
})
|
82
83
|
@template.content_tag(:li) do
|
83
84
|
if !options[:force_static] && (user && options[:current_user] == user &&
|
@@ -104,11 +105,16 @@ module AjaxfulRating # :nodoc:
|
|
104
105
|
:url => "#{remote_options[:url]}",
|
105
106
|
:with => "'#{query}'"
|
106
107
|
}
|
107
|
-
|
108
|
+
if options[:disable_remote]
|
109
|
+
config[:url] += "?" + query
|
110
|
+
@template.link_to(value, config[:url], config[:html])
|
111
|
+
else
|
112
|
+
@template.link_to_remote(value, remote_options.merge(config))
|
113
|
+
end
|
108
114
|
end
|
109
115
|
|
110
116
|
def wrapper_tag
|
111
|
-
@template.content_tag(:div, ratings_tag, :class => "ajaxful-rating-wrapper",
|
117
|
+
@template.content_tag(:div, ratings_tag, :class => "ajaxful-rating-wrapper#{' show-user-rating' if @options[:show_user_rating]}",
|
112
118
|
:id => rateable.wrapper_dom_id(options))
|
113
119
|
end
|
114
120
|
end
|
metadata
CHANGED
@@ -1,14 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ajaxful_rating
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
5
|
-
prerelease:
|
4
|
+
hash: 21
|
5
|
+
prerelease:
|
6
6
|
segments:
|
7
7
|
- 2
|
8
8
|
- 2
|
9
|
-
-
|
10
|
-
|
11
|
-
version: 2.2.8.2
|
9
|
+
- 9
|
10
|
+
version: 2.2.9
|
12
11
|
platform: ruby
|
13
12
|
authors:
|
14
13
|
- Edgar J. Suarez
|
@@ -16,8 +15,7 @@ autorequire:
|
|
16
15
|
bindir: bin
|
17
16
|
cert_chain: []
|
18
17
|
|
19
|
-
date:
|
20
|
-
default_executable:
|
18
|
+
date: 2011-09-20 00:00:00 Z
|
21
19
|
dependencies: []
|
22
20
|
|
23
21
|
description: Provides a simple way to add rating functionality to your application.
|
@@ -57,7 +55,6 @@ files:
|
|
57
55
|
- lib/axr/locale.rb
|
58
56
|
- lib/axr/model.rb
|
59
57
|
- lib/axr/stars_builder.rb
|
60
|
-
has_rdoc: true
|
61
58
|
homepage: http://github.com/edgarjs/ajaxful-rating
|
62
59
|
licenses: []
|
63
60
|
|
@@ -93,7 +90,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
93
90
|
requirements: []
|
94
91
|
|
95
92
|
rubyforge_project: ajaxful_rating
|
96
|
-
rubygems_version: 1.
|
93
|
+
rubygems_version: 1.8.6
|
97
94
|
signing_key:
|
98
95
|
specification_version: 3
|
99
96
|
summary: Provides a simple way to add rating functionality to your application.
|