rateme 0.1.0

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/.rvmrc ADDED
@@ -0,0 +1 @@
1
+ rvm use ruby-1.9.3-p125@rateme --create
data/.travis.yml ADDED
@@ -0,0 +1,2 @@
1
+ rvm:
2
+ - 1.9.3
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ source 'http://rubygems.org'
2
+
3
+ group :development do
4
+ gem 'redcarpet', '~> 2.1.0'
5
+ gem 'yard', '~> 0.7.5'
6
+ gem 'jeweler', '~> 1.8.3'
7
+ end
8
+
data/Gemfile.lock ADDED
@@ -0,0 +1,23 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ git (1.2.5)
5
+ jeweler (1.8.3)
6
+ bundler (~> 1.0)
7
+ git (>= 1.2.5)
8
+ rake
9
+ rdoc
10
+ json (1.6.5)
11
+ rake (0.9.2.2)
12
+ rdoc (3.12)
13
+ json (~> 1.4)
14
+ redcarpet (2.1.0)
15
+ yard (0.7.5)
16
+
17
+ PLATFORMS
18
+ ruby
19
+
20
+ DEPENDENCIES
21
+ jeweler (~> 1.8.3)
22
+ redcarpet (~> 2.1.0)
23
+ yard (~> 0.7.5)
data/LICENSE.md ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2012 Thomas Boerger <http://www.tbpro.de>
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,17 @@
1
+ # Rateme [![Build Status](https://secure.travis-ci.org/tbpro/rateme.pmg)](https://secure.travis-ci.org/tbpro/rateme)
2
+
3
+ ## Install
4
+
5
+ ```ruby
6
+ gem 'rateme'
7
+ ```
8
+
9
+ ## Usage
10
+
11
+ ```ruby
12
+ ```
13
+
14
+ ## Credits
15
+
16
+ Copyright (c) 2012 Thomas Boerger <http://www.tbpro.de>
17
+
data/Rakefile ADDED
@@ -0,0 +1,33 @@
1
+ require 'rubygems'
2
+
3
+ begin
4
+ require 'bundler'
5
+ Bundler.setup(:default, :development)
6
+ rescue Bundler::BundlerError => e
7
+ $stderr.puts e.message
8
+ $stderr.puts 'Run `bundle install` to install missing gems'
9
+ exit e.status_code
10
+ end
11
+
12
+ require 'rake'
13
+ require 'jeweler'
14
+ require 'yard'
15
+
16
+ $:.push File.expand_path('../lib', __FILE__)
17
+ require 'rateme/version'
18
+
19
+ Jeweler::Tasks.new do |gem|
20
+ gem.name = 'rateme'
21
+ gem.version = Rateme::Version::STRING
22
+ gem.homepage = 'https://github.com/tbpro/rateme'
23
+ gem.license = 'MIT'
24
+ gem.summary = %Q{Rateme is a simple rating plugin for active record}
25
+ gem.email = 'tboerger@tbpro.de'
26
+ gem.authors = ['Thomas Boerger']
27
+ end
28
+
29
+ Jeweler::RubygemsDotOrgTasks.new
30
+ YARD::Rake::YardocTask.new
31
+
32
+ task :default => :version
33
+
@@ -0,0 +1,16 @@
1
+ <div class="rating rating-star">
2
+ <ul class="star<%= record.rating.round.to_i %>">
3
+ <% record.rating_range.map do |i| -%>
4
+ <li class="star<%= i %>">
5
+ <%= link_to i, send(route, record, i) %>
6
+ </li>
7
+ <% end -%>
8
+ </ul>
9
+ </div>
10
+
11
+ <div class="rating rating-text">
12
+ <%= record.ratings.count %> Bewertungen
13
+ </div>
14
+
15
+ <%= image_tag "/images/spinner.gif", :class => "rating rating-load", :style => "display: none;" %>
16
+
data/init.rb ADDED
@@ -0,0 +1 @@
1
+ require 'rateme'
File without changes
@@ -0,0 +1,46 @@
1
+ require 'rails/generators/migration'
2
+ require 'rails/generators/active_record'
3
+
4
+ class RatemeGenerator < Rails::Generators::Base
5
+ include Rails::Generators::Migration
6
+ source_root File.expand_path('../templates', __FILE__)
7
+
8
+ class_option :migration,
9
+ :type => :boolean,
10
+ :default => true,
11
+ :description => "Generate a migration file for this model"
12
+
13
+ class_option :stylesheet,
14
+ :type => :boolean,
15
+ :default => true,
16
+ :description => "Generate the images, stylesheet and javascript"
17
+
18
+ def self.next_migration_number(path)
19
+ ActiveRecord::Generators::Base.next_migration_number(path)
20
+ end
21
+
22
+ def generate_layout
23
+ template "model.rb",
24
+ "app/models/rating.rb"
25
+
26
+ if options.migration?
27
+ migration_template "migration.rb",
28
+ "db/migrate/create_ratings.rb"
29
+ end
30
+
31
+ if options.stylesheet?
32
+ copy_file "stylesheet.css",
33
+ "public/stylesheets/rateme.css"
34
+
35
+ copy_file "javascript.js",
36
+ "public/javascripts/rateme.js"
37
+
38
+ copy_file "stars.gif",
39
+ "public/images/stars.gif"
40
+
41
+ copy_file "spinner.gif",
42
+ "public/images/spinner.gif"
43
+ end
44
+ end
45
+ end
46
+
@@ -0,0 +1,15 @@
1
+ class CreateRatings < ActiveRecord::Migration
2
+ def self.up
3
+ create_table :ratings, :force => true do |t|
4
+ t.belongs_to :rateable, :polymorphic => true
5
+ t.integer :value, :default => 0
6
+ t.string :ip_address
7
+ t.timestamps
8
+ end
9
+ end
10
+
11
+ def self.down
12
+ drop_table :ratings
13
+ end
14
+ end
15
+
@@ -0,0 +1,32 @@
1
+ class Rating < ActiveRecord::Base
2
+ belongs_to :rateable, :polymorphic => true
3
+
4
+ validates_presence_of :rateable_type, :rateable_id
5
+ validates_numericality_of :value
6
+ validate :maximum_value_is_not_breached
7
+
8
+ before_save :delete_last_rating
9
+
10
+ def self.find_similar(rating)
11
+ Rating.find(
12
+ :first,
13
+ :conditions => {
14
+ :ip_address => rating.ip_address,
15
+ :rateable_id => rating.rateable_id,
16
+ :rateable_type => rating.rateable_type
17
+ }
18
+ )
19
+ end
20
+
21
+ protected
22
+ def maximum_value_is_not_breached
23
+ errors.add('value', 'is not in the range') unless rateable.rating_range.include?(value)
24
+ end
25
+
26
+ def delete_last_rating
27
+ if (rating = Rating.find_similar(self))
28
+ rating.destroy
29
+ end
30
+ end
31
+ end
32
+
@@ -0,0 +1,104 @@
1
+ div.rating {
2
+ float: left;
3
+ }
4
+
5
+ div.rating-star {
6
+ width: 80px;
7
+ height: 16px;
8
+ margin: 0;
9
+ padding: 0;
10
+ list-style: none !important;
11
+ clear: both;
12
+ position: relative;
13
+ background: url(/images/stars.gif) no-repeat 0 0;
14
+ }
15
+
16
+ div.rating-star ul.star0 {
17
+ background-position: 0 0
18
+ }
19
+
20
+ div.rating-star ul.star1 {
21
+ background-position: 0 -16px
22
+ }
23
+
24
+ div.rating-star ul.star2 {
25
+ background-position: 0 -32px
26
+ }
27
+
28
+ div.rating-star ul.star3 {
29
+ background-position: 0 -48px
30
+ }
31
+
32
+ div.rating-star ul.star4 {
33
+ background-position: 0 -64px
34
+ }
35
+
36
+ div.rating-star ul.star5 {
37
+ background-position: 0 -80px
38
+ }
39
+
40
+ div.rating-star ul li {
41
+ cursor: pointer;
42
+ float: left;
43
+ text-indent: -999em;
44
+ }
45
+
46
+ div.rating-star li a {
47
+ position: absolute;
48
+ left: 0;
49
+ top: 0;
50
+ width: 16px;
51
+ height: 16px;
52
+ text-decoration: none;
53
+ z-index: 200;
54
+ }
55
+
56
+ div.rating-star li a:hover {
57
+ z-index: 2;
58
+ width: 80px;
59
+ height: 16px;
60
+ overflow: hidden;
61
+ left: 0;
62
+ background: url(/images/stars.gif) no-repeat 0 0
63
+ }
64
+
65
+ div.rating-star li.star1 a {
66
+ left: 0
67
+ }
68
+
69
+ div.rating-star li.star2 a {
70
+ left: 16px;
71
+ }
72
+
73
+ div.rating-star li.star3 a {
74
+ left: 32px;
75
+ }
76
+
77
+ div.rating-star li.star4 a {
78
+ left: 48px;
79
+ }
80
+
81
+ div.rating-star li.star5 a {
82
+ left: 64px;
83
+ }
84
+
85
+ div.rating-star li.star1 a:hover {
86
+ background-position: 0 -96px;
87
+ }
88
+
89
+ div.rating-star li.star2 a:hover {
90
+ background-position: 0 -112px;
91
+ }
92
+
93
+ div.rating-star li.star3 a:hover {
94
+ background-position: 0 -128px;
95
+ }
96
+
97
+ div.rating-star li.star4 a:hover {
98
+ background-position: 0 -144px;
99
+ }
100
+
101
+ div.rating-star li.star5 a:hover {
102
+ background-position: 0 -160px;
103
+ }
104
+
data/lib/rateme.rb ADDED
@@ -0,0 +1,8 @@
1
+ module Rateme
2
+ autoload :Version, 'rateme/version'
3
+ autoload :Macros, 'rateme/macros'
4
+ autoload :Helper, 'rateme/helper'
5
+ end
6
+
7
+ require 'rateme/railtie' if defined? Rails
8
+
@@ -0,0 +1,15 @@
1
+ module Rateme
2
+ module Helper
3
+ extend ActiveSupport::Concern
4
+
5
+ included do
6
+ def render_rating(record, route)
7
+ render :partial => 'rateme/rating', :locals => { :record => record, :route => route }
8
+ end
9
+ end
10
+
11
+ module ClassMethods
12
+ end
13
+ end
14
+ end
15
+
@@ -0,0 +1,41 @@
1
+ module Rateme
2
+ module Macros
3
+ extend ActiveSupport::Concern
4
+
5
+ included do
6
+ end
7
+
8
+ module ClassMethods
9
+ def rateme(options = {})
10
+ include RequiredMethods
11
+
12
+ has_many :ratings, :as => :rateable
13
+
14
+ cattr_accessor :minimum_rating_allowed
15
+ cattr_accessor :maximum_rating_allowed
16
+
17
+ self.minimum_rating_allowed = options[:from] || 1
18
+ self.maximum_rating_allowed = options[:upto] || 5
19
+ end
20
+ end
21
+
22
+ module RequiredMethods
23
+ def rating
24
+ if (rating = ratings.average(:value))
25
+ rating
26
+ else
27
+ 0.to_f
28
+ end
29
+ end
30
+
31
+ def rate(value, options = {})
32
+ ratings.create(options.merge({ :value => value }))
33
+ end
34
+
35
+ def rating_range
36
+ minimum_rating_allowed..maximum_rating_allowed
37
+ end
38
+ end
39
+ end
40
+ end
41
+
@@ -0,0 +1,12 @@
1
+ module Rateme
2
+ class Railtie < Rails::Railtie
3
+ ActiveSupport.on_load(:action_view) do
4
+ include Rateme::Helper
5
+ end
6
+
7
+ ActiveSupport.on_load(:active_record) do
8
+ include Rateme::Macros
9
+ end
10
+ end
11
+ end
12
+
@@ -0,0 +1,11 @@
1
+ module Rateme
2
+ module Version
3
+ MAJOR = 0
4
+ MINOR = 1
5
+ PATCH = 0
6
+ BUILD = nil
7
+
8
+ STRING = [MAJOR, MINOR, PATCH, BUILD].compact.join('.')
9
+ end
10
+ end
11
+
data/rateme.gemspec ADDED
@@ -0,0 +1,67 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = "rateme"
8
+ s.version = "0.1.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Thomas Boerger"]
12
+ s.date = "2012-06-14"
13
+ s.email = "tboerger@tbpro.de"
14
+ s.extra_rdoc_files = [
15
+ "LICENSE.md",
16
+ "README.md"
17
+ ]
18
+ s.files = [
19
+ ".rvmrc",
20
+ ".travis.yml",
21
+ "Gemfile",
22
+ "Gemfile.lock",
23
+ "LICENSE.md",
24
+ "README.md",
25
+ "Rakefile",
26
+ "app/views/rateme/_rating.html.erb",
27
+ "init.rb",
28
+ "lib/generators/rateme/USAGE",
29
+ "lib/generators/rateme/rateme_generator.rb",
30
+ "lib/generators/rateme/templates/javascript.js",
31
+ "lib/generators/rateme/templates/migration.rb",
32
+ "lib/generators/rateme/templates/model.rb",
33
+ "lib/generators/rateme/templates/spinner.gif",
34
+ "lib/generators/rateme/templates/stars.gif",
35
+ "lib/generators/rateme/templates/stylesheet.css",
36
+ "lib/rateme.rb",
37
+ "lib/rateme/helper.rb",
38
+ "lib/rateme/macros.rb",
39
+ "lib/rateme/railtie.rb",
40
+ "lib/rateme/version.rb",
41
+ "rateme.gemspec"
42
+ ]
43
+ s.homepage = "https://github.com/tbpro/rateme"
44
+ s.licenses = ["MIT"]
45
+ s.require_paths = ["lib"]
46
+ s.rubygems_version = "1.8.23"
47
+ s.summary = "Rateme is a simple rating plugin for active record"
48
+
49
+ if s.respond_to? :specification_version then
50
+ s.specification_version = 3
51
+
52
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
53
+ s.add_development_dependency(%q<redcarpet>, ["~> 2.1.0"])
54
+ s.add_development_dependency(%q<yard>, ["~> 0.7.5"])
55
+ s.add_development_dependency(%q<jeweler>, ["~> 1.8.3"])
56
+ else
57
+ s.add_dependency(%q<redcarpet>, ["~> 2.1.0"])
58
+ s.add_dependency(%q<yard>, ["~> 0.7.5"])
59
+ s.add_dependency(%q<jeweler>, ["~> 1.8.3"])
60
+ end
61
+ else
62
+ s.add_dependency(%q<redcarpet>, ["~> 2.1.0"])
63
+ s.add_dependency(%q<yard>, ["~> 0.7.5"])
64
+ s.add_dependency(%q<jeweler>, ["~> 1.8.3"])
65
+ end
66
+ end
67
+
metadata ADDED
@@ -0,0 +1,121 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rateme
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Thomas Boerger
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-06-14 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: redcarpet
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 2.1.0
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: 2.1.0
30
+ - !ruby/object:Gem::Dependency
31
+ name: yard
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: 0.7.5
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: 0.7.5
46
+ - !ruby/object:Gem::Dependency
47
+ name: jeweler
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ version: 1.8.3
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: 1.8.3
62
+ description:
63
+ email: tboerger@tbpro.de
64
+ executables: []
65
+ extensions: []
66
+ extra_rdoc_files:
67
+ - LICENSE.md
68
+ - README.md
69
+ files:
70
+ - .rvmrc
71
+ - .travis.yml
72
+ - Gemfile
73
+ - Gemfile.lock
74
+ - LICENSE.md
75
+ - README.md
76
+ - Rakefile
77
+ - app/views/rateme/_rating.html.erb
78
+ - init.rb
79
+ - lib/generators/rateme/USAGE
80
+ - lib/generators/rateme/rateme_generator.rb
81
+ - lib/generators/rateme/templates/javascript.js
82
+ - lib/generators/rateme/templates/migration.rb
83
+ - lib/generators/rateme/templates/model.rb
84
+ - lib/generators/rateme/templates/spinner.gif
85
+ - lib/generators/rateme/templates/stars.gif
86
+ - lib/generators/rateme/templates/stylesheet.css
87
+ - lib/rateme.rb
88
+ - lib/rateme/helper.rb
89
+ - lib/rateme/macros.rb
90
+ - lib/rateme/railtie.rb
91
+ - lib/rateme/version.rb
92
+ - rateme.gemspec
93
+ homepage: https://github.com/tbpro/rateme
94
+ licenses:
95
+ - MIT
96
+ post_install_message:
97
+ rdoc_options: []
98
+ require_paths:
99
+ - lib
100
+ required_ruby_version: !ruby/object:Gem::Requirement
101
+ none: false
102
+ requirements:
103
+ - - ! '>='
104
+ - !ruby/object:Gem::Version
105
+ version: '0'
106
+ segments:
107
+ - 0
108
+ hash: 3172530871267540312
109
+ required_rubygems_version: !ruby/object:Gem::Requirement
110
+ none: false
111
+ requirements:
112
+ - - ! '>='
113
+ - !ruby/object:Gem::Version
114
+ version: '0'
115
+ requirements: []
116
+ rubyforge_project:
117
+ rubygems_version: 1.8.23
118
+ signing_key:
119
+ specification_version: 3
120
+ summary: Rateme is a simple rating plugin for active record
121
+ test_files: []