acts-as-taggable-on 2.0.6 → 2.4.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.
Files changed (54) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +11 -0
  3. data/.rspec +2 -0
  4. data/.travis.yml +9 -0
  5. data/CHANGELOG.md +35 -0
  6. data/Gemfile +2 -9
  7. data/Guardfile +5 -0
  8. data/{MIT-LICENSE → MIT-LICENSE.md} +1 -1
  9. data/README.md +297 -0
  10. data/Rakefile +9 -55
  11. data/UPGRADING +14 -0
  12. data/acts-as-taggable-on.gemspec +32 -0
  13. data/lib/acts-as-taggable-on/version.rb +4 -0
  14. data/lib/acts-as-taggable-on.rb +37 -4
  15. data/lib/acts_as_taggable_on/acts_as_taggable_on/cache.rb +6 -6
  16. data/lib/acts_as_taggable_on/acts_as_taggable_on/collection.rb +99 -45
  17. data/lib/acts_as_taggable_on/acts_as_taggable_on/core.rb +162 -45
  18. data/lib/acts_as_taggable_on/acts_as_taggable_on/dirty.rb +37 -0
  19. data/lib/acts_as_taggable_on/acts_as_taggable_on/ownership.rb +40 -15
  20. data/lib/acts_as_taggable_on/acts_as_taggable_on/related.rb +28 -18
  21. data/lib/acts_as_taggable_on/tag.rb +41 -16
  22. data/lib/acts_as_taggable_on/tag_list.rb +19 -14
  23. data/lib/acts_as_taggable_on/taggable.rb +102 -0
  24. data/lib/acts_as_taggable_on/{acts_as_tagger.rb → tagger.rb} +3 -3
  25. data/lib/acts_as_taggable_on/tagging.rb +12 -2
  26. data/lib/acts_as_taggable_on/tags_helper.rb +2 -2
  27. data/lib/acts_as_taggable_on/utils.rb +34 -0
  28. data/lib/generators/acts_as_taggable_on/migration/migration_generator.rb +9 -2
  29. data/lib/generators/acts_as_taggable_on/migration/templates/active_record/migration.rb +3 -1
  30. data/spec/acts_as_taggable_on/acts_as_taggable_on_spec.rb +333 -54
  31. data/spec/acts_as_taggable_on/tag_list_spec.rb +117 -61
  32. data/spec/acts_as_taggable_on/tag_spec.rb +111 -14
  33. data/spec/acts_as_taggable_on/taggable_spec.rb +330 -34
  34. data/spec/acts_as_taggable_on/tagger_spec.rb +62 -15
  35. data/spec/acts_as_taggable_on/tagging_spec.rb +2 -5
  36. data/spec/acts_as_taggable_on/tags_helper_spec.rb +16 -0
  37. data/spec/acts_as_taggable_on/utils_spec.rb +21 -0
  38. data/spec/database.yml.sample +4 -2
  39. data/spec/generators/acts_as_taggable_on/migration/migration_generator_spec.rb +22 -0
  40. data/spec/models.rb +28 -1
  41. data/spec/schema.rb +18 -0
  42. data/spec/spec_helper.rb +30 -7
  43. data/uninstall.rb +1 -0
  44. metadata +174 -57
  45. data/CHANGELOG +0 -25
  46. data/README.rdoc +0 -221
  47. data/VERSION +0 -1
  48. data/generators/acts_as_taggable_on_migration/acts_as_taggable_on_migration_generator.rb +0 -7
  49. data/generators/acts_as_taggable_on_migration/templates/migration.rb +0 -29
  50. data/lib/acts_as_taggable_on/acts_as_taggable_on.rb +0 -53
  51. data/lib/acts_as_taggable_on/compatibility/Gemfile +0 -8
  52. data/lib/acts_as_taggable_on/compatibility/active_record_backports.rb +0 -17
  53. data/lib/acts_as_taggable_on/compatibility/postgresql.rb +0 -44
  54. data/spec/database.yml +0 -17
