Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecated method #3

Open
wants to merge 27 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
a21e428
Add Rails 3 generator and code changes
odorcicd Mar 11, 2010
0b25124
nested content_tags fixed in Rails commit 4464b8e - reverting back to…
odorcicd Mar 12, 2010
a4ac23a
Add html_safe to star_tags to mark the string as safe
odorcicd Mar 12, 2010
6708c2d
Remove updated to v2.2.x message
odorcicd Mar 13, 2010
c2fa203
Fix Error classes not being called correctly
odorcicd Mar 13, 2010
5888fc4
Add initial testing because a plugin like this needs some :)
odorcicd Mar 13, 2010
f78aea7
Remove empty strings from wrapper_dom_id, otherwise you get back __ w…
odorcicd Mar 13, 2010
4cd6950
Do away with data-url when building the star links as the support is …
odorcicd Mar 19, 2010
47e7b0d
Remove Rails 2.x style generator
odorcicd Mar 13, 2010
f67a233
Change gem manager to jeweler
edgarjs May 3, 2010
fa5a50e
fixing singular_class_name to dom_class for rails3.0.0.rc
msaffitz Aug 8, 2010
e2a6408
replacing returning with tap
msaffitz Aug 8, 2010
85221d1
bumping beta2
edgarjs Aug 9, 2010
81b563e
Changing I18n keys
edgarjs Oct 14, 2010
7fc2780
Merge branch 'rails3' of github.com:danbee/ajaxful_rating_jquery into…
danbee Jun 22, 2011
4f9dc29
Merge branch 'rails3' of ../ajaxful-rating into rails3
danbee Jun 22, 2011
0715118
Fixed the rest of the bugs with the merge.
danbee Jun 23, 2011
b033a00
Updated README file.
danbee Jun 24, 2011
446407d
Minor fix to README.
danbee Jun 24, 2011
6301549
Minor fix to README.
danbee Jun 24, 2011
89ecdab
Updated gemspec file.
danbee Jun 24, 2011
db43721
Use rails.js to submit action, fix in the get paramets to ensure siz…
rposborne Jun 28, 2011
418928f
Merge pull request #1 from rposborne/master
danbee Jul 1, 2011
33889d9
add of .rvmrc
sdesbure Jul 1, 2011
1462c32
issue with size options in the helper
sdesbure Jul 1, 2011
ed63e32
Merge branch 'release/v2.2.4'
sdesbure Jul 1, 2011
b4a2c76
Merge pull request #2 from sdesbure/master
danbee Jul 1, 2011
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pkg
doc
.DS_Store
ajaxful_rating*.gem
*.gem
1 change: 1 addition & 0 deletions .rvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
rvm 1.9.2@ajaxful_rating
5 changes: 4 additions & 1 deletion CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
== 3.0.0.beta2 August 8, 2010
* Fix dom_class and tap methods in rails.rc

== 2.2.9 Sept 30, 2010
* Released as a separate ajaxful_rating_jquery gem.

Expand Down Expand Up @@ -51,4 +54,4 @@
* Added option for showing current_user's rate instead of global average

== 2.1.0 July 25, 2009
* AjaxfulRating is now available as a gem
* AjaxfulRating is now available as a gem
28 changes: 16 additions & 12 deletions README.textile
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
h1. Ajaxful Rating jQuery

Provides a simple way to add rating functionality to your application. This fork uses jQuery instead of prototype and uses unobtrusive javascript. Currently, it only supports Rails 2.3.x.
Provides a simple way to add rating functionality to your application. This fork uses jQuery instead of prototype and uses unobtrusive javascript.

This fork is a merge of "kamui/ajaxful_rating_jquery":http://github.com/kamui/ajaxful_rating_jquery and the rails3 branch of "edgarjs/ajaxful-rating":http://github.com/edgarjs/ajaxful-rating and works on Rails 3. I've taken some care to update the documentation here but there's probably things that are missing or incorrect.

!http://s3.amazonaws.com/ember/v9SvvO3rdSkA40e1sXBf8JgpuaWCC0uB_o.png!

