ajaxful_rating 2.1.4 → 2.1.5

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG CHANGED
@@ -1,5 +1,9 @@
1
- == 2.1.0 July 25, 2009
2
- * AjaxfulRating is now available as a gem
1
+ == 2.1.5 January 28, 2010
2
+ * Renamed options method name to avoid collapse.
3
+ * Removed CSS duplication.
3
4
 
4
5
  == 2.1.4 January 25, 2010
5
- * Added option for showing current_user's rate instead of global average
6
+ * Added option for showing current_user's rate instead of global average
7
+
8
+ == 2.1.0 July 25, 2009
9
+ * AjaxfulRating is now available as a gem
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.1.4') do |p|
5
+ Echoe.new('ajaxful_rating', '2.1.5') 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"
@@ -2,11 +2,11 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{ajaxful_rating}
5
- s.version = "2.1.4"
5
+ s.version = "2.1.5"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Edgar J. Suarez"]
9
- s.date = %q{2010-01-25}
9
+ s.date = %q{2010-01-28}
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
12
  s.extra_rdoc_files = ["CHANGELOG", "README.textile", "lib/ajaxful_rating.rb", "lib/ajaxful_rating_helper.rb", "lib/ajaxful_rating_model.rb"]
@@ -74,24 +74,22 @@ module AjaxfulRating # :nodoc:
74
74
  # other: "{{count}} stars out of {{total}}"
75
75
  def ratings_for(rateable, *args)
76
76
  user = extract_options(rateable, *args)
77
- user_rating = if options[:show_user_rating] == true and rateable.rated_by?(user, options[:dimension])
78
- rateable.rates(options[:dimension]).find_by_user_id(user).stars
77
+ user_rating = if ajaxful_rating_options[:show_user_rating] == true and rateable.rated_by?(user, ajaxful_rating_options[:dimension])
78
+ rateable.rates(ajaxful_rating_options[:dimension]).find_by_user_id(user).stars
79
79
  else
80
80
  user_rating = 0
81
81
  end
82
- ajaxful_styles << %Q(
83
- .#{options[:class]} { width: #{rateable.class.max_rate_value * 25}px; }
84
- .#{options[:small_star_class]} { width: #{rateable.class.max_rate_value * 10}px; }
85
- )
86
- width = ((options[:show_user_rating] == true ? user_rating : rateable.rate_average(true, options[:dimension])) / rateable.class.max_rate_value.to_f) * 100
87
- ul = content_tag(:ul, options[:html]) do
82
+ ajaxful_styles[ajaxful_rating_options[:class]] ||= ".#{ajaxful_rating_options[:class]} { width: #{rateable.class.max_rate_value * 25}px; }"
83
+ ajaxful_styles[ajaxful_rating_options[:small_star_class]] ||= ".#{ajaxful_rating_options[:class]}.#{ajaxful_rating_options[:small_star_class]} { width: #{rateable.class.max_rate_value * 10}px; }"
84
+ width = ((ajaxful_rating_options[:show_user_rating] == true ? user_rating : rateable.rate_average(true, ajaxful_rating_options[:dimension])) / rateable.class.max_rate_value.to_f) * 100
85
+ ul = content_tag(:ul, ajaxful_rating_options[:html]) do
88
86
  (1..rateable.class.max_rate_value).collect do |i|
89
87
  build_star rateable, user, i
90
88
  end.insert(0, content_tag(:li, current_average(rateable), :class => 'current-rating', :style => "width:#{width}%")).join
91
89
  end
92
- if options[:wrap]
93
- content_tag(:div, ul, :class => 'ajaxful-rating-wrapper', :id => "ajaxful-rating-#{!options[:dimension].blank? ?
94
- "#{options[:dimension]}-" : ''}#{rateable.class.name.tableize.singularize}-#{rateable.id}")
90
+ if ajaxful_rating_options[:wrap]
91
+ content_tag(:div, ul, :class => 'ajaxful-rating-wrapper', :id => "ajaxful-rating-#{!ajaxful_rating_options[:dimension].blank? ?
92
+ "#{ajaxful_rating_options[:dimension]}-" : ''}#{rateable.class.name.tableize.singularize}-#{rateable.id}")
95
93
  else
