ajaxful_rating 2.2.0 → 2.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/CHANGELOG CHANGED
@@ -1,3 +1,9 @@
1
+ == 2.2.1 March 8, 2010
2
+ * Changed :force_dynamic for its opposite :force_static.
3
+ * Fixed I18n texts.
4
+ * Fixed missed quotes for Rate belongs_to association with User class
5
+ * Detailed wrapper DOM id with passed hash.
6
+
1
7
  == 2.2.0 March 7, 2010
2
8
  * Improved model methods and options.
3
9
  * Works now with inherited models.
data/Manifest CHANGED
@@ -2,7 +2,6 @@ CHANGELOG
2
2
  Manifest
3
3
  README.textile
4
4
  Rakefile
5
- ajaxful_rating.gemspec
6
5
  generators/ajaxful_rating/USAGE
7
6
  generators/ajaxful_rating/ajaxful_rating_generator.rb
8
7
  generators/ajaxful_rating/templates/images/star.png
data/README.textile CHANGED
@@ -19,17 +19,13 @@ h2. Instructions
19
19
 
20
20
  h3. Install
21
21
 
22
- To install the plugin:
22
+ To install the gem run the next command:
23
23
 
24
- @script/plugin install git://github.com/edgarjs/ajaxful-rating.git@
25
-
26
- Or the gem
27
-
28
- @sudo gem install edgarjs-ajaxful_rating --source=http://gems.github.com@
24
+ @gem install ajaxful_rating@
29
25
 
30
26
  You can configure it in your environment.rb file also:
31
27
 
32
- @config.gem "edgarjs-ajaxful_rating", :lib => "ajaxful_rating", :source => "http://gems.github.com"@
28
+ @config.gem "ajaxful_rating"@
33
29
 
34
30
  h3. Generate
35
31
 
@@ -141,8 +137,8 @@ example (if you added the @rate@ route):
141
137
  @car = Car.find(params[:id])
142
138
  @car.rate(params[:stars], current_user, params[:dimension])
143
139
  render :update do |page|
144
- page.replace_html @car.wrapper_dom_id(params[:dimension]), ratings_for(@car, params.merge(:wrap => false))
145
- page.visual_effect :highlight, @car.wrapper_dom_id(params[:dimension])
140
+ page.replace_html @car.wrapper_dom_id(params), ratings_for(@car, params.merge(:wrap => false))
141
+ page.visual_effect :highlight, @car.wrapper_dom_id(params)
146
142
  end
147
143
  end