h2. Repository

Find it at "http://github.com/kamui/ajaxful_rating_jquery":http://github.com/kamui/ajaxful_rating_jquery
Find it at "http://github.com/danbee/ajaxful_rating_jquery":http://github.com/danbee/ajaxful_rating_jquery

The original repository, which uses Prototype, is located at "http://github.com/edgarjs/ajaxful-rating":http://github.com/edgarjs/ajaxful-rating

Expand All @@ -23,17 +25,13 @@ h2. Instructions

h3. Install

To install the gem run the next command:

@gem install ajaxful_rating_jquery@

You can configure it in your environment.rb file also:
To install the gem add it to your Gemfile:

@config.gem "ajaxful_rating_jquery"@
<pre>gem 'ajaxful_rating_jquery', :git => '[email protected]:danbee/ajaxful_rating_jquery.git'</pre>

h3. Generate

@script/generate ajaxful_rating UserModelName@
@rails g ajaxful_rating UserModelName@

The generator takes one argument: UserModelName, which is the name of your *current*
user model. This is necessary to link both the rate and user models.
Expand All @@ -44,8 +42,8 @@ Example:
_I suppose you have generated already an authenticated model..._

<pre>
script/generate authenticated user sessions
script/generate ajaxful_rating user
rails g authenticated user sessions
rails g ajaxful_rating user
</pre>

So this call will create a Rate model and will link it to your User model.
Expand Down Expand Up @@ -77,7 +75,13 @@ end
Finally, as a mere recommendation to make it even easier, modify your routes to
map a rate action:

@map.resources :cars, :member => {:rate => :post}@
<pre>
resources :cars do
member do
post :rate
end
end
</pre>

h3. Use it

Expand Down
30 changes: 18 additions & 12 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
require 'rubygems'
require 'rake'
require 'echoe'

Echoe.new('ajaxful_rating_jquery', '2.2.9') do |p|
p.summary = "Add star rating functionality to your Rails 2.3.x application. Requires jQuery."
p.description = "Provides a simple way to add rating functionality to your application. This is a fork of ajaxful_ratings that works with jQuery instead of Prototype and uses unobtrusive javascript instead of link_to_remote."
p.url = "http://github.com/kamui/ajaxful_rating_jquery"
p.author = "Jack Chu, Edgar J. Suarez"
p.email = "[email protected]"
p.ignore_pattern = ["tmp/*", "script/*"]
p.development_dependencies = []
end

Dir["#{File.dirname(__FILE__)}/tasks/*.rake"].sort.each { |ext| load ext }
begin
require 'jeweler'

Jeweler::Tasks.new do |spec|
spec.name = "ajaxful_rating"
spec.version = "3.0.0.beta3"
spec.summary = "Provides a simple way to add rating functionality to your application."
spec.description = "Provides a simple way to add rating functionality to your application."
spec.homepage = "http://github.com/edgarjs/ajaxful-rating"
spec.authors = ["Edgar J. Suarez", "Denis Odorcic"]
spec.email = ["[email protected]", "[email protected]"]
spec.has_rdoc = true
spec.files.exclude 'init.rb'
end

rescue LoadError
puts "Jeweler not available. Install it with: gem install jeweler"
end
67 changes: 55 additions & 12 deletions ajaxful_rating_jquery.gemspec
Original file line number Diff line number Diff line change
@@ -1,22 +1,64 @@
# Generated by jeweler
# DO NOT EDIT THIS FILE DIRECTLY
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
# -*- encoding: utf-8 -*-

Gem::Specification.new do |s|
s.name = %q{ajaxful_rating_jquery}
s.version = "2.2.9"
s.version = "3.0.0.beta3"

