crowdint_acts-as-taggable-on 2.3.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (45) hide show
  1. data/.gitignore +10 -0
  2. data/.rspec +2 -0
  3. data/.travis.yml +9 -0
  4. data/CHANGELOG +35 -0
  5. data/Gemfile +3 -0
  6. data/Guardfile +5 -0
  7. data/MIT-LICENSE +20 -0
  8. data/README.rdoc +250 -0
  9. data/Rakefile +13 -0
  10. data/acts-as-taggable-on.gemspec +28 -0
  11. data/lib/acts-as-taggable-on.rb +59 -0
  12. data/lib/acts-as-taggable-on/version.rb +4 -0
  13. data/lib/acts_as_taggable_on/acts_as_taggable_on/cache.rb +53 -0
  14. data/lib/acts_as_taggable_on/acts_as_taggable_on/collection.rb +127 -0
  15. data/lib/acts_as_taggable_on/acts_as_taggable_on/core.rb +349 -0
  16. data/lib/acts_as_taggable_on/acts_as_taggable_on/dirty.rb +37 -0
  17. data/lib/acts_as_taggable_on/acts_as_taggable_on/ownership.rb +99 -0
  18. data/lib/acts_as_taggable_on/acts_as_taggable_on/related.rb +73 -0
  19. data/lib/acts_as_taggable_on/tag.rb +77 -0
  20. data/lib/acts_as_taggable_on/tag_list.rb +97 -0
  21. data/lib/acts_as_taggable_on/taggable.rb +102 -0
  22. data/lib/acts_as_taggable_on/tagger.rb +67 -0
  23. data/lib/acts_as_taggable_on/tagging.rb +34 -0
  24. data/lib/acts_as_taggable_on/tags_helper.rb +17 -0
  25. data/lib/acts_as_taggable_on/utils.rb +34 -0
  26. data/lib/generators/acts_as_taggable_on/migration/migration_generator.rb +39 -0
  27. data/lib/generators/acts_as_taggable_on/migration/templates/active_record/migration.rb +30 -0
  28. data/rails/init.rb +1 -0
  29. data/spec/acts_as_taggable_on/acts_as_taggable_on_spec.rb +514 -0
  30. data/spec/acts_as_taggable_on/acts_as_tagger_spec.rb +114 -0
  31. data/spec/acts_as_taggable_on/tag_list_spec.rb +93 -0
  32. data/spec/acts_as_taggable_on/tag_spec.rb +153 -0
  33. data/spec/acts_as_taggable_on/taggable_spec.rb +543 -0
  34. data/spec/acts_as_taggable_on/tagger_spec.rb +112 -0
  35. data/spec/acts_as_taggable_on/tagging_spec.rb +28 -0
  36. data/spec/acts_as_taggable_on/tags_helper_spec.rb +44 -0
  37. data/spec/acts_as_taggable_on/utils_spec.rb +21 -0
  38. data/spec/bm.rb +52 -0
  39. data/spec/database.yml.sample +19 -0
  40. data/spec/generators/acts_as_taggable_on/migration/migration_generator_spec.rb +22 -0
  41. data/spec/models.rb +49 -0
  42. data/spec/schema.rb +61 -0
  43. data/spec/spec_helper.rb +83 -0
  44. data/uninstall.rb +1 -0
  45. metadata +240 -0