96
94
  ul
97
95
  end
@@ -105,7 +103,7 @@ module AjaxfulRating # :nodoc:
105
103
  # <%= ajaxful_rating_style %>
106
104
  # </head>
107
105
  def ajaxful_rating_style
108
- stylesheet_link_tag('ajaxful_rating') + content_tag(:style, ajaxful_styles,
106
+ stylesheet_link_tag('ajaxful_rating') + content_tag(:style, ajaxful_styles.values.join("\n"),
109
107
  :type => 'text/css') unless ajaxful_styles.blank?
110
108
  end
111
109
 
@@ -113,15 +111,16 @@ module AjaxfulRating # :nodoc:
113
111
 
114
112
  # Builds a star
115
113
  def build_star(rateable, user, i)
116
- a_class = "#{options[:link_class_prefix]}-#{i}"
117
- ajaxful_styles << %Q(
118
- .#{options[:class]} .#{a_class}{
114
+ a_class = "#{ajaxful_rating_options[:link_class_prefix]}-#{i}"
115
+ selector = ".#{ajaxful_rating_options[:class]} .#{a_class}"
116
+ ajaxful_styles[selector] ||= <<-EOS
117
+ #{selector} {
119
118
  width: #{(i / rateable.class.max_rate_value.to_f) * 100}%;
120
119
  z-index: #{rateable.class.max_rate_value + 2 - i};
121
120
  }
122
- )
123
- rated = rateable.rated_by?(user, options[:dimension]) if user
124
- star = if options[:force_dynamic] || (user && ((rated && rateable.class.options[:allow_update]) || !rated))
121
+ EOS
122
+ rated = rateable.rated_by?(user, ajaxful_rating_options[:dimension]) if user
123
+ star = if ajaxful_rating_options[:force_dynamic] || (user && ((rated && rateable.class.ajaxful_rating_options[:allow_update]) || !rated))
125
124
  link_to_remote(i, build_remote_options({:class => a_class, :title => pluralize_title(i, rateable.class.max_rate_value)}, i))
126
125
  else
127
126
  content_tag(:span, i, :class => a_class, :title => current_average(rateable))
@@ -130,8 +129,8 @@ module AjaxfulRating # :nodoc:
130
129
  end
131
130
 
132
131
  # Default options for the helper.