148
144
  </pre>
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.0') do |p|
5
+ Echoe.new('ajaxful_rating', '2.2.1') 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,15 +2,15 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{ajaxful_rating}
5
- s.version = "2.2.0"
5
+ s.version = "2.2.1"
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-03-07}
9
+ s.date = %q{2010-03-08}
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/axr/css_builder.rb", "lib/axr/errors.rb", "lib/axr/helpers.rb", "lib/axr/locale.rb", "lib/axr/model.rb", "lib/axr/stars_builder.rb"]
13
- s.files = ["CHANGELOG", "Manifest", "README.textile", "Rakefile", "ajaxful_rating.gemspec", "generators/ajaxful_rating/USAGE", "generators/ajaxful_rating/ajaxful_rating_generator.rb", "generators/ajaxful_rating/templates/images/star.png", "generators/ajaxful_rating/templates/images/star_small.png", "generators/ajaxful_rating/templates/migration.rb", "generators/ajaxful_rating/templates/model.rb", "generators/ajaxful_rating/templates/style.css", "init.rb", "lib/ajaxful_rating.rb", "lib/axr/css_builder.rb", "lib/axr/errors.rb", "lib/axr/helpers.rb", "lib/axr/locale.rb", "lib/axr/model.rb", "lib/axr/stars_builder.rb"]
13
+ s.files = ["CHANGELOG", "Manifest", "README.textile", "Rakefile", "generators/ajaxful_rating/USAGE", "generators/ajaxful_rating/ajaxful_rating_generator.rb", "generators/ajaxful_rating/templates/images/star.png", "generators/ajaxful_rating/templates/images/star_small.png", "generators/ajaxful_rating/templates/migration.rb", "generators/ajaxful_rating/templates/model.rb", "generators/ajaxful_rating/templates/style.css", "init.rb", "lib/ajaxful_rating.rb", "lib/axr/css_builder.rb", "lib/axr/errors.rb", "lib/axr/helpers.rb", "lib/axr/locale.rb", "lib/axr/model.rb", "lib/axr/stars_builder.rb", "ajaxful_rating.gemspec"]
14
14
  s.homepage = %q{http://github.com/edgarjs/ajaxful-rating}
15
15
  s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Ajaxful_rating", "--main", "README.textile"]
16
16
  s.require_paths = ["lib"]
@@ -1,5 +1,5 @@
1
1
  class Rate < ActiveRecord::Base
2
- belongs_to :rater, :class_name => <%= file_name.classify %>
2
+ belongs_to :rater, :class_name => "<%= file_name.classify %>"
3
3
  belongs_to :rateable, :polymorphic => true
4
4
 
5
5
  attr_accessible :rate, :dimension
data/lib/axr/helpers.rb CHANGED
@@ -19,6 +19,7 @@ module AjaxfulRating # :nodoc:
19
19
  # * <tt>:wrap</tt> Whether the star list is wrapped within a div tag or not. This is useful when page updating. Default is true.
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
+ # * <tt>:force_static</tt> Force static stars even when you're passing a user instance.
22
23
  #
23
24
  # Example:
24
25
  # <%= ratings_for @article, :wrap => false %> # => Will produce something like:
@@ -67,15 +68,14 @@ module AjaxfulRating # :nodoc:
67
68
  # string by setting these keys on your translation hash:
68
69
  #
69
70
  # ajaxful_rating:
70
- # stars:
71
- # current_average: "Current rating: {{average}}/{{max}}"
72
- # title:
73
- # one: 1 star out of {{total}}
74
- # other: "{{count}} stars out of {{total}}"
71
+ # helper:
72
+ # global_average: "Global rating average: {{value}} out of {{max}}"
73
+ # user_rating: "Your rating: {{value}} out of {{max}}"
74
+ # hover: "Rate {{value}} out of {{max}}" def ratings_for(*args)
75
75
  def ratings_for(*args)
76
76
  @axr_css ||= CSSBuilder.new
77
77
  options = args.extract_options!.symbolize_keys.slice(:small, :remote_options,
78
- :wrap, :show_user_rating, :dimension)
78
+ :wrap, :show_user_rating, :dimension, :force_static)
79
79
  remote_options = options.delete(:remote_options) || {}
80
80
  rateable = args.shift
81
81
  user = args.shift || (respond_to?(:current_user) ? current_user : raise(NoUserSpecified))
data/lib/axr/locale.rb CHANGED
@@ -4,18 +4,27 @@ module AjaxfulRating # :nodoc:
4
4
  #
5
5
  # ajaxful_rating:
6
6
  # helper:
7
- # global_average: "Current rating average: {{value}} out of {{max}}"
7
+ # global_average: "Global rating average: {{value}} out of {{max}}"
8
8
  # user_rating: "Your rating: {{value}} out of {{max}}"
9
+ # hover: "Rate {{value}} out of {{max}}"
9
10
  module Locale
10
- def i18n(global = true)
11
- key = "ajaxful_rating.helper.#{global ? 'global_average' : 'user_rating'}"
12
- default =
13
- if global
14
- "Current rating average: {{value}} out of {{max}}"
15
- else
16
- "Your rating: {{value}} out of {{max}}"
17
- end
18
- I18n.t(key, :value => show_value, :max => rateable.class.max_stars, :default => default)
11
+
12
+ DEFAULTS = {
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
+ }
17
+
18
+ def i18n(key, value = nil)
19
+ key = if key == :current
20
+ options[:show_user_rating] ? :user_rating : :global_average
21
+ else
22
+ key.to_sym
23
+ end
24
+ default = DEFAULTS[key]
25
+ key = "ajaxful_rating.helper.#{key}"
26
+ I18n.t(key, :value => (value || show_value),
27
+ :max => rateable.class.max_stars, :default => default)
19
28
  end
20
29
  end
21
30
  end
data/lib/axr/model.rb CHANGED
@@ -86,9 +86,17 @@ module AjaxfulRating # :nodoc:
86
86
  end
87
87
 
88
88
  # Builds the DOM id attribute for the wrapper in view.
89
- def wrapper_dom_id(dimension = nil)
89
+ def wrapper_dom_id(options = {})
90
+ options = options.slice(:small, :wrap, :show_user_rating, :dimension, :force_static)
91
+ options = options.map do |k, v|
92
+ if k == :dimension
93
+ v
94
+ else
95
+ v.to_s == 'true' ? k.to_s : "no-#{k}"
96
+ end
97
+ end
90
98
  prefix = "ajaxful_rating"