s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
s.authors = ["Jack Chu, Edgar J. Suarez"]
s.date = %q{2010-09-30}
s.description = %q{Provides a simple way to add rating functionality to your application. This is a fork of ajaxful_ratings that works with jQuery instead of Prototype and uses unobtrusive javascript instead of link_to_remote.}
s.email = %q{[email protected]}
s.extra_rdoc_files = ["CHANGELOG", "README.textile", "lib/ajaxful_rating_jquery.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"]
s.files = ["CHANGELOG", "Manifest", "README.textile", "Rakefile", "ajaxful_rating_jquery.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_medium.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_jquery.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"]
s.homepage = %q{http://github.com/kamui/ajaxful_rating_jquery}
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Ajaxful_rating_jquery", "--main", "README.textile"]
s.required_rubygems_version = Gem::Requirement.new("> 1.3.1") if s.respond_to? :required_rubygems_version=
s.authors = ["Edgar J. Suarez", "Denis Odorcic", "Dan Barber"]
s.date = %q{2011-06-24}
s.description = %q{Provides a simple way to add rating functionality to your application.}
s.email = ["[email protected]", "[email protected]", "[email protected]"]
s.extra_rdoc_files = [
"README.textile"
]
s.files = [
".gitignore",
"CHANGELOG",
"Manifest",
"README.textile",
"Rakefile",
"ajaxful_rating_jquery.gemspec",
"lib/ajaxful_rating_jquery.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",
"lib/generators/ajaxful_rating/USAGE",
"lib/generators/ajaxful_rating/ajaxful_rating_generator.rb",
"lib/generators/ajaxful_rating/templates/images/star.png",
"lib/generators/ajaxful_rating/templates/images/star_small.png",
"lib/generators/ajaxful_rating/templates/migration.rb",
"lib/generators/ajaxful_rating/templates/model.rb",
"lib/generators/ajaxful_rating/templates/style.css",
"test/fixtures/car.rb",
"test/fixtures/cars.yml",
"test/fixtures/rate.rb",
"test/fixtures/rates.yml",
"test/fixtures/schema.rb",
"test/fixtures/user.rb",
"test/fixtures/users.yml",
"test/lib/model_test.rb",
"test/test_helper.rb"
]
s.homepage = %q{http://github.com/danbee/ajaxful-rating-jquery}
s.rdoc_options = ["--charset=UTF-8"]
s.require_paths = ["lib"]
s.rubyforge_project = %q{ajaxful_rating_jquery}
s.rubygems_version = %q{1.3.7}
s.summary = %q{Add star rating functionality to your Rails 2.3.x application. Requires jQuery.}
s.summary = %q{Provides a simple way to add rating functionality to your application.}
s.test_files = [
"test/fixtures/car.rb",
"test/fixtures/rate.rb",
"test/fixtures/schema.rb",
"test/fixtures/user.rb",
"test/lib/model_test.rb",
"test/test_helper.rb"
]

if s.respond_to? :specification_version then
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
Expand All @@ -28,3 +70,4 @@ Gem::Specification.new do |s|
else
end
end

57 changes: 15 additions & 42 deletions lib/axr/helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,42 +11,13 @@ def ajaxful_rating_style
end

def ajaxful_rating_script
if protect_against_forgery?
authenticity_script = %{
csrf_param = "authenticity_token";
csrf_token = #{form_authenticity_token.inspect};

// Always send the authenticity_token with ajax
$(document).ajaxSend(function(event, request, settings) {
if ( settings.type == 'post' ) {
settings.data = (settings.data ? settings.data + "&" : "")
+ encodeURIComponent( csrf_param ) + "=" + encodeURIComponent( csrf_token );
}
});
}
end

%{<script>
#{authenticity_script}

$(document).ready(function(){
$('.ajaxful-rating a').bind('click',function(event){
event.preventDefault();
$.ajax({
type: $(this).attr('data-method'),
url: $(this).attr('href'),
data: {
stars: $(this).attr('data-stars'),
dimension: $(this).attr('data-dimension'),
size: $(this).attr('data-size'),
show_user_rating: $(this).attr('data-show_user_rating')
},
success: function(response){
$('#' + response.id + ' .show-value').css('width', response.width + '%');
}
});
});
});
%{<script>
$(document).ready(function(){
$(".ajaxful-rating a")
.bind("ajax:success", function(status, data, xhr) {
$('#' + data.id + ' .show-value').css('width', data.width + '%');
});
});
</script>}
end

Expand Down Expand Up @@ -131,16 +102,18 @@ def ajaxful_rating_script_prototype
#
# ajaxful_rating:
# helper:
# global_average: "Global rating average: {{value}} out of {{max}}"
# user_rating: "Your rating: {{value}} out of {{max}}"
# hover: "Rate {{value}} out of {{max}}" def ratings_for(*args)
# global_average: "Global rating average: %{value} out of %{max}"
# user_rating: "Your rating: %{value} out of %{max}"
# hover: "Rate %{value} out of %{max}" def ratings_for(*args)
def ratings_for(*args)
@axr_css ||= CSSBuilder.new
options = args.extract_options!.symbolize_keys.slice(:size, :url, :method,
options = args.extract_options!.to_hash.symbolize_keys.slice(:size, :remote_options,
:wrap, :show_user_rating, :dimension, :force_static, :current_user)

remote_options = options.delete(:remote_options) || {}
rateable = args.shift
user = args.shift || (respond_to?(:current_user) ? current_user : raise(NoUserSpecified))
StarsBuilder.new(rateable, user, self, @axr_css, options).render
user = args.shift || (respond_to?(:current_user) ? current_user : raise(Errors::NoUserSpecified))
StarsBuilder.new(rateable, user, self, @axr_css, options, remote_options).render
end
end
end
Expand Down
12 changes: 6 additions & 6 deletions lib/axr/locale.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ module AjaxfulRating # :nodoc:
#
# ajaxful_rating:
# helper:
# global_average: "Global rating average: {{value}} out of {{max}}"
# user_rating: "Your rating: {{value}} out of {{max}}"
# hover: "Rate {{value}} out of {{max}}"
# global_average: "Global rating average: %{value} out of %{max}"
# user_rating: "Your rating: %{value} out of %{max}"
# hover: "Rate %{value} out of %{max}"
module Locale

DEFAULTS = {
:user_rating => "Your rating: {{value}} out of {{max}}",
:global_average => "Global rating average: {{value}} out of {{max}}",
:hover => "Rate {{value}} out of {{max}}"
:user_rating => "Your rating: %{value} out of %{max}",
:global_average => "Global rating average: %{value} out of %{max}",
:hover => "Rate %{value} out of %{max}"
}

def i18n(key, value = nil)
Expand Down
14 changes: 8 additions & 6 deletions lib/axr/model.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,12 @@ def axr_config
# end
def rate(stars, user, dimension = nil)
return false if (stars.to_i > self.class.max_stars)
raise AlreadyRatedError if (!self.class.axr_config[:allow_update] && rated_by?(user, dimension))
raise Errors::AlreadyRatedError if (!self.class.axr_config[:allow_update] && rated_by?(user, dimension))

rate = if self.class.axr_config[:allow_update] && rated_by?(user, dimension)
rate_by(user, dimension)
else
returning rates(dimension).build do |r|
rates(dimension).build.tap do |r|
r.rater = user
end
end
Expand All @@ -87,16 +87,18 @@ def rate(stars, user, dimension = nil)

# Builds the DOM id attribute for the wrapper in view.
def wrapper_dom_id(options = {})
options = options.symbolize_keys.slice(:size, :dimension)
options = options.select { |k, v| v.present? or (v == false) }.map do |k, v|
options = options.to_hash.symbolize_keys.slice(:size, :dimension)
options = options.map do |k, v|
if k == :dimension
v.to_s
else
v.to_s == 'true' ? k.to_s : "no-#{k}"
end
end
options.unshift("ajaxful_rating")
ApplicationController.helpers.dom_id(self, options.sort.join('_'))
options = options.delete_if { |x| x.empty? }
prefix = "ajaxful_rating"
prefix << "_#{options.sort.join('_')}" unless options.empty?
ApplicationController.helpers.dom_id(self, prefix)
end

# Returns an array with the users that have rated this object for the
Expand Down
Loading