data/.gitignore ADDED
@@ -0,0 +1,10 @@
1
+ *.log
2
+ *.sqlite3
3
+ /pkg/*
4
+ .bundle
5
+ .rvmrc
6
+ Gemfile.lock
7
+ spec/database.yml
8
+ tmp*.sw?
9
+ *.sw?
10
+ tmp
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --colour
2
+ --backtrace
data/.travis.yml ADDED
@@ -0,0 +1,9 @@
1
+ script: "cp spec/database.yml.sample spec/database.yml && bundle install && bundle exec rake"
2
+ rvm:
3
+ - 1.8.7
4
+ - 1.9.2
5
+ - 1.9.3
6
+ env:
7
+ - DB=sqlite3
8
+ - DB=mysql
9
+ - DB=postgresql
data/CHANGELOG ADDED
@@ -0,0 +1,35 @@
1
+ == 2011-08-21
2
+ * escape _ and % for mysql and postgres (@tilsammans)
3
+ * Now depends on mysql2 gem
4
+ * tagged_with :any is chainable now (@jeffreyiacono)
5
+ * tagged_with(nil) returns scoped object
6
+ * Case-insensitivity for TaggedModel.tagged_with for PostgreSQL database
7
+ * tagged_with(' ') returns scoped object
8
+ * remove warning for rails 3.1 about class_inheritable_attribute
9
+ * use ActiveRecord migration_number to avoid clashs (@atd)
10
+
11
+ == 2010-02-17
12
+ * Converted the plugin to be compatible with Rails3
13
+
14
+ == 2009-12-02
15
+
16
+ * PostgreSQL is now supported (via morgoth)
17
+
18
+ == 2008-07-17
19
+
20
+ * Can now use a named_scope to find tags!
21
+
22
+ == 2008-06-23
23
+
24
+ * Can now find related objects of another class (tristanzdunn)
25
+ * Removed extraneous down migration cruft (azabaj)
26
+
27
+ == 2008-06-09
28
+
29
+ * Added support for Single Table Inheritance
30
+ * Adding gemspec and rails/init.rb for gemified plugin
31
+
32
+ == 2007-12-12
33
+
34
+ * Added ability to use dynamic tag contexts
35
+ * Fixed missing migration generator
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'http://rubygems.org'
2
+ gemspec
3
+
data/Guardfile ADDED
@@ -0,0 +1,5 @@
1
+ guard 'rspec' do
2
+ watch(%r{^spec/.+_spec\.rb})
3
+ watch(%r{^lib/(.+)\.rb}) { |m| "spec/lib/#{m[1]}_spec.rb" }
4
+ watch('spec/spec_helper.rb') { "spec" }
5
+ end
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2007 Michael Bleigh and Intridea Inc.
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.rdoc ADDED
@@ -0,0 +1,250 @@
1
+ = Changed in this fork:
2
+
3
+ - The save_owned_tags method was modified in order to avoid old_tags deletion when updating the user owned_tags
4
+
5
+ -------------------------------------
6
+
7
+ = ActsAsTaggableOn
8
+ {<img src="https://secure.travis-ci.org/mbleigh/acts-as-taggable-on.png" />}[http://travis-ci.org/mbleigh/acts-as-taggable-on]
9
+
10
+ This plugin was originally based on Acts as Taggable on Steroids by Jonathan Viney.
11
+ It has evolved substantially since that point, but all credit goes to him for the
12
+ initial tagging functionality that so many people have used.
13
+
14
+ For instance, in a social network, a user might have tags that are called skills,
15
+ interests, sports, and more. There is no real way to differentiate between tags and
16
+ so an implementation of this type is not possible with acts as taggable on steroids.
17
+
18
+ Enter Acts as Taggable On. Rather than tying functionality to a specific keyword
19
+ (namely "tags"), acts as taggable on allows you to specify an arbitrary number of
20
+ tag "contexts" that can be used locally or in combination in the same way steroids
21
+ was used.
22
+
23
+ == Installation
24
+
25
+ === Rails 2.x
26
+
27
+ Not supported any more! It is time for update guys.
28
+
29
+ === Rails 3.x
30
+
31
+ To use it, add it to your Gemfile:
32
+
33
+ gem 'acts-as-taggable-on', '~> 2.3.1'
34
+
35
+ ==== Post Installation
36
+
37
+ 1. rails generate acts_as_taggable_on:migration
38
+ 2. rake db:migrate
39
+
40
+ == Testing
41
+
42
+ Acts As Taggable On uses RSpec for its test coverage. Inside the gem
43
+ directory, you can run the specs for RoR 3.x with:
44
+
45
+ rake spec
46
+
47
+ == Usage
48
+
49
+ class User < ActiveRecord::Base
50
+ # Alias for <tt>acts_as_taggable_on :tags</tt>:
51
+ acts_as_taggable
52
+ acts_as_taggable_on :skills, :interests
53
+ end
54
+
55
+ @user = User.new(:name => "Bobby")
56
+ @user.tag_list = "awesome, slick, hefty" # this should be familiar
57
+ @user.skill_list = "joking, clowning, boxing" # but you can do it for any context!
58
+ @user.skill_list # => ["joking","clowning","boxing"] as TagList
59
+ @user.save
60
+
61
+ @user.tags # => [<Tag name:"awesome">,<Tag name:"slick">,<Tag name:"hefty">]
62
+ @user.skills # => [<Tag name:"joking">,<Tag name:"clowning">,<Tag name:"boxing">]
63
+
64
+ @frankie = User.create(:name => "Frankie", :skill_list => "joking, flying, eating")
65
+ User.skill_counts # => [<Tag name="joking" count=2>,<Tag name="clowning" count=1>...]
66
+ @frankie.skill_counts
67
+
68
+ To preserve the order in which tags are created use acts_as_ordered_taggable:
69
+
70
+ class User < ActiveRecord::Base
71
+ # Alias for <tt>acts_as_ordered_taggable_on :tags</tt>:
72
+ acts_as_ordered_taggable
73
+ acts_as_ordered_taggable_on :skills, :interests
74
+ end
75
+
76
+ @user = User.new(:name => "Bobby")
77
+ @user.tag_list = "east, south"
78
+ @user.save
79
+
80
+ @user.tag_list = "north, east, south, west"
81
+ @user.save
82
+
83
+ @user.reload
84
+ @user.tag_list # => ["north", "east", "south", "west"]
85
+
86
+
87
+ === Finding Tagged Objects
88
+
89
+ Acts As Taggable On utilizes named_scopes to create an association for tags.
90
+ This way you can mix and match to filter down your results, and it also improves
91
+ compatibility with the will_paginate gem:
92
+
93
+ class User < ActiveRecord::Base
94
+ acts_as_taggable_on :tags, :skills
95
+ scope :by_join_date, order("created_at DESC")
96
+ end
97
+
98
+ User.tagged_with("awesome").by_date
99
+ User.tagged_with("awesome").by_date.paginate(:page => params[:page], :per_page => 20)
100
+
101
+ # Find a user with matching all tags, not just one
102
+ User.tagged_with(["awesome", "cool"], :match_all => true)
103
+
104
+ # Find a user with any of the tags:
105
+ User.tagged_with(["awesome", "cool"], :any => true)
106
+
107
+ # Find a user that not tags with awesome or cool:
108
+ User.tagged_with(["awesome", "cool"], :exclude => true)
109
+
110
+ # Find a user with any of tags based on context:
111
+ User.tagged_with(['awesome, cool'], :on => :tags, :any => true).tagged_with(['smart', 'shy'], :on => :skills, :any => true)
112
+
113
+ You can also use :wild => true option along with :any or :exclude option. It will looking for %awesome% and %cool% in sql.
114
+
115
+ Tip: User.tagged_with([]) or '' will return [], but not all records.
116
+
117
+ === Relationships
118
+
119
+ You can find objects of the same type based on similar tags on certain contexts.
120
+ Also, objects will be returned in descending order based on the total number of
121
+ matched tags.
122
+
123
+ @bobby = User.find_by_name("Bobby")
124
+ @bobby.skill_list # => ["jogging", "diving"]
125
+
126
+ @frankie = User.find_by_name("Frankie")
127
+ @frankie.skill_list # => ["hacking"]
128
+
129
+ @tom = User.find_by_name("Tom")
130
+ @tom.skill_list # => ["hacking", "jogging", "diving"]
131
+
132
+ @tom.find_related_skills # => [<User name="Bobby">,<User name="Frankie">]
133
+ @bobby.find_related_skills # => [<User name="Tom">]
134
+ @frankie.find_related_skills # => [<User name="Tom">]
135
+
136
+ === Dynamic Tag Contexts
137
+
138
+ In addition to the generated tag contexts in the definition, it is also possible
139
+ to allow for dynamic tag contexts (this could be user generated tag contexts!)
140
+
141
+ @user = User.new(:name => "Bobby")
142
+ @user.set_tag_list_on(:customs, "same, as, tag, list")
143
+ @user.tag_list_on(:customs) # => ["same","as","tag","list"]
144
+ @user.save
145
+ @user.tags_on(:customs) # => [<Tag name='same'>,...]
146
+ @user.tag_counts_on(:customs)
147
+ User.tagged_with("same", :on => :customs) # => [@user]
148
+
149
+ === Tag Ownership
150
+
151
+ Tags can have owners:
152
+
153
+ class User < ActiveRecord::Base
154
+ acts_as_tagger
155
+ end
156
+
157
+ class Photo < ActiveRecord::Base
158
+ acts_as_taggable_on :locations
159
+ end
160
+
161
+ @some_user.tag(@some_photo, :with => "paris, normandy", :on => :locations)
162
+ @some_user.owned_taggings
163
+ @some_user.owned_tags
164
+ @some_photo.locations_from(@some_user) # => ["paris", "normandy"]
165
+ @some_photo.owner_tags_on(@some_user, :locations) # => [#<ActsAsTaggableOn::Tag id: 1, name: "paris">...]
166
+ @some_photo.owner_tags_on(nil, :locations) # => Ownerships equivalent to saying @some_photo.locations
167
+ @some_user.tag(@some_photo, :with => "paris, normandy", :on => :locations, :skip_save => true) #won't save @some_photo object
168
+
169
+ === Dirty objects
170
+
171
+ @bobby = User.find_by_name("Bobby")
172
+ @bobby.skill_list # => ["jogging", "diving"]
173
+
174
+ @boddy.skill_list_changed? #=> false
175
+ @boddy.changes #=> {}
176
+
177
+ @bobby.skill_list = "swimming"
178
+ @bobby.changes.should == {"skill_list"=>["jogging, diving", ["swimming"]]}
179
+ @boddy.skill_list_changed? #=> true
180
+
181
+ @bobby.skill_list_change.should == ["jogging, diving", ["swimming"]]
182
+
183
+ === Tag cloud calculations
184
+
185
+ To construct tag clouds, the frequency of each tag needs to be calculated.
186
+ Because we specified +acts_as_taggable_on+ on the <tt>User</tt> class, we can
187
+ 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
188
+ an single user's posts? To achieve this we call tag_counts on the association:
189
+
190
+ User.find(:first).posts.tag_counts_on(:tags)
191
+
192
+ A helper is included to assist with generating tag clouds.
193
+
194
+ Here is an example that generates a tag cloud.
195
+
196
+ Helper:
197
+
198
+ module PostsHelper
199
+ include ActsAsTaggableOn::TagsHelper
200
+ end
201
+
202
+ Controller:
203
+
204
+ class PostController < ApplicationController
205
+ def tag_cloud
206
+ @tags = Post.tag_counts_on(:tags)
207
+ end
208
+ end
209
+
210
+ View:
211
+
212
+ <% tag_cloud(@tags, %w(css1 css2 css3 css4)) do |tag, css_class| %>
213
+ <%= link_to tag.name, { :action => :tag, :id => tag.name }, :class => css_class %>
214
+ <% end %>
215
+
216
+ CSS:
217
+
218
+ .css1 { font-size: 1.0em; }
219
+ .css2 { font-size: 1.2em; }
220
+ .css3 { font-size: 1.4em; }
221
+ .css4 { font-size: 1.6em; }
222
+
223
+ == Configuration
224
+
225
+ If you would like to remove unused tag objects after removing taggings, add
226
+
227
+ ActsAsTaggableOn.remove_unused_tags = true
228
+
229
+ If you want force tags to be saved downcased:
230
+
231
+ ActsAsTaggableOn.force_lowercase = true
232
+
233
+ If you want tags to be saved parametrized (you can redefine to_param as well):
234
+
235
+ ActsAsTaggableOn.force_parameterize = true
236
+
237
+
238
+ == Contributors
239
+
240
+ We have a long list of valued contributors. {Check them all}[https://github.com/mbleigh/acts-as-taggable-on/contributors]
241
+
242
+ == Maintainers
243
+
244
+ * Artem Kramarenko (artemk)
245
+
246
+ == Author
247
+
248
+ * Michael Bleigh
249
+
250
+ Copyright (c) 2007-2011 Michael Bleigh (http://mbleigh.com/) and Intridea Inc. (http://intridea.com/), released under the MIT license
data/Rakefile ADDED
@@ -0,0 +1,13 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ Bundler.setup :default, :development
4
+
5
+ desc 'Default: run specs'
6
+ task :default => :spec
7
+
8
+ require 'rspec/core/rake_task'
9
+ RSpec::Core::RakeTask.new do |t|
10
+ t.pattern = "spec/**/*_spec.rb"
11
+ end
12
+
13
+ Bundler::GemHelper.install_tasks
@@ -0,0 +1,28 @@
1
+ $:.push File.dirname(__FILE__) + '/lib'
2
+ require 'acts-as-taggable-on/version'
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.name = %q{crowdint_acts-as-taggable-on}
6
+ gem.authors = ["Michael Bleigh", 'Crowd Interactive']
7
+ gem.date = %q{2012-05-26}
8
+ gem.description = %q{With ActsAsTaggableOn, you can tag a single model on several contexts, such as skills, interests, and awards. It also provides other advanced functionality. Do not remove old tags after creating a new tag}
9
+ gem.summary = "Advanced tagging for Rails."
10
+ gem.email = %q{michael@intridea.com opensource@crowdint.com}
11
+ gem.homepage = 'https://github.com/crowdint/acts-as-taggable-on'
12
+
13
+ gem.add_runtime_dependency 'rails', '~> 3.0'
14
+ gem.add_development_dependency 'rspec', '~> 2.6'
15
+ gem.add_development_dependency 'ammeter', '~> 0.1.3'
16
+ gem.add_development_dependency 'sqlite3'
17
+ gem.add_development_dependency 'mysql2', '~> 0.3.7'
18
+ gem.add_development_dependency 'pg'
19
+ gem.add_development_dependency 'guard'
20
+ gem.add_development_dependency 'guard-rspec'
21
+
22
+ gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
23
+ gem.files = `git ls-files`.split("\n")
24
+ gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
25
+ gem.name = "crowdint_acts-as-taggable-on"
26
+ gem.require_paths = ['lib']
27
+ gem.version = ActsAsTaggableOn::VERSION
28
+ end
@@ -0,0 +1,59 @@
1
+ require "active_record"
2
+ require "active_record/version"
3
+ require "action_view"
4
+
5
+ require "digest/sha1"
6
+
7
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
8
+
9
+ module ActsAsTaggableOn
10
+ mattr_accessor :delimiter
11
+ @@delimiter = ','
12
+
13
+ mattr_accessor :force_lowercase
14
+ @@force_lowercase = false
15
+
16
+ mattr_accessor :force_parameterize
17
+ @@force_parameterize = false
18
+
19
+ mattr_accessor :remove_unused_tags
20
+ self.remove_unused_tags = false
21
+
22
+ def self.glue
23
+ @@delimiter.ends_with?(" ") ? @@delimiter : "#{@@delimiter} "
24
+ end
25
+
26
+ def self.setup
27
+ yield self
28
+ end
29
+ end
30
+
31
+
32
+ require "acts_as_taggable_on/utils"
33
+
34
+ require "acts_as_taggable_on/taggable"
35
+ require "acts_as_taggable_on/acts_as_taggable_on/core"
36
+ require "acts_as_taggable_on/acts_as_taggable_on/collection"
37
+ require "acts_as_taggable_on/acts_as_taggable_on/cache"
38
+ require "acts_as_taggable_on/acts_as_taggable_on/ownership"
39
+ require "acts_as_taggable_on/acts_as_taggable_on/related"
40
+ require "acts_as_taggable_on/acts_as_taggable_on/dirty"
41
+
42
+ require "acts_as_taggable_on/tagger"
43
+ require "acts_as_taggable_on/tag"
44
+ require "acts_as_taggable_on/tag_list"
45
+ require "acts_as_taggable_on/tags_helper"
46
+ require "acts_as_taggable_on/tagging"
47
+
48
+ $LOAD_PATH.shift
49
+
50
+
51
+ if defined?(ActiveRecord::Base)
52
+ ActiveRecord::Base.extend ActsAsTaggableOn::Taggable
53
+ ActiveRecord::Base.send :include, ActsAsTaggableOn::Tagger
54
+ end
55
+
56
+ if defined?(ActionView::Base)
57
+ ActionView::Base.send :include, ActsAsTaggableOn::TagsHelper
58
+ end
59
+