133
- def options
134
- @ajaxful_options ||= {
132
+ def ajaxful_rating_options
133
+ @ajaxful_rating_options ||= {
135
134
  :wrap => true,
136
135
  :force_dynamic => false,
137
136
  :class => 'ajaxful-rating',
@@ -151,24 +150,24 @@ module AjaxfulRating # :nodoc:
151
150
 
152
151
  # Returns the current average string.
153
152
  def current_average(rateable)
154
- I18n.t('ajaxful_rating.stars.current_average', :average => rateable.rate_average(true, options[:dimension]),
153
+ I18n.t('ajaxful_rating.stars.current_average', :average => rateable.rate_average(true, ajaxful_rating_options[:dimension]),
155
154
  :max => rateable.class.max_rate_value, :default => "Current rating: {{average}}/{{max}}")
156
155
  end
157
156
 
158
157
  # Temporary instance to hold dynamic styles.
159
158
  def ajaxful_styles
160
- @ajaxful_styles ||= ''
159
+ @ajaxful_styles ||= {}
161
160
  end
162
161
 
163
162
  # Builds the default options for the link_to_remote function.
164
163
  def build_remote_options(html, i)
165
- options[:remote_options].reverse_merge(:html => html).merge(
166
- :url => "#{options[:remote_options][:url]}?#{{:stars => i, :dimension => options[:dimension], :small_stars => options[:small_stars]}.to_query}")
164
+ ajaxful_rating_options[:remote_options].reverse_merge(:html => html).merge(
165
+ :url => "#{ajaxful_rating_options[:remote_options][:url]}?#{{:stars => i, :dimension => ajaxful_rating_options[:dimension], :small_stars => ajaxful_rating_options[:small_stars]}.to_query}")
167
166
  end
168
167
 
169
168
  # Extracts the hash options and returns the user instance.
170
169
  def extract_options(rateable, *args)
171
- options[:show_user_rating] = false # Reset
170
+ ajaxful_rating_options[:show_user_rating] = false # Reset
172
171
  user = if args.first.class.name == rateable.class.user_class_name.classify
173
172
  args.shift
174
173
  elsif args.first != :static
@@ -184,8 +183,8 @@ module AjaxfulRating # :nodoc:
184
183
  }
185
184
  end
186
185
  config[:small_stars] = (config[:small_stars].downcase == "true") if config[:small_stars].is_a?(String)
187
- options.merge!(config)
188
- options[:html].reverse_merge!(:class => "#{options[:class]} #{options[:small_star_class] if options[:small_stars]}")
186
+ ajaxful_rating_options.merge!(config)
187
+ ajaxful_rating_options[:html].reverse_merge!(:class => "#{ajaxful_rating_options[:class]} #{ajaxful_rating_options[:small_star_class] if ajaxful_rating_options[:small_stars]}")
189
188
  user
190
189
  end
191
190
  end
@@ -10,7 +10,7 @@ module AjaxfulRating # :nodoc:
10
10
  end
11
11
 
12
12
  module ClassMethods
13
- attr_reader :options
13
+ attr_reader :ajaxful_rating_options
14
14
 
15
15
  # Extends the model to be easy ajaxly rateable.
16
16
  #
@@ -33,7 +33,7 @@ module AjaxfulRating # :nodoc:
33
33
  :conditions => {:dimension => dimension.to_s}, :class_name => 'Rate', :as => :rateable
34
34
  end if options[:dimensions].is_a?(Array)
35
35
 
36
- @options = options.reverse_merge(
36
+ @ajaxful_rating_options = options.reverse_merge(
37
37
  :stars => 5,
38
38
  :allow_update => true,
39
39
  :cache_column => :rating_average
@@ -53,7 +53,7 @@ module AjaxfulRating # :nodoc:
53
53
  #
54
54
  # ajaxful_rateable :stars => 10
55
55
  def max_rate_value
56
- options[:stars]
56
+ ajaxful_rating_options[:stars]
57
57
  end
58
58
  end
59
59
 
@@ -71,9 +71,9 @@ module AjaxfulRating # :nodoc:
71
71
  # end
72
72
  def rate(stars, user, dimension = nil)
73
73
  return false if (stars.to_i > self.class.max_rate_value)
74
- raise AlreadyRatedError if (!self.class.options[:allow_update] && rated_by?(user, dimension))
74
+ raise AlreadyRatedError if (!self.class.ajaxful_rating_options[:allow_update] && rated_by?(user, dimension))
75
75
 
76
- rate = (self.class.options[:allow_update] && rated_by?(user, dimension)) ?
76
+ rate = (self.class.ajaxful_rating_options[:allow_update] && rated_by?(user, dimension)) ?
77
77
  rate_by(user, dimension) : rates(dimension).build
78
78
  rate.stars = stars
79
79
  if user.respond_to?(:rates)
@@ -148,8 +148,7 @@ module AjaxfulRating # :nodoc:
148
148
  def update_cached_average(dimension = nil)
149
149
  if self.class.caching_average?(dimension)
150
150
  rates(:refresh).size if self.respond_to?(:rates_count)
151
- send("#{caching_column_name(dimension)}=", self.rate_average(false, dimension))
152
- save!
151
+ update_attribute caching_column_name(dimension), self.rate_average(false, dimension)
153
152
  end
154
153
  end
155
154
  end
@@ -211,7 +210,7 @@ module AjaxfulRating # :nodoc:
211
210
 
212
211
  # Returns the name of the cache column for the passed dimension.
213
212
  def caching_column_name(dimension = nil)
214
- name = options[:cache_column].to_s
213
+ name = ajaxful_rating_options[:cache_column].to_s
215
214
  name += "_#{dimension.to_s.underscore}" unless dimension.blank?
216
215
  name
217
216
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ajaxful_rating
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.4
4
+ version: 2.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Edgar J. Suarez
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2010-01-25 00:00:00 -06:00
12
+ date: 2010-01-28 00:00:00 -06:00
13
13
  default_executable:
14
14
  dependencies: []
15
15