91
- prefix << "_#{dimension}" unless dimension.blank?
99
+ prefix << "__#{options.join('_')}" unless options.empty?
92
100
  ApplicationController.helpers.dom_id(self, prefix)
93
101
  end
94
102
 
@@ -12,7 +12,7 @@ module AjaxfulRating # :nodoc:
12
12
 
13
13
  def show_value
14
14
  if options[:show_user_rating]
15
- rate = rateable.rate_by(user, options[:dimension])
15
+ rate = rateable.rate_by(user, options[:dimension]) if user
16
16
  rate ? rate.stars : 0
17
17
  else
18
18
  rateable.rate_average(true, options[:dimension])
@@ -29,7 +29,8 @@ module AjaxfulRating # :nodoc:
29
29
  @options = {
30
30
  :wrap => true,
31
31
  :small => false,
32
- :show_user_rating => false
32
+ :show_user_rating => false,
33
+ :force_static => false
33
34
  }.merge(options)
34
35
 
35
36
  @options[:small] = @options[:small].to_s == 'true'
@@ -60,7 +61,7 @@ module AjaxfulRating # :nodoc:
60
61
  @css_builder.rule('.ajaxful-rating.small',
61
62
  :width => (rateable.class.max_stars * 10)) if options[:small]
62
63
 
63
- stars << @template.content_tag(:li, i18n, :class => "show-value",
64
+ stars << @template.content_tag(:li, i18n(:current), :class => "show-value",
64
65
  :style => "width: #{width}%")
65
66
  stars += (1..rateable.class.max_stars).map do |i|
66
67
  star_tag(i)
@@ -77,10 +78,10 @@ module AjaxfulRating # :nodoc:
77
78
  })
78
79
 
79
80
  @template.content_tag(:li) do
80
- if user && (!already_rated || rateable.axr_config[:allow_update])
81
+ if !options[:force_static] && (user && (!already_rated || rateable.axr_config[:allow_update]))
81
82
  link_star_tag(value, css_class)
82
83
  else
83
- @template.content_tag(:span, show_value, :class => css_class, :title => i18n)
84
+ @template.content_tag(:span, show_value, :class => css_class, :title => i18n(:current))
84
85
  end
85
86
  end
86
87
  end
@@ -95,7 +96,7 @@ module AjaxfulRating # :nodoc:
95
96
  config = {
96
97
  :html => {
97
98
  :class => css_class,
98
- :title => i18n(false)
99
+ :title => i18n(:hover, value)
99
100
  },
100
101
  :url => "#{remote_options[:url]}",
101
102
  :with => "'#{query}'"
@@ -105,7 +106,7 @@ module AjaxfulRating # :nodoc:
105
106
 
106
107
  def wrapper_tag
107
108
  @template.content_tag(:div, ratings_tag, :class => "ajaxful-rating-wrapper",
108
- :id => rateable.wrapper_dom_id(options[:dimension]))
109
+ :id => rateable.wrapper_dom_id(options))
109
110
  end
110
111
  end
111
112
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 2
7
7
  - 2
8
- - 0
9
- version: 2.2.0
8
+ - 1
9
+ version: 2.2.1
10
10
  platform: ruby
11
11
  authors:
12
12
  - Edgar J. Suarez
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-03-07 00:00:00 -06:00
17
+ date: 2010-03-08 00:00:00 -06:00
18
18
  default_executable:
19
19
  dependencies: []
20
20
 
@@ -39,7 +39,6 @@ files:
39
39
  - Manifest
40
40
  - README.textile
41
41
  - Rakefile
42
- - ajaxful_rating.gemspec
43
42
  - generators/ajaxful_rating/USAGE
44
43
  - generators/ajaxful_rating/ajaxful_rating_generator.rb
45
44
  - generators/ajaxful_rating/templates/images/star.png
@@ -55,6 +54,7 @@ files:
55
54
  - lib/axr/locale.rb
56
55
  - lib/axr/model.rb
57
56
  - lib/axr/stars_builder.rb
57
+ - ajaxful_rating.gemspec
58
58
  has_rdoc: true
59
59
  homepage: http://github.com/edgarjs/ajaxful-rating
60
60
  licenses: []