data/README.rdoc DELETED
@@ -1,221 +0,0 @@
1
- = ActsAsTaggableOn
2
-
3
- This plugin was originally based on Acts as Taggable on Steroids by Jonathan Viney.
4
- It has evolved substantially since that point, but all credit goes to him for the
5
- initial tagging functionality that so many people have used.
6
-
7
- For instance, in a social network, a user might have tags that are called skills,
8
- interests, sports, and more. There is no real way to differentiate between tags and
9
- so an implementation of this type is not possible with acts as taggable on steroids.
10
-
11
- Enter Acts as Taggable On. Rather than tying functionality to a specific keyword
12
- (namely "tags"), acts as taggable on allows you to specify an arbitrary number of
13
- tag "contexts" that can be used locally or in combination in the same way steroids
14
- was used.
15
-
16
- == Installation
17
-
18
- === Rails 2.3.x
19
-
20
- Acts As Taggable On is tested to work in Rails 2.3.5.
21
-
22
- ==== Plugin
23
-
24
- Acts As Taggable On is available both as a gem and as a traditional plugin. For the
25
- traditional plugin you can install like so:
26
-
27
- script/plugin install git://github.com/mbleigh/acts-as-taggable-on.git
28
-
29
- Acts As Taggable On is also available as a gem plugin using Rails 2.1's gem dependencies.
30
- To install the gem, add this to your config/environment.rb:
31
-
32
- config.gem "acts-as-taggable-on", :source => "http://gemcutter.org", :version => '2.0.0.rc1'
33
-
34
- After that, you can run "rake gems:install" to install the gem if you don't already have it.
35
-
36
- ==== Post Installation
37
-
38
- 1. script/generate acts_as_taggable_on_migration
39
- 2. rake db:migrate
40
-
41
- === Rails 3.0
42
-
43
- Acts As Taggable On is now useable in Rails 3.0, thanks to the excellent work of Szymon Nowak
44
- and Jelle Vandebeeck.
45
-
46
- To use it, add it to your Gemfile:
47
-
48
- gem 'acts-as-taggable-on'
49
-
50
- ==== Post Installation
51
-
52
- 1. rails generate acts_as_taggable_on:migration
53
- 2. rake db:migrate
54
-
55
- == Testing
56
-
57
- Acts As Taggable On uses RSpec for its test coverage. Inside the plugin
58
- directory, you can run the specs for RoR 3.0.0 with:
59
-
60
- rake spec
61
-
62
- If you want to test the plugin for Rails 2.3.x, use:
63
-
64
- rake rails2.3:spec
65
-
66
- If you already have RSpec on your application, the specs will run while using:
67
-
68
- rake spec:plugins
69
-
70
-
71
- == Usage
72
-
73
- class User < ActiveRecord::Base
74
- # Alias for <tt>acts_as_taggable_on :tags</tt>:
75
- acts_as_taggable
76
- acts_as_taggable_on :skills, :interests
77
- end
78
-
79
- @user = User.new(:name => "Bobby")
80
- @user.tag_list = "awesome, slick, hefty" # this should be familiar
81
- @user.skill_list = "joking, clowning, boxing" # but you can do it for any context!
82
- @user.skill_list # => ["joking","clowning","boxing"] as TagList
83
- @user.save
84
-
85
- @user.tags # => [<Tag name:"awesome">,<Tag name:"slick">,<Tag name:"hefty">]
86
- @user.skills # => [<Tag name:"joking">,<Tag name:"clowning">,<Tag name:"boxing">]
87
-
88
- @frankie = User.create(:name => "Frankie", :skill_list => "joking, flying, eating")
89
- User.skill_counts # => [<Tag name="joking" count=2>,<Tag name="clowning" count=1>...]
90
- @frankie.skill_counts
91
-
92
- === Finding Tagged Objects
93
-
94
- Acts As Taggable On utilizes named_scopes to create an association for tags.
95
- This way you can mix and match to filter down your results, and it also improves
96
- compatibility with the will_paginate gem:
97
-
98
- class User < ActiveRecord::Base
99
- acts_as_taggable_on :tags
100
- named_scope :by_join_date, :order => "created_at DESC"
101
- end
102
-
103
- User.tagged_with("awesome").by_date
104
- User.tagged_with("awesome").by_date.paginate(:page => params[:page], :per_page => 20)
105
-
106
- # Find a user with matching all tags, not just one
107
- User.tagged_with(["awesome", "cool"], :match_all => :true)
108
-
109
- # Find a user with any of the tags:
110
- User.tagged_with(["awesome", "cool"], :any => true)
111
-
112
- === Relationships
113
-
114
- You can find objects of the same type based on similar tags on certain contexts.
115
- Also, objects will be returned in descending order based on the total number of
116
- matched tags.
117
-
118
- @bobby = User.find_by_name("Bobby")
119
- @bobby.skill_list # => ["jogging", "diving"]
120
-
121
- @frankie = User.find_by_name("Frankie")
122
- @frankie.skill_list # => ["hacking"]
123
-
124
- @tom = User.find_by_name("Tom")
125
- @tom.skill_list # => ["hacking", "jogging", "diving"]
126
-
127
- @tom.find_related_skills # => [<User name="Bobby">,<User name="Frankie">]
128
- @bobby.find_related_skills # => [<User name="Tom">]
129
- @frankie.find_related_skills # => [<User name="Tom">]
130
-
131
- === Dynamic Tag Contexts
132
-
133
- In addition to the generated tag contexts in the definition, it is also possible
134
- to allow for dynamic tag contexts (this could be user generated tag contexts!)
135
-
136
- @user = User.new(:name => "Bobby")
137
- @user.set_tag_list_on(:customs, "same, as, tag, list")
138
- @user.tag_list_on(:customs) # => ["same","as","tag","list"]
139
- @user.save
140
- @user.tags_on(:customs) # => [<Tag name='same'>,...]
141
- @user.tag_counts_on(:customs)
142
- User.tagged_with("same", :on => :customs) # => [@user]
143
-
144
- === Tag Ownership
145
-
146
- Tags can have owners:
147
-
148
- class User < ActiveRecord::Base
149
- acts_as_tagger
150
- end
151
-
152
- class Photo < ActiveRecord::Base
153
- acts_as_taggable_on :locations
154
- end
155
-
156
- @some_user.tag(@some_photo, :with => "paris, normandy", :on => :locations)
157
- @some_user.owned_taggings
158
- @some_user.owned_tags
159
- @some_photo.locations_from(@some_user)
160
-
161
- === Tag cloud calculations
162
-
163
- To construct tag clouds, the frequency of each tag needs to be calculated.
164
- Because we specified +acts_as_taggable_on+ on the <tt>User</tt> class, we can
165
- get a calculation of all the tag counts by using <tt>User.tag_counts_on(:customs)</tt>. But what if we wanted a tag count for
166
- an single user's posts? To achieve this we call tag_counts on the association:
167
-
168
- User.find(:first).posts.tag_counts_on(:tags)
169
-
170
- A helper is included to assist with generating tag clouds.
171
-
172
- Here is an example that generates a tag cloud.
173
-
174
- Helper:
175
-
176
- module PostsHelper
177
- include ActsAsTaggableOn::TagsHelper
178
- end
179
-
180
- Controller:
181
-
182
- class PostController < ApplicationController
183
- def tag_cloud
184
- @tags = Post.tag_counts_on(:tags)
185
- end
186
- end
187
-
188
- View:
189
-
190
- <% tag_cloud(@tags, %w(css1 css2 css3 css4)) do |tag, css_class| %>
191
- <%= link_to tag.name, { :action => :tag, :id => tag.name }, :class => css_class %>
192
- <% end %>
193
-
194
- CSS:
195
-
196
- .css1 { font-size: 1.0em; }
197
- .css2 { font-size: 1.2em; }
198
- .css3 { font-size: 1.4em; }
199
- .css4 { font-size: 1.6em; }
200
-
201
- == Contributors
202
-
203
- * TomEric (i76) - Maintainer
204
- * Michael Bleigh - Original Author
205
- * Szymon Nowak - Rails 3.0 compatibility
206
- * Jelle Vandebeeck - Rails 3.0 compatibility
207
- * Brendan Lim - Related Objects
208
- * Pradeep Elankumaran - Taggers
209
- * Sinclair Bain - Patch King
210
-
211
- === Patch Contributors
212
-
213
- * tristanzdunn - Related objects of other classes
214
- * azabaj - Fixed migrate down
215
- * Peter Cooper - named_scope fix
216
- * slainer68 - STI fix
217
- * harrylove - migration instructions and fix-ups
218
- * lawrencepit - cached tag work
219
- * sobrinho - fixed tag_cloud helper
220
-
221
- Copyright (c) 2007-2010 Michael Bleigh (http://mbleigh.com/) and Intridea Inc. (http://intridea.com/), released under the MIT license
data/VERSION DELETED
@@ -1 +0,0 @@
1
- 2.0.6
@@ -1,7 +0,0 @@
1
- class ActsAsTaggableOnMigrationGenerator < Rails::Generator::Base
2
- def manifest
3
- record do |m|
4
- m.migration_template 'migration.rb', 'db/migrate', :migration_file_name => "acts_as_taggable_on_migration"
5
- end
6
- end
7
- end
@@ -1,29 +0,0 @@
1
- class ActsAsTaggableOnMigration < ActiveRecord::Migration
2
- def self.up
3
- create_table :tags do |t|
4
- t.column :name, :string
5
- end
6
-
7
- create_table :taggings do |t|
8
- t.column :tag_id, :integer
9
- t.column :taggable_id, :integer
10
- t.column :tagger_id, :integer
11
- t.column :tagger_type, :string
12
-
13
- # You should make sure that the column created is
14
- # long enough to store the required class names.
15
- t.column :taggable_type, :string
16
- t.column :context, :string
17
-
18
- t.column :created_at, :datetime
19
- end
20
-
21
- add_index :taggings, :tag_id
22
- add_index :taggings, [:taggable_id, :taggable_type, :context]
23
- end
24
-
25
- def self.down
26
- drop_table :taggings
27
- drop_table :tags
28
- end
29
- end
@@ -1,53 +0,0 @@
1
- module ActsAsTaggableOn
2
- module Taggable
3
- def taggable?
4
- false
5
- end
6
-
7
- ##
8
- # This is an alias for calling <tt>acts_as_taggable_on :tags</tt>.
9
- #
10
- # Example:
11
- # class Book < ActiveRecord::Base
12
- # acts_as_taggable
13
- # end
14
- def acts_as_taggable
15
- acts_as_taggable_on :tags
16
- end
17
-
18
- ##
19
- # Make a model taggable on specified contexts.
20
- #
21
- # @param [Array] tag_types An array of taggable contexts
22
- #
23
- # Example:
24
- # class User < ActiveRecord::Base
25
- # acts_as_taggable_on :languages, :skills
26
- # end
27
- def acts_as_taggable_on(*tag_types)
28
- tag_types = tag_types.to_a.flatten.compact.map(&:to_sym)
29
-
30
- if taggable?
31
- write_inheritable_attribute(:tag_types, (self.tag_types + tag_types).uniq)
32
- else
33
- write_inheritable_attribute(:tag_types, tag_types)
34
- class_inheritable_reader(:tag_types)
35
-
36
- class_eval do
37
- has_many :taggings, :as => :taggable, :dependent => :destroy, :include => :tag, :class_name => "ActsAsTaggableOn::Tagging"
38
- has_many :base_tags, :through => :taggings, :source => :tag, :class_name => "ActsAsTaggableOn::Tag"
39
-
40
- def self.taggable?
41
- true
42
- end
43
-
44
- include ActsAsTaggableOn::Taggable::Core
45
- include ActsAsTaggableOn::Taggable::Collection
46
- include ActsAsTaggableOn::Taggable::Cache
47
- include ActsAsTaggableOn::Taggable::Ownership
48
- include ActsAsTaggableOn::Taggable::Related
49
- end
50
- end
51
- end
52
- end
53
- end
@@ -1,8 +0,0 @@
1
- source :gemcutter
2
-
3
- # Rails 2.3
4
- gem 'rails', '2.3.5'
5
- gem 'rspec', '1.3.0', :require => 'spec'
6
- gem 'sqlite3-ruby', '1.2.5', :require => 'sqlite3'
7
- gem 'mysql'
8
- gem 'pg'
@@ -1,17 +0,0 @@
1
- module ActsAsTaggableOn
2
- module ActiveRecord
3
- module Backports
4
- def self.included(base)
5
- base.class_eval do
6
- named_scope :where, lambda { |conditions| { :conditions => conditions } }
7
- named_scope :joins, lambda { |joins| { :joins => joins } }
8
- named_scope :group, lambda { |group| { :group => group } }
9
- named_scope :order, lambda { |order| { :order => order } }
10
- named_scope :select, lambda { |select| { :select => select } }
11
- named_scope :limit, lambda { |limit| { :limit => limit } }
12
- named_scope :readonly, lambda { |readonly| { :readonly => readonly } }
13
- end
14
- end
15
- end
16
- end
17
- end
@@ -1,44 +0,0 @@
1
- module ActsAsTaggableOn
2
- module Taggable
3
- module PostgreSQL
4
- def self.included(base)
5
- base.send :include, ActsAsTaggableOn::Taggable::PostgreSQL::InstanceMethods
6
- base.extend ActsAsTaggableOn::Taggable::PostgreSQL::ClassMethods
7
-
8
- ActsAsTaggableOn::Tag.class_eval do
9
- def self.named(name)
10
- where(["name ILIKE ?", name])
11
- end
12
-
13
- def self.named_any(list)
14
- where(list.map { |tag| sanitize_sql(["name ILIKE ?", tag.to_s]) }.join(" OR "))
15
- end
16
-
17
- def self.named_like(name)
18
- where(["name ILIKE ?", "%#{name}%"])
19
- end
20
-
21
- def self.named_like_any(list)
22
- where(list.map { |tag| sanitize_sql(["name ILIKE ?", "%#{tag.to_s}%"]) }.join(" OR "))
23
- end
24
- end
25
- end
26
-
27
- module InstanceMethods
28
- end
29
-
30
- module ClassMethods
31
- # all column names are necessary for PostgreSQL group clause
32
- def grouped_column_names_for(*objects)
33
- object = objects.shift
34
- columns = object.column_names.map { |column| "#{object.table_name}.#{column}" }
35
- columns << objects.map do |object|
36
- "#{object.table_name}.created_at"
37
- end.flatten
38
-
39
- columns.flatten.join(", ")
40
- end
41
- end
42
- end
43
- end
44
- end
data/spec/database.yml DELETED
@@ -1,17 +0,0 @@
1
- sqlite3:
2
- adapter: sqlite3
3
- database: acts_as_taggable_on.sqlite3
4
-
5
- mysql:
6
- adapter: mysql
7
- hostname: localhost
8
- username: root
9
- password:
10
- database: acts_as_taggable_on
11
-
12
- postgresql:
13
- adapter: postgresql
14
- hostname: localhost
15
- username: postgres
16
- password:
17
- database: acts_as_taggable_on