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.
- checksums.yaml +7 -0
- data/.gitignore +11 -0
- data/.rspec +2 -0
- data/.travis.yml +9 -0
- data/CHANGELOG.md +35 -0
- data/Gemfile +2 -9
- data/Guardfile +5 -0
- data/{MIT-LICENSE → MIT-LICENSE.md} +1 -1
- data/README.md +297 -0
- data/Rakefile +9 -55
- data/UPGRADING +14 -0
- data/acts-as-taggable-on.gemspec +32 -0
- data/lib/acts-as-taggable-on/version.rb +4 -0
- data/lib/acts-as-taggable-on.rb +37 -4
- data/lib/acts_as_taggable_on/acts_as_taggable_on/cache.rb +6 -6
- data/lib/acts_as_taggable_on/acts_as_taggable_on/collection.rb +99 -45
- data/lib/acts_as_taggable_on/acts_as_taggable_on/core.rb +162 -45
- data/lib/acts_as_taggable_on/acts_as_taggable_on/dirty.rb +37 -0
- data/lib/acts_as_taggable_on/acts_as_taggable_on/ownership.rb +40 -15
- data/lib/acts_as_taggable_on/acts_as_taggable_on/related.rb +28 -18
- data/lib/acts_as_taggable_on/tag.rb +41 -16
- data/lib/acts_as_taggable_on/tag_list.rb +19 -14
- data/lib/acts_as_taggable_on/taggable.rb +102 -0
- data/lib/acts_as_taggable_on/{acts_as_tagger.rb → tagger.rb} +3 -3
- data/lib/acts_as_taggable_on/tagging.rb +12 -2
- data/lib/acts_as_taggable_on/tags_helper.rb +2 -2
- data/lib/acts_as_taggable_on/utils.rb +34 -0
- data/lib/generators/acts_as_taggable_on/migration/migration_generator.rb +9 -2
- data/lib/generators/acts_as_taggable_on/migration/templates/active_record/migration.rb +3 -1
- data/spec/acts_as_taggable_on/acts_as_taggable_on_spec.rb +333 -54
- data/spec/acts_as_taggable_on/tag_list_spec.rb +117 -61
- data/spec/acts_as_taggable_on/tag_spec.rb +111 -14
- data/spec/acts_as_taggable_on/taggable_spec.rb +330 -34
- data/spec/acts_as_taggable_on/tagger_spec.rb +62 -15
- data/spec/acts_as_taggable_on/tagging_spec.rb +2 -5
- data/spec/acts_as_taggable_on/tags_helper_spec.rb +16 -0
- data/spec/acts_as_taggable_on/utils_spec.rb +21 -0
- data/spec/database.yml.sample +4 -2
- data/spec/generators/acts_as_taggable_on/migration/migration_generator_spec.rb +22 -0
- data/spec/models.rb +28 -1
- data/spec/schema.rb +18 -0
- data/spec/spec_helper.rb +30 -7
- data/uninstall.rb +1 -0
- metadata +174 -57
- data/CHANGELOG +0 -25
- data/README.rdoc +0 -221
- data/VERSION +0 -1
- data/generators/acts_as_taggable_on_migration/acts_as_taggable_on_migration_generator.rb +0 -7
- data/generators/acts_as_taggable_on_migration/templates/migration.rb +0 -29
- data/lib/acts_as_taggable_on/acts_as_taggable_on.rb +0 -53
- data/lib/acts_as_taggable_on/compatibility/Gemfile +0 -8
- data/lib/acts_as_taggable_on/compatibility/active_record_backports.rb +0 -17
- data/lib/acts_as_taggable_on/compatibility/postgresql.rb +0 -44
- data/spec/database.yml +0 -17
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: fd04dd7817f5d465548706b2bb39ed8923bef126
|
4
|
+
data.tar.gz: 371cb9a485f0370ff51074edc74296219d6f1342
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: f6dd2e281ec95af2bf1b3779a96522a99c81aa06d09b6e59337805c94060419c9860ef707d378029214b58fae76a9d23ac67d9b94a978c91385fffb2f605d64b
|
7
|
+
data.tar.gz: 843b679f0dd4212e1b814323a3b253d8f8d62942acd30d0f696a64301064c6bc5d6f4b65cfb33d300929b3c2f6f7910c844e98fa9b9fabbd47c5fc03f968cb44
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/CHANGELOG.md
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
CHANGED
data/Guardfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,297 @@
|
|
1
|
+
# ActsAsTaggableOn
|
2
|
+
[](http://travis-ci.org/mbleigh/acts-as-taggable-on)
|
3
|
+
|
4
|
+
This plugin was originally based on Acts as Taggable on Steroids by Jonathan Viney.
|
5
|
+
It has evolved substantially since that point, but all credit goes to him for the
|
6
|
+
initial tagging functionality that so many people have used.
|
7
|
+
|
8
|
+
For instance, in a social network, a user might have tags that are called skills,
|
9
|
+
interests, sports, and more. There is no real way to differentiate between tags and
|
10
|
+
so an implementation of this type is not possible with acts as taggable on steroids.
|
11
|
+
|
12
|
+
Enter Acts as Taggable On. Rather than tying functionality to a specific keyword
|
13
|
+
(namely `tags`), acts as taggable on allows you to specify an arbitrary number of
|
14
|
+
tag "contexts" that can be used locally or in combination in the same way steroids
|
15
|
+
was used.
|
16
|
+
|
17
|
+
## Installation
|
18
|
+
|
19
|
+
### Rails 2.x
|
20
|
+
|
21
|
+
Not supported any more! It is time for update guys.
|
22
|
+
|
23
|
+
### Rails 3.x
|
24
|
+
|
25
|
+
To use it, add it to your Gemfile:
|
26
|
+
|
27
|
+
```ruby
|
28
|
+
gem 'acts-as-taggable-on', '~> 2.3.1'
|
29
|
+
```
|
30
|
+
|
31
|
+
#### Post Installation
|
32
|
+
|
33
|
+
```shell
|
34
|
+
rails generate acts_as_taggable_on:migration
|
35
|
+
rake db:migrate
|
36
|
+
```
|
37
|
+
|
38
|
+
## Testing
|
39
|
+
|
40
|
+
Acts As Taggable On uses RSpec for its test coverage. Inside the gem
|
41
|
+
directory, you can run the specs for RoR 3.x with:
|
42
|
+
|
43
|
+
```shell
|
44
|
+
rake spec
|
45
|
+
```
|
46
|
+
|
47
|
+
## Usage
|
48
|
+
|
49
|
+
```ruby
|
50
|
+
class User < ActiveRecord::Base
|
51
|
+
# Alias for acts_as_taggable_on :tags
|
52
|
+
acts_as_taggable
|
53
|
+
acts_as_taggable_on :skills, :interests
|
54
|
+
end
|
55
|
+
|
56
|
+
@user = User.new(:name => "Bobby")
|
57
|
+
@user.tag_list = "awesome, slick, hefty" # this should be familiar
|
58
|
+
@user.skill_list = "joking, clowning, boxing" # but you can do it for any context!
|
59
|
+
|
60
|
+
@user.tags # => [<Tag name:"awesome">,<Tag name:"slick">,<Tag name:"hefty">]
|
61
|
+
@user.skills # => [<Tag name:"joking">,<Tag name:"clowning">,<Tag name:"boxing">]
|
62
|
+
@user.skill_list # => ["joking","clowning","boxing"] as TagList
|
63
|
+
|
64
|
+
@user.tag_list.remove("awesome") # remove a single tag
|
65
|
+
@user.tag_list.remove("awesome, slick") # works with arrays too
|
66
|
+
@user.tag_list.add("awesomer") # add a single tag. alias for <<
|
67
|
+
@user.tag_list.add("awesomer, slicker") # also works with arrays
|
68
|
+
|
69
|
+
User.skill_counts # => [<Tag name="joking" count=2>,<Tag name="clowning" count=1>...]
|
70
|
+
```
|
71
|
+
|
72
|
+
To preserve the order in which tags are created use `acts_as_ordered_taggable`:
|
73
|
+
|
74
|
+
```ruby
|
75
|
+
class User < ActiveRecord::Base
|
76
|
+
# Alias for acts_as_ordered_taggable_on :tags
|
77
|
+
acts_as_ordered_taggable
|
78
|
+
acts_as_ordered_taggable_on :skills, :interests
|
79
|
+
end
|
80
|
+
|
81
|
+
@user = User.new(:name => "Bobby")
|
82
|
+
@user.tag_list = "east, south"
|
83
|
+
@user.save
|
84
|
+
|
85
|
+
@user.tag_list = "north, east, south, west"
|
86
|
+
@user.save
|
87
|
+
|
88
|
+
@user.reload
|
89
|
+
@user.tag_list # => ["north", "east", "south", "west"]
|
90
|
+
```
|
91
|
+
|
92
|
+
### Finding Tagged Objects
|
93
|
+
|
94
|
+
Acts As Taggable On uses scopes to create an association for tags.
|
95
|
+
This way you can mix and match to filter down your results.
|
96
|
+
|
97
|
+
```ruby
|
98
|
+
class User < ActiveRecord::Base
|
99
|
+
acts_as_taggable_on :tags, :skills
|
100
|
+
scope :by_join_date, order("created_at DESC")
|
101
|
+
end
|
102
|
+
|
103
|
+
User.tagged_with("awesome").by_join_date
|
104
|
+
User.tagged_with("awesome").by_join_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
|
+
# Find a user that not tags with awesome or cool:
|
113
|
+
User.tagged_with(["awesome", "cool"], :exclude => true)
|
114
|
+
|
115
|
+
# Find a user with any of tags based on context:
|
116
|
+
User.tagged_with(['awesome, cool'], :on => :tags, :any => true).tagged_with(['smart', 'shy'], :on => :skills, :any => true)
|
117
|
+
```
|
118
|
+
|
119
|
+
You can also use `:wild => true` option along with `:any` or `:exclude` option. It will looking for `%awesome%` and `%cool%` in sql.
|
120
|
+
|
121
|
+
__Tip:__ `User.tagged_with([])` or '' will return `[]`, but not all records.
|
122
|
+
|
123
|
+
### Relationships
|
124
|
+
|
125
|
+
You can find objects of the same type based on similar tags on certain contexts.
|
126
|
+
Also, objects will be returned in descending order based on the total number of
|
127
|
+
matched tags.
|
128
|
+
|
129
|
+
```ruby
|
130
|
+
@bobby = User.find_by_name("Bobby")
|
131
|
+
@bobby.skill_list # => ["jogging", "diving"]
|
132
|
+
|
133
|
+
@frankie = User.find_by_name("Frankie")
|
134
|
+
@frankie.skill_list # => ["hacking"]
|
135
|
+
|
136
|
+
@tom = User.find_by_name("Tom")
|
137
|
+
@tom.skill_list # => ["hacking", "jogging", "diving"]
|
138
|
+
|
139
|
+
@tom.find_related_skills # => [<User name="Bobby">,<User name="Frankie">]
|
140
|
+
@bobby.find_related_skills # => [<User name="Tom">]
|
141
|
+
@frankie.find_related_skills # => [<User name="Tom">]
|
142
|
+
```
|
143
|
+
|
144
|
+
### Dynamic Tag Contexts
|
145
|
+
|
146
|
+
In addition to the generated tag contexts in the definition, it is also possible
|
147
|
+
to allow for dynamic tag contexts (this could be user generated tag contexts!)
|
148
|
+
|
149
|
+
```ruby
|
150
|
+
@user = User.new(:name => "Bobby")
|
151
|
+
@user.set_tag_list_on(:customs, "same, as, tag, list")
|
152
|
+
@user.tag_list_on(:customs) # => ["same","as","tag","list"]
|
153
|
+
@user.save
|
154
|
+
@user.tags_on(:customs) # => [<Tag name='same'>,...]
|
155
|
+
@user.tag_counts_on(:customs)
|
156
|
+
User.tagged_with("same", :on => :customs) # => [@user]
|
157
|
+
```
|
158
|
+
|
159
|
+
### Tag Ownership
|
160
|
+
|
161
|
+
Tags can have owners:
|
162
|
+
|
163
|
+
```ruby
|
164
|
+
class User < ActiveRecord::Base
|
165
|
+
acts_as_tagger
|
166
|
+
end
|
167
|
+
|
168
|
+
class Photo < ActiveRecord::Base
|
169
|
+
acts_as_taggable_on :locations
|
170
|
+
end
|
171
|
+
|
172
|
+
@some_user.tag(@some_photo, :with => "paris, normandy", :on => :locations)
|
173
|
+
@some_user.owned_taggings
|
174
|
+
@some_user.owned_tags
|
175
|
+
Photo.tagged_with("paris", :on => :locations, :owned_by => @some_user)
|
176
|
+
@some_photo.locations_from(@some_user) # => ["paris", "normandy"]
|
177
|
+
@some_photo.owner_tags_on(@some_user, :locations) # => [#<ActsAsTaggableOn::Tag id: 1, name: "paris">...]
|
178
|
+
@some_photo.owner_tags_on(nil, :locations) # => Ownerships equivalent to saying @some_photo.locations
|
179
|
+
@some_user.tag(@some_photo, :with => "paris, normandy", :on => :locations, :skip_save => true) #won't save @some_photo object
|
180
|
+
```
|
181
|
+
|
182
|
+
### Dirty objects
|
183
|
+
|
184
|
+
```ruby
|
185
|
+
@bobby = User.find_by_name("Bobby")
|
186
|
+
@bobby.skill_list # => ["jogging", "diving"]
|
187
|
+
|
188
|
+
@bobby.skill_list_changed? #=> false
|
189
|
+
@bobby.changes #=> {}
|
190
|
+
|
191
|
+
@bobby.skill_list = "swimming"
|
192
|
+
@bobby.changes.should == {"skill_list"=>["jogging, diving", ["swimming"]]}
|
193
|
+
@bobby.skill_list_changed? #=> true
|
194
|
+
|
195
|
+
@bobby.skill_list_change.should == ["jogging, diving", ["swimming"]]
|
196
|
+
```
|
197
|
+
|
198
|
+
### Tag cloud calculations
|
199
|
+
|
200
|
+
To construct tag clouds, the frequency of each tag needs to be calculated.
|
201
|
+
Because we specified `acts_as_taggable_on` on the `User` class, we can
|
202
|
+
get a calculation of all the tag counts by using `User.tag_counts_on(:customs)`. But what if we wanted a tag count for
|
203
|
+
an single user's posts? To achieve this we call tag_counts on the association:
|
204
|
+
|
205
|
+
```ruby
|
206
|
+
User.find(:first).posts.tag_counts_on(:tags)
|
207
|
+
```
|
208
|
+
|
209
|
+
A helper is included to assist with generating tag clouds.
|
210
|
+
|
211
|
+
Here is an example that generates a tag cloud.
|
212
|
+
|
213
|
+
Helper:
|
214
|
+
|
215
|
+
```ruby
|
216
|
+
module PostsHelper
|
217
|
+
include ActsAsTaggableOn::TagsHelper
|
218
|
+
end
|
219
|
+
```
|
220
|
+
|
221
|
+
Controller:
|
222
|
+
|
223
|
+
```ruby
|
224
|
+
class PostController < ApplicationController
|
225
|
+
def tag_cloud
|
226
|
+
@tags = Post.tag_counts_on(:tags)
|
227
|
+
end
|
228
|
+
end
|
229
|
+
```
|
230
|
+
|
231
|
+
View:
|
232
|
+
|
233
|
+
```erb
|
234
|
+
<% tag_cloud(@tags, %w(css1 css2 css3 css4)) do |tag, css_class| %>
|
235
|
+
<%= link_to tag.name, { :action => :tag, :id => tag.name }, :class => css_class %>
|
236
|
+
<% end %>
|
237
|
+
```
|
238
|
+
|
239
|
+
CSS:
|
240
|
+
|
241
|
+
```css
|
242
|
+
.css1 { font-size: 1.0em; }
|
243
|
+
.css2 { font-size: 1.2em; }
|
244
|
+
.css3 { font-size: 1.4em; }
|
245
|
+
.css4 { font-size: 1.6em; }
|
246
|
+
```
|
247
|
+
|
248
|
+
## Configuration
|
249
|
+
|
250
|
+
If you would like to remove unused tag objects after removing taggings, add:
|
251
|
+
|
252
|
+
```ruby
|
253
|
+
ActsAsTaggableOn.remove_unused_tags = true
|
254
|
+
```
|
255
|
+
|
256
|
+
If you want force tags to be saved downcased:
|
257
|
+
|
258
|
+
```ruby
|
259
|
+
ActsAsTaggableOn.force_lowercase = true
|
260
|
+
```
|
261
|
+
|
262
|
+
If you want tags to be saved parametrized (you can redefine to_param as well):
|
263
|
+
|
264
|
+
```ruby
|
265
|
+
ActsAsTaggableOn.force_parameterize = true
|
266
|
+
```
|
267
|
+
|
268
|
+
If you would like tags to be case-sensitive and not use LIKE queries for creation:
|
269
|
+
|
270
|
+
```ruby
|
271
|
+
ActsAsTaggableOn.strict_case_match = true
|
272
|
+
```
|
273
|
+
|
274
|
+
If you want to change the default delimiter (it defaults to ','). You can also pass in an array of delimiters such as ([',', '|']):
|
275
|
+
|
276
|
+
```ruby
|
277
|
+
ActsAsTaggableOn.delimiter = ','
|
278
|
+
```
|
279
|
+
|
280
|
+
## Changelog
|
281
|
+
|
282
|
+
See [CHANGELOG](https://github.com/mbleigh/acts-as-taggable-on/blob/master/CHANGELOG.md).
|
283
|
+
|
284
|
+
## Contributors
|
285
|
+
|
286
|
+
We have a long list of valued contributors. [Check them all](https://github.com/mbleigh/acts-as-taggable-on/contributors)
|
287
|
+
|
288
|
+
## Maintainers
|
289
|
+
|
290
|
+
* [Artem Kramarenko](https://github.com/artemk) (artemk)
|
291
|
+
* [Joost Baaij](https://github.com/tilsammans)
|
292
|
+
|
293
|
+
## Author
|
294
|
+
|
295
|
+
* [Michael Bleigh](https://github.com/mbleigh)
|
296
|
+
|
297
|
+
Copyright (c) 2007-2011 Michael Bleigh (http://mbleigh.com/) and Intridea Inc. (http://intridea.com/), released under the [MIT license](https://github.com/mbleigh/acts-as-taggable-on/blob/master/MIT-LICENSE.md)
|
data/Rakefile
CHANGED
@@ -1,59 +1,13 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler'
|
3
|
+
Bundler.setup :default, :development
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
Spec::Rake::SpecTask.new do |t|
|
8
|
-
t.spec_files = FileList["spec/**/*_spec.rb"]
|
9
|
-
end
|
5
|
+
desc 'Default: run specs'
|
6
|
+
task :default => :spec
|
10
7
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
t.rcov_opts = ['--exclude', 'spec']
|
15
|
-
end
|
16
|
-
|
17
|
-
rescue LoadError
|
18
|
-
# Rspec 2.0
|
19
|
-
require 'rspec/core/rake_task'
|
20
|
-
|
21
|
-
desc 'Default: run specs'
|
22
|
-
task :default => :spec
|
23
|
-
Rspec::Core::RakeTask.new do |t|
|
24
|
-
t.pattern = "spec/**/*_spec.rb"
|
25
|
-
end
|
26
|
-
|
27
|
-
Rspec::Core::RakeTask.new('rcov') do |t|
|
28
|
-
t.pattern = "spec/**/*_spec.rb"
|
29
|
-
t.rcov = true
|
30
|
-
t.rcov_opts = ['--exclude', 'spec']
|
31
|
-
end
|
32
|
-
|
33
|
-
rescue LoadError
|
34
|
-
puts "Rspec not available. Install it with: gem install rspec"
|
35
|
-
end
|
36
|
-
|
37
|
-
namespace 'rails2.3' do
|
38
|
-
task :spec do
|
39
|
-
gemfile = File.join(File.dirname(__FILE__), 'lib', 'acts_as_taggable_on', 'compatibility', 'Gemfile')
|
40
|
-
ENV['BUNDLE_GEMFILE'] = gemfile
|
41
|
-
Rake::Task['spec'].invoke
|
42
|
-
end
|
8
|
+
require 'rspec/core/rake_task'
|
9
|
+
RSpec::Core::RakeTask.new do |t|
|
10
|
+
t.pattern = "spec/**/*_spec.rb"
|
43
11
|
end
|
44
12
|
|
45
|
-
|
46
|
-
require 'jeweler'
|
47
|
-
Jeweler::Tasks.new do |gemspec|
|
48
|
-
gemspec.name = "acts-as-taggable-on"
|
49
|
-
gemspec.summary = "ActsAsTaggableOn is a tagging plugin for Rails that provides multiple tagging contexts on a single model."
|
50
|
-
gemspec.description = "With ActsAsTaggableOn, you could tag a single model on several contexts, such as skills, interests, and awards. It also provides other advanced functionality."
|
51
|
-
gemspec.email = "michael@intridea.com"
|
52
|
-
gemspec.homepage = "http://github.com/mbleigh/acts-as-taggable-on"
|
53
|
-
gemspec.authors = ["Michael Bleigh"]
|
54
|
-
gemspec.files = FileList["[A-Z]*", "{generators,lib,spec,rails}/**/*"] - FileList["**/*.log"]
|
55
|
-
end
|
56
|
-
Jeweler::GemcutterTasks.new
|
57
|
-
rescue LoadError
|
58
|
-
puts "Jeweler not available. Install it with: gem install jeweler"
|
59
|
-
end
|
13
|
+
Bundler::GemHelper.install_tasks
|
data/UPGRADING
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
|
2
|
+
** acts-as-taggable-on version 2.4.0
|
3
|
+
|
4
|
+
Hello! This version is the first one released by me (@tilsammans),
|
5
|
+
a new maintainer on the project. It's been a while since the last
|
6
|
+
release and I am not 100% sure if any breaking changes have been
|
7
|
+
introduced. Please test your tagging functionality carefully.
|
8
|
+
|
9
|
+
From now on things should stabilize. Please check the project's
|
10
|
+
milestones and compatibilities stated in the readme. If you have
|
11
|
+
any questions, feel free to create an issue on github.
|
12
|
+
|
13
|
+
https://github.com/mbleigh/acts-as-taggable-on
|
14
|
+
|
@@ -0,0 +1,32 @@
|
|
1
|
+
$:.push File.dirname(__FILE__) + '/lib'
|
2
|
+
require 'acts-as-taggable-on/version'
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.name = %q{acts-as-taggable-on}
|
6
|
+
gem.authors = ["Michael Bleigh"]
|
7
|
+
gem.date = %q{2012-07-16}
|
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.}
|
9
|
+
gem.summary = "Advanced tagging for Rails."
|
10
|
+
gem.email = %q{michael@intridea.com}
|
11
|
+
gem.homepage = ''
|
12
|
+
|
13
|
+
if File.exists?('UPGRADING')
|
14
|
+
gem.post_install_message = File.read("UPGRADING")
|
15
|
+
end
|
16
|
+
|
17
|
+
gem.add_runtime_dependency 'rails', '~> 3.0'
|
18
|
+
gem.add_development_dependency 'rspec', '~> 2.6'
|
19
|
+
gem.add_development_dependency 'ammeter', '~> 0.1.3'
|
20
|
+
gem.add_development_dependency 'sqlite3'
|
21
|
+
gem.add_development_dependency 'mysql2', '~> 0.3.7'
|
22
|
+
gem.add_development_dependency 'pg'
|
23
|
+
gem.add_development_dependency 'guard'
|
24
|
+
gem.add_development_dependency 'guard-rspec'
|
25
|
+
|
26
|
+
gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
27
|
+
gem.files = `git ls-files`.split("\n")
|
28
|
+
gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
29
|
+
gem.name = "acts-as-taggable-on"
|
30
|
+
gem.require_paths = ['lib']
|
31
|
+
gem.version = ActsAsTaggableOn::VERSION
|
32
|
+
end
|
data/lib/acts-as-taggable-on.rb
CHANGED
@@ -1,18 +1,49 @@
|
|
1
1
|
require "active_record"
|
2
|
+
require "active_record/version"
|
2
3
|
require "action_view"
|
3
4
|
|
5
|
+
require "digest/sha1"
|
6
|
+
|
4
7
|
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
5
8
|
|
6
|
-
|
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 :strict_case_match
|
20
|
+
@@strict_case_match = false
|
7
21
|
|
8
|
-
|
22
|
+
mattr_accessor :remove_unused_tags
|
23
|
+
self.remove_unused_tags = false
|
24
|
+
|
25
|
+
def self.glue
|
26
|
+
delimiter = @@delimiter.kind_of?(Array) ? @@delimiter[0] : @@delimiter
|
27
|
+
delimiter.ends_with?(" ") ? delimiter : "#{delimiter} "
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.setup
|
31
|
+
yield self
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
|
36
|
+
require "acts_as_taggable_on/utils"
|
37
|
+
|
38
|
+
require "acts_as_taggable_on/taggable"
|
9
39
|
require "acts_as_taggable_on/acts_as_taggable_on/core"
|
10
40
|
require "acts_as_taggable_on/acts_as_taggable_on/collection"
|
11
41
|
require "acts_as_taggable_on/acts_as_taggable_on/cache"
|
12
42
|
require "acts_as_taggable_on/acts_as_taggable_on/ownership"
|
13
43
|
require "acts_as_taggable_on/acts_as_taggable_on/related"
|
44
|
+
require "acts_as_taggable_on/acts_as_taggable_on/dirty"
|
14
45
|
|
15
|
-
require "acts_as_taggable_on/
|
46
|
+
require "acts_as_taggable_on/tagger"
|
16
47
|
require "acts_as_taggable_on/tag"
|
17
48
|
require "acts_as_taggable_on/tag_list"
|
18
49
|
require "acts_as_taggable_on/tags_helper"
|
@@ -20,6 +51,7 @@ require "acts_as_taggable_on/tagging"
|
|
20
51
|
|
21
52
|
$LOAD_PATH.shift
|
22
53
|
|
54
|
+
|
23
55
|
if defined?(ActiveRecord::Base)
|
24
56
|
ActiveRecord::Base.extend ActsAsTaggableOn::Taggable
|
25
57
|
ActiveRecord::Base.send :include, ActsAsTaggableOn::Tagger
|
@@ -27,4 +59,5 @@ end
|
|
27
59
|
|
28
60
|
if defined?(ActionView::Base)
|
29
61
|
ActionView::Base.send :include, ActsAsTaggableOn::TagsHelper
|
30
|
-
end
|
62
|
+
end
|
63
|
+
|
@@ -11,23 +11,23 @@ module ActsAsTaggableOn::Taggable
|
|
11
11
|
before_save :save_cached_tag_list
|
12
12
|
end
|
13
13
|
|
14
|
-
base.
|
14
|
+
base.initialize_acts_as_taggable_on_cache
|
15
15
|
end
|
16
16
|
|
17
17
|
module ClassMethods
|
18
|
-
def
|
18
|
+
def initialize_acts_as_taggable_on_cache
|
19
19
|
tag_types.map(&:to_s).each do |tag_type|
|
20
|
-
class_eval
|
20
|
+
class_eval <<-RUBY, __FILE__, __LINE__ + 1
|
21
21
|
def self.caching_#{tag_type.singularize}_list?
|
22
22
|
caching_tag_list_on?("#{tag_type}")
|
23
23
|
end
|
24
|
-
|
24
|
+
RUBY
|
25
25
|
end
|
26
26
|
end
|
27
27
|
|
28
28
|
def acts_as_taggable_on(*args)
|
29
29
|
super(*args)
|
30
|
-
|
30
|
+
initialize_acts_as_taggable_on_cache
|
31
31
|
end
|
32
32
|
|
33
33
|
def caching_tag_list_on?(context)
|
@@ -40,7 +40,7 @@ module ActsAsTaggableOn::Taggable
|
|
40
40
|
tag_types.map(&:to_s).each do |tag_type|
|
41
41
|
if self.class.send("caching_#{tag_type.singularize}_list?")
|
42
42
|
if tag_list_cache_set_on(tag_type)
|
43
|
-
list = tag_list_cache_on(tag_type
|
43
|
+
list = tag_list_cache_on(tag_type).to_a.flatten.compact.join(', ')
|
44
44
|
self["cached_#{tag_type.singularize}_list"] = list
|
45
45
|
end
|
46
46
|
end
|