acts-as-taggable-on 2.0.6 → 3.0.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 +18 -0
- data/Appraisals +11 -0
- data/CHANGELOG.md +47 -0
- data/Gemfile +10 -9
- data/Guardfile +5 -0
- data/{MIT-LICENSE → LICENSE.md} +1 -1
- data/README.md +313 -0
- data/Rakefile +21 -49
- data/UPGRADING +7 -0
- data/acts-as-taggable-on.gemspec +35 -0
- data/{lib/generators/acts_as_taggable_on/migration/templates/active_record/migration.rb → db/migrate/1_acts_as_taggable_on_migration.rb} +3 -1
- data/db/migrate/2_add_missing_unique_indices.rb +21 -0
- data/gemfiles/rails_3.2.gemfile +7 -0
- data/gemfiles/rails_4.0.gemfile +7 -0
- data/gemfiles/rails_4.1.gemfile +7 -0
- data/lib/acts-as-taggable-on.rb +44 -13
- data/lib/acts_as_taggable_on/acts_as_taggable_on/cache.rb +52 -23
- data/lib/acts_as_taggable_on/acts_as_taggable_on/collection.rb +111 -49
- data/lib/acts_as_taggable_on/acts_as_taggable_on/compatibility.rb +34 -0
- data/lib/acts_as_taggable_on/acts_as_taggable_on/core.rb +208 -55
- 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 +51 -17
- data/lib/acts_as_taggable_on/acts_as_taggable_on/related.rb +41 -22
- data/lib/acts_as_taggable_on/engine.rb +6 -0
- data/lib/acts_as_taggable_on/tag.rb +65 -20
- data/lib/acts_as_taggable_on/tag_list.rb +19 -14
- data/lib/acts_as_taggable_on/taggable.rb +105 -0
- data/lib/acts_as_taggable_on/{acts_as_tagger.rb → tagger.rb} +15 -6
- data/lib/acts_as_taggable_on/tagging.rb +14 -4
- data/lib/acts_as_taggable_on/tags_helper.rb +3 -5
- data/lib/acts_as_taggable_on/utils.rb +34 -0
- data/lib/acts_as_taggable_on/version.rb +4 -0
- data/lib/acts_as_taggable_on.rb +6 -0
- data/spec/acts_as_taggable_on/acts_as_taggable_on_spec.rb +137 -140
- data/spec/acts_as_taggable_on/acts_as_tagger_spec.rb +27 -27
- data/spec/acts_as_taggable_on/caching_spec.rb +77 -0
- data/spec/acts_as_taggable_on/related_spec.rb +143 -0
- data/spec/acts_as_taggable_on/single_table_inheritance_spec.rb +187 -0
- data/spec/acts_as_taggable_on/tag_list_spec.rb +118 -62
- data/spec/acts_as_taggable_on/tag_spec.rb +110 -14
- data/spec/acts_as_taggable_on/taggable_spec.rb +382 -75
- data/spec/acts_as_taggable_on/tagger_spec.rb +67 -21
- data/spec/acts_as_taggable_on/tagging_spec.rb +3 -6
- data/spec/acts_as_taggable_on/tags_helper_spec.rb +24 -8
- data/spec/acts_as_taggable_on/utils_spec.rb +21 -0
- data/spec/database.yml.sample +4 -2
- data/spec/models.rb +29 -2
- data/spec/schema.rb +40 -18
- data/spec/spec_helper.rb +40 -30
- metadata +177 -62
- 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/lib/generators/acts_as_taggable_on/migration/migration_generator.rb +0 -32
- data/rails/init.rb +0 -1
- data/spec/database.yml +0 -17
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: 5b46e80f19a5c7de71ec448bd0700ef672ea9639
|
|
4
|
+
data.tar.gz: d7c19bc3aec73a2b5d1ff08ad18cb9c85e61225c
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 4ac4317c1fa00caa6f048d4958d830da83bae5a48d8fd2f4018918319069e9e0311b99318cfe337fcd8d23f9c37055484e1c40c1ab0ecda2c256d361315b0848
|
|
7
|
+
data.tar.gz: 7e29cf71dfce65f2ac65d0a10972c6b26344398278c53b088b9069ec728955e697389f496b25a8f57fd521b6349aaa2ef827caab78bf8a00c7416c9be43c21e5
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
rvm:
|
|
2
|
+
- 1.9.3
|
|
3
|
+
- 2.0.0
|
|
4
|
+
env:
|
|
5
|
+
- DB=sqlite3
|
|
6
|
+
- DB=mysql
|
|
7
|
+
- DB=postgresql
|
|
8
|
+
gemfile:
|
|
9
|
+
- gemfiles/rails_3.2.gemfile
|
|
10
|
+
- gemfiles/rails_4.0.gemfile
|
|
11
|
+
- gemfiles/rails_4.1.gemfile
|
|
12
|
+
cache: bundler
|
|
13
|
+
script: bundle exec rake
|
|
14
|
+
before_install:
|
|
15
|
+
- gem install bundler
|
|
16
|
+
bundler_args: '--without local_development'
|
|
17
|
+
matrix:
|
|
18
|
+
fast_finish: true
|
data/Appraisals
ADDED
data/CHANGELOG.md
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
Changes are below categorized as `Features, Fixes, or Misc`.
|
|
2
|
+
|
|
3
|
+
Each change should fall into categories that would affect whether the release is major (breaking changes), minor (new behavior), or patch (bug fix). See [semver](http://semver.org/) and [pessimistic versioning](http://guides.rubygems.org/patterns/#pessimistic_version_constraint)
|
|
4
|
+
|
|
5
|
+
As such, a _Feature_ would map to either major or minor. A _bug fix_ to a patch. And _misc_ is either minor or patch, the difference being kind of fuzzy for the purposes of history. Adding tests would be patch level.
|
|
6
|
+
|
|
7
|
+
### Master [changes](https://github.com/mbleigh/acts-as-taggable-on/compare/v3.0.0...master)
|
|
8
|
+
|
|
9
|
+
* Breaking Changes
|
|
10
|
+
* Features
|
|
11
|
+
* Fixes
|
|
12
|
+
* Misc
|
|
13
|
+
|
|
14
|
+
### [3.0.0 / 2014-01-01](https://github.com/mbleigh/acts-as-taggable-on/compare/v2.4.1...v3.0.0)
|
|
15
|
+
|
|
16
|
+
* Breaking Changes
|
|
17
|
+
* No longer supports Ruby 1.8.
|
|
18
|
+
* Features
|
|
19
|
+
* Supports Rails 4.1.
|
|
20
|
+
* Misc (TODO: expand)
|
|
21
|
+
* [zquest #359](https://github.com/mbleigh/acts-as-taggable-on/pull/359)
|
|
22
|
+
* [rsl #367](https://github.com/mbleigh/acts-as-taggable-on/pull/367)
|
|
23
|
+
* [ktdreyer #383](https://github.com/mbleigh/acts-as-taggable-on/pull/383)
|
|
24
|
+
* [cwoodcox #346](https://github.com/mbleigh/acts-as-taggable-on/pull/346)
|
|
25
|
+
* [mrb #421](https://github.com/mbleigh/acts-as-taggable-on/pull/421)
|
|
26
|
+
* [bf4 #430](https://github.com/mbleigh/acts-as-taggable-on/pull/430)
|
|
27
|
+
* [sanemat #368](https://github.com/mbleigh/acts-as-taggable-on/pull/368)
|
|
28
|
+
* [bf4 #343](https://github.com/mbleigh/acts-as-taggable-on/pull/343)
|
|
29
|
+
* [marclennox #429](https://github.com/mbleigh/acts-as-taggable-on/pull/429)
|
|
30
|
+
* [shekibobo #403](https://github.com/mbleigh/acts-as-taggable-on/pull/403)
|
|
31
|
+
* [ches ktdreyer #410](https://github.com/mbleigh/acts-as-taggable-on/pull/410)
|
|
32
|
+
* [makaroni4 #371](https://github.com/mbleigh/acts-as-taggable-on/pull/371)
|
|
33
|
+
* [kenzai dstosik awt #431](https://github.com/mbleigh/acts-as-taggable-on/pull/431)
|
|
34
|
+
* [bf4 joelcogen shekibobo aaronchi #438](https://github.com/mbleigh/acts-as-taggable-on/pull/438)
|
|
35
|
+
* [seuros #442](https://github.com/mbleigh/acts-as-taggable-on/pull/442)
|
|
36
|
+
* [bf4 #445](https://github.com/mbleigh/acts-as-taggable-on/pull/445)
|
|
37
|
+
* [eaglemt #446](https://github.com/mbleigh/acts-as-taggable-on/pull/446)
|
|
38
|
+
|
|
39
|
+
### 3.0.0.rc2 [changes](https://github.com/mbleigh/acts-as-taggable-on/compare/fork-v3.0.0.rc1...fork-v3.0.0.rc2)
|
|
40
|
+
|
|
41
|
+
### 3.0.0.rc1 [changes](https://github.com/mbleigh/acts-as-taggable-on/compare/v2.4.1...fork-v3.0.0.rc1)
|
|
42
|
+
|
|
43
|
+
### [2.4.1 / 2013-05-07](https://github.com/mbleigh/acts-as-taggable-on/compare/v2.4.0...v2.4.1)
|
|
44
|
+
|
|
45
|
+
* Features
|
|
46
|
+
* Fixes
|
|
47
|
+
* Misc
|
data/Gemfile
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
source
|
|
1
|
+
source 'https://rubygems.org'
|
|
2
|
+
|
|
3
|
+
gemspec
|
|
4
|
+
|
|
5
|
+
group :local_development do
|
|
6
|
+
gem 'guard'
|
|
7
|
+
gem 'guard-rspec'
|
|
8
|
+
gem 'appraisal'
|
|
9
|
+
gem 'rake'
|
|
10
|
+
end
|
|
2
11
|
|
|
3
|
-
# Rails 3.0
|
|
4
|
-
gem 'rails', '3.0.0.beta3'
|
|
5
|
-
gem 'rspec', '2.0.0.beta.8'
|
|
6
|
-
gem 'sqlite3-ruby', :require => 'sqlite3'
|
|
7
|
-
gem 'mysql'
|
|
8
|
-
gem 'pg'
|
|
9
|
-
gem 'jeweler'
|
|
10
|
-
gem 'rcov'
|
data/Guardfile
ADDED
data/{MIT-LICENSE → LICENSE.md}
RENAMED
data/README.md
ADDED
|
@@ -0,0 +1,313 @@
|
|
|
1
|
+
# ActsAsTaggableOn
|
|
2
|
+
[](http://travis-ci.org/mbleigh/acts-as-taggable-on)
|
|
3
|
+
[](https://codeclimate.com/github/mbleigh/acts-as-taggable-on)
|
|
4
|
+
|
|
5
|
+
This plugin was originally based on Acts as Taggable on Steroids by Jonathan Viney.
|
|
6
|
+
It has evolved substantially since that point, but all credit goes to him for the
|
|
7
|
+
initial tagging functionality that so many people have used.
|
|
8
|
+
|
|
9
|
+
For instance, in a social network, a user might have tags that are called skills,
|
|
10
|
+
interests, sports, and more. There is no real way to differentiate between tags and
|
|
11
|
+
so an implementation of this type is not possible with acts as taggable on steroids.
|
|
12
|
+
|
|
13
|
+
Enter Acts as Taggable On. Rather than tying functionality to a specific keyword
|
|
14
|
+
(namely `tags`), acts as taggable on allows you to specify an arbitrary number of
|
|
15
|
+
tag "contexts" that can be used locally or in combination in the same way steroids
|
|
16
|
+
was used.
|
|
17
|
+
|
|
18
|
+
## Compatibility
|
|
19
|
+
|
|
20
|
+
Versions 2.x are compatible with Ruby 1.8.7+ and Rails 3.
|
|
21
|
+
|
|
22
|
+
Versions 2.4.1 and up are compatible with Rails 4 too (thanks to arabonradar and cwoodcox).
|
|
23
|
+
|
|
24
|
+
Versions 3.x (currently unreleased) are compatible with Ruby 1.9.3+ and Rails 3 and 4. There is a [release candidate you may try](http://rubygems.org/gems/acts_as_taggable_on).
|
|
25
|
+
|
|
26
|
+
For an up-to-date roadmap, see https://github.com/mbleigh/acts-as-taggable-on/issues/milestones
|
|
27
|
+
|
|
28
|
+
## Installation
|
|
29
|
+
|
|
30
|
+
To use it, add it to your Gemfile:
|
|
31
|
+
|
|
32
|
+
```ruby
|
|
33
|
+
gem 'acts-as-taggable-on'
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
and bundle:
|
|
37
|
+
|
|
38
|
+
```ruby
|
|
39
|
+
bundle
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
#### Post Installation
|
|
43
|
+
|
|
44
|
+
```shell
|
|
45
|
+
# For the latest versions
|
|
46
|
+
rake railties:install:migrations FROM=acts_as_taggable_on_engine db:migrate
|
|
47
|
+
|
|
48
|
+
# For versions 2.4.1 and earlier
|
|
49
|
+
rails generate acts_as_taggable_on:migration
|
|
50
|
+
rake db:migrate
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
#### Upgrading
|
|
54
|
+
|
|
55
|
+
see [UPGRADING](UPGRADING)
|
|
56
|
+
|
|
57
|
+
## Usage
|
|
58
|
+
|
|
59
|
+
```ruby
|
|
60
|
+
class User < ActiveRecord::Base
|
|
61
|
+
# Alias for acts_as_taggable_on :tags
|
|
62
|
+
acts_as_taggable
|
|
63
|
+
acts_as_taggable_on :skills, :interests
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
@user = User.new(:name => "Bobby")
|
|
67
|
+
@user.tag_list = "awesome, slick, hefty" # this should be familiar
|
|
68
|
+
@user.skill_list = "joking, clowning, boxing" # but you can do it for any context!
|
|
69
|
+
|
|
70
|
+
@user.tags # => [<Tag name:"awesome">,<Tag name:"slick">,<Tag name:"hefty">]
|
|
71
|
+
@user.skills # => [<Tag name:"joking">,<Tag name:"clowning">,<Tag name:"boxing">]
|
|
72
|
+
@user.skill_list # => ["joking","clowning","boxing"] as TagList
|
|
73
|
+
|
|
74
|
+
@user.tag_list.remove("awesome") # remove a single tag
|
|
75
|
+
@user.tag_list.remove("awesome, slick") # works with arrays too
|
|
76
|
+
@user.tag_list.add("awesomer") # add a single tag. alias for <<
|
|
77
|
+
@user.tag_list.add("awesomer, slicker") # also works with arrays
|
|
78
|
+
|
|
79
|
+
User.skill_counts # => [<Tag name="joking" count=2>,<Tag name="clowning" count=1>...]
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
To preserve the order in which tags are created use `acts_as_ordered_taggable`:
|
|
83
|
+
|
|
84
|
+
```ruby
|
|
85
|
+
class User < ActiveRecord::Base
|
|
86
|
+
# Alias for acts_as_ordered_taggable_on :tags
|
|
87
|
+
acts_as_ordered_taggable
|
|
88
|
+
acts_as_ordered_taggable_on :skills, :interests
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
@user = User.new(:name => "Bobby")
|
|
92
|
+
@user.tag_list = "east, south"
|
|
93
|
+
@user.save
|
|
94
|
+
|
|
95
|
+
@user.tag_list = "north, east, south, west"
|
|
96
|
+
@user.save
|
|
97
|
+
|
|
98
|
+
@user.reload
|
|
99
|
+
@user.tag_list # => ["north", "east", "south", "west"]
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
### Finding Tagged Objects
|
|
103
|
+
|
|
104
|
+
Acts As Taggable On uses scopes to create an association for tags.
|
|
105
|
+
This way you can mix and match to filter down your results.
|
|
106
|
+
|
|
107
|
+
```ruby
|
|
108
|
+
class User < ActiveRecord::Base
|
|
109
|
+
acts_as_taggable_on :tags, :skills
|
|
110
|
+
scope :by_join_date, order("created_at DESC")
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
User.tagged_with("awesome").by_join_date
|
|
114
|
+
User.tagged_with("awesome").by_join_date.paginate(:page => params[:page], :per_page => 20)
|
|
115
|
+
|
|
116
|
+
# Find a user with matching all tags, not just one
|
|
117
|
+
User.tagged_with(["awesome", "cool"], :match_all => true)
|
|
118
|
+
|
|
119
|
+
# Find a user with any of the tags:
|
|
120
|
+
User.tagged_with(["awesome", "cool"], :any => true)
|
|
121
|
+
|
|
122
|
+
# Find a user that not tags with awesome or cool:
|
|
123
|
+
User.tagged_with(["awesome", "cool"], :exclude => true)
|
|
124
|
+
|
|
125
|
+
# Find a user with any of tags based on context:
|
|
126
|
+
User.tagged_with(['awesome, cool'], :on => :tags, :any => true).tagged_with(['smart', 'shy'], :on => :skills, :any => true)
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
You can also use `:wild => true` option along with `:any` or `:exclude` option. It will looking for `%awesome%` and `%cool%` in sql.
|
|
130
|
+
|
|
131
|
+
__Tip:__ `User.tagged_with([])` or '' will return `[]`, but not all records.
|
|
132
|
+
|
|
133
|
+
### Relationships
|
|
134
|
+
|
|
135
|
+
You can find objects of the same type based on similar tags on certain contexts.
|
|
136
|
+
Also, objects will be returned in descending order based on the total number of
|
|
137
|
+
matched tags.
|
|
138
|
+
|
|
139
|
+
```ruby
|
|
140
|
+
@bobby = User.find_by_name("Bobby")
|
|
141
|
+
@bobby.skill_list # => ["jogging", "diving"]
|
|
142
|
+
|
|
143
|
+
@frankie = User.find_by_name("Frankie")
|
|
144
|
+
@frankie.skill_list # => ["hacking"]
|
|
145
|
+
|
|
146
|
+
@tom = User.find_by_name("Tom")
|
|
147
|
+
@tom.skill_list # => ["hacking", "jogging", "diving"]
|
|
148
|
+
|
|
149
|
+
@tom.find_related_skills # => [<User name="Bobby">,<User name="Frankie">]
|
|
150
|
+
@bobby.find_related_skills # => [<User name="Tom">]
|
|
151
|
+
@frankie.find_related_skills # => [<User name="Tom">]
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
### Dynamic Tag Contexts
|
|
155
|
+
|
|
156
|
+
In addition to the generated tag contexts in the definition, it is also possible
|
|
157
|
+
to allow for dynamic tag contexts (this could be user generated tag contexts!)
|
|
158
|
+
|
|
159
|
+
```ruby
|
|
160
|
+
@user = User.new(:name => "Bobby")
|
|
161
|
+
@user.set_tag_list_on(:customs, "same, as, tag, list")
|
|
162
|
+
@user.tag_list_on(:customs) # => ["same","as","tag","list"]
|
|
163
|
+
@user.save
|
|
164
|
+
@user.tags_on(:customs) # => [<Tag name='same'>,...]
|
|
165
|
+
@user.tag_counts_on(:customs)
|
|
166
|
+
User.tagged_with("same", :on => :customs) # => [@user]
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
### Tag Ownership
|
|
170
|
+
|
|
171
|
+
Tags can have owners:
|
|
172
|
+
|
|
173
|
+
```ruby
|
|
174
|
+
class User < ActiveRecord::Base
|
|
175
|
+
acts_as_tagger
|
|
176
|
+
end
|
|
177
|
+
|
|
178
|
+
class Photo < ActiveRecord::Base
|
|
179
|
+
acts_as_taggable_on :locations
|
|
180
|
+
end
|
|
181
|
+
|
|
182
|
+
@some_user.tag(@some_photo, :with => "paris, normandy", :on => :locations)
|
|
183
|
+
@some_user.owned_taggings
|
|
184
|
+
@some_user.owned_tags
|
|
185
|
+
Photo.tagged_with("paris", :on => :locations, :owned_by => @some_user)
|
|
186
|
+
@some_photo.locations_from(@some_user) # => ["paris", "normandy"]
|
|
187
|
+
@some_photo.owner_tags_on(@some_user, :locations) # => [#<ActsAsTaggableOn::Tag id: 1, name: "paris">...]
|
|
188
|
+
@some_photo.owner_tags_on(nil, :locations) # => Ownerships equivalent to saying @some_photo.locations
|
|
189
|
+
@some_user.tag(@some_photo, :with => "paris, normandy", :on => :locations, :skip_save => true) #won't save @some_photo object
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
### Dirty objects
|
|
193
|
+
|
|
194
|
+
```ruby
|
|
195
|
+
@bobby = User.find_by_name("Bobby")
|
|
196
|
+
@bobby.skill_list # => ["jogging", "diving"]
|
|
197
|
+
|
|
198
|
+
@bobby.skill_list_changed? #=> false
|
|
199
|
+
@bobby.changes #=> {}
|
|
200
|
+
|
|
201
|
+
@bobby.skill_list = "swimming"
|
|
202
|
+
@bobby.changes.should == {"skill_list"=>["jogging, diving", ["swimming"]]}
|
|
203
|
+
@bobby.skill_list_changed? #=> true
|
|
204
|
+
|
|
205
|
+
@bobby.skill_list_change.should == ["jogging, diving", ["swimming"]]
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
### Tag cloud calculations
|
|
209
|
+
|
|
210
|
+
To construct tag clouds, the frequency of each tag needs to be calculated.
|
|
211
|
+
Because we specified `acts_as_taggable_on` on the `User` class, we can
|
|
212
|
+
get a calculation of all the tag counts by using `User.tag_counts_on(:customs)`. But what if we wanted a tag count for
|
|
213
|
+
an single user's posts? To achieve this we call tag_counts on the association:
|
|
214
|
+
|
|
215
|
+
```ruby
|
|
216
|
+
User.find(:first).posts.tag_counts_on(:tags)
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
A helper is included to assist with generating tag clouds.
|
|
220
|
+
|
|
221
|
+
Here is an example that generates a tag cloud.
|
|
222
|
+
|
|
223
|
+
Helper:
|
|
224
|
+
|
|
225
|
+
```ruby
|
|
226
|
+
module PostsHelper
|
|
227
|
+
include ActsAsTaggableOn::TagsHelper
|
|
228
|
+
end
|
|
229
|
+
```
|
|
230
|
+
|
|
231
|
+
Controller:
|
|
232
|
+
|
|
233
|
+
```ruby
|
|
234
|
+
class PostController < ApplicationController
|
|
235
|
+
def tag_cloud
|
|
236
|
+
@tags = Post.tag_counts_on(:tags)
|
|
237
|
+
end
|
|
238
|
+
end
|
|
239
|
+
```
|
|
240
|
+
|
|
241
|
+
View:
|
|
242
|
+
|
|
243
|
+
```erb
|
|
244
|
+
<% tag_cloud(@tags, %w(css1 css2 css3 css4)) do |tag, css_class| %>
|
|
245
|
+
<%= link_to tag.name, { :action => :tag, :id => tag.name }, :class => css_class %>
|
|
246
|
+
<% end %>
|
|
247
|
+
```
|
|
248
|
+
|
|
249
|
+
CSS:
|
|
250
|
+
|
|
251
|
+
```css
|
|
252
|
+
.css1 { font-size: 1.0em; }
|
|
253
|
+
.css2 { font-size: 1.2em; }
|
|
254
|
+
.css3 { font-size: 1.4em; }
|
|
255
|
+
.css4 { font-size: 1.6em; }
|
|
256
|
+
```
|
|
257
|
+
|
|
258
|
+
## Configuration
|
|
259
|
+
|
|
260
|
+
If you would like to remove unused tag objects after removing taggings, add:
|
|
261
|
+
|
|
262
|
+
```ruby
|
|
263
|
+
ActsAsTaggableOn.remove_unused_tags = true
|
|
264
|
+
```
|
|
265
|
+
|
|
266
|
+
If you want force tags to be saved downcased:
|
|
267
|
+
|
|
268
|
+
```ruby
|
|
269
|
+
ActsAsTaggableOn.force_lowercase = true
|
|
270
|
+
```
|
|
271
|
+
|
|
272
|
+
If you want tags to be saved parametrized (you can redefine to_param as well):
|
|
273
|
+
|
|
274
|
+
```ruby
|
|
275
|
+
ActsAsTaggableOn.force_parameterize = true
|
|
276
|
+
```
|
|
277
|
+
|
|
278
|
+
If you would like tags to be case-sensitive and not use LIKE queries for creation:
|
|
279
|
+
|
|
280
|
+
```ruby
|
|
281
|
+
ActsAsTaggableOn.strict_case_match = true
|
|
282
|
+
```
|
|
283
|
+
|
|
284
|
+
If you want to change the default delimiter (it defaults to ','). You can also pass in an array of delimiters such as ([',', '|']):
|
|
285
|
+
|
|
286
|
+
```ruby
|
|
287
|
+
ActsAsTaggableOn.delimiter = ','
|
|
288
|
+
```
|
|
289
|
+
|
|
290
|
+
## Contributors
|
|
291
|
+
|
|
292
|
+
We have a long list of valued contributors. [Check them all](https://github.com/mbleigh/acts-as-taggable-on/contributors)
|
|
293
|
+
|
|
294
|
+
## Maintainer
|
|
295
|
+
|
|
296
|
+
* [Joost Baaij](https://github.com/tilsammans)
|
|
297
|
+
|
|
298
|
+
## Testing
|
|
299
|
+
|
|
300
|
+
Acts As Taggable On uses RSpec for its test coverage. Inside the gem
|
|
301
|
+
directory, you can run the specs with:
|
|
302
|
+
|
|
303
|
+
```shell
|
|
304
|
+
bundle
|
|
305
|
+
rake spec
|
|
306
|
+
```
|
|
307
|
+
|
|
308
|
+
You can run all the tests across all the Rails versions by running `rake appraise`. If you'd also like to [run the tests across all rubies and databases as configured for Travis CI, install and run `wwtd`](https://github.com/grosser/wwtd).
|
|
309
|
+
|
|
310
|
+
|
|
311
|
+
## License
|
|
312
|
+
|
|
313
|
+
See [LICENSE](https://github.com/mbleigh/acts-as-taggable-on/blob/master/LICENSE.md)
|
data/Rakefile
CHANGED
|
@@ -1,59 +1,31 @@
|
|
|
1
|
+
require 'rubygems'
|
|
1
2
|
begin
|
|
2
|
-
|
|
3
|
-
|
|
3
|
+
require 'bundler/setup'
|
|
4
|
+
rescue LoadError
|
|
5
|
+
STDERR.puts "Bundler not loaded"
|
|
6
|
+
end
|
|
4
7
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
end
|
|
8
|
+
desc 'Copy sample spec database.yml over if not exists'
|
|
9
|
+
task :copy_db_config do
|
|
10
|
+
cp 'spec/database.yml.sample', 'spec/database.yml'
|
|
11
|
+
end
|
|
10
12
|
|
|
11
|
-
|
|
12
|
-
t.spec_files = FileList["spec/**/*_spec.rb"]
|
|
13
|
-
t.rcov = true
|
|
14
|
-
t.rcov_opts = ['--exclude', 'spec']
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
rescue LoadError
|
|
18
|
-
# Rspec 2.0
|
|
19
|
-
require 'rspec/core/rake_task'
|
|
13
|
+
task :spec => [:copy_db_config]
|
|
20
14
|
|
|
21
|
-
|
|
22
|
-
|
|
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
|
|
15
|
+
desc 'Default: run specs'
|
|
16
|
+
task :default => :spec
|
|
32
17
|
|
|
18
|
+
begin
|
|
19
|
+
require 'appraisal'
|
|
20
|
+
desc 'Run tests across gemfiles specified in Appraisals'
|
|
21
|
+
task :appraise => ['appraisal:cleanup', 'appraisal:install', 'appraisal']
|
|
33
22
|
rescue LoadError
|
|
34
|
-
puts "
|
|
23
|
+
puts "appraisal tasks not available"
|
|
35
24
|
end
|
|
36
25
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
ENV['BUNDLE_GEMFILE'] = gemfile
|
|
41
|
-
Rake::Task['spec'].invoke
|
|
42
|
-
end
|
|
26
|
+
require 'rspec/core/rake_task'
|
|
27
|
+
RSpec::Core::RakeTask.new do |t|
|
|
28
|
+
t.pattern = "spec/**/*_spec.rb"
|
|
43
29
|
end
|
|
44
30
|
|
|
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
|
|
31
|
+
Bundler::GemHelper.install_tasks
|
data/UPGRADING
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
# coding: utf-8
|
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
|
+
require 'acts_as_taggable_on/version'
|
|
5
|
+
|
|
6
|
+
Gem::Specification.new do |gem|
|
|
7
|
+
gem.name = "acts-as-taggable-on"
|
|
8
|
+
gem.version = ActsAsTaggableOn::VERSION
|
|
9
|
+
gem.authors = ["Michael Bleigh", "Joost Baaij"]
|
|
10
|
+
gem.email = ["michael@intridea.com", "joost@spacebabies.nl"]
|
|
11
|
+
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.}
|
|
12
|
+
gem.summary = "Advanced tagging for Rails."
|
|
13
|
+
gem.homepage = 'https://github.com/mbleigh/acts-as-taggable-on'
|
|
14
|
+
gem.license = "MIT"
|
|
15
|
+
|
|
16
|
+
gem.files = `git ls-files`.split($/)
|
|
17
|
+
gem.executables = gem.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
|
18
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
|
19
|
+
gem.require_paths = ["lib"]
|
|
20
|
+
|
|
21
|
+
if File.exists?('UPGRADING')
|
|
22
|
+
gem.post_install_message = File.read('UPGRADING')
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
gem.add_runtime_dependency 'rails', ['>= 3', '< 5']
|
|
26
|
+
|
|
27
|
+
gem.add_development_dependency 'sqlite3'
|
|
28
|
+
gem.add_development_dependency 'mysql2', '~> 0.3.7'
|
|
29
|
+
gem.add_development_dependency 'pg'
|
|
30
|
+
|
|
31
|
+
gem.add_development_dependency 'rspec-rails', '2.13.0' # 2.13.1 is broken
|
|
32
|
+
gem.add_development_dependency 'rspec', '~> 2.6'
|
|
33
|
+
gem.add_development_dependency 'ammeter'
|
|
34
|
+
|
|
35
|
+
end
|
|
@@ -12,7 +12,9 @@ class ActsAsTaggableOnMigration < ActiveRecord::Migration
|
|
|
12
12
|
t.references :taggable, :polymorphic => true
|
|
13
13
|
t.references :tagger, :polymorphic => true
|
|
14
14
|
|
|
15
|
-
|
|
15
|
+
# Limit is created to prevent MySQL error on index
|
|
16
|
+
# length for MyISAM table type: http://bit.ly/vgW2Ql
|
|
17
|
+
t.string :context, :limit => 128
|
|
16
18
|
|
|
17
19
|
t.datetime :created_at
|
|
18
20
|
end
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
class AddMissingUniqueIndices < ActiveRecord::Migration
|
|
2
|
+
|
|
3
|
+
def self.up
|
|
4
|
+
add_index :tags, :name, unique: true
|
|
5
|
+
|
|
6
|
+
remove_index :taggings, :tag_id
|
|
7
|
+
remove_index :taggings, [:taggable_id, :taggable_type, :context]
|
|
8
|
+
add_index :taggings,
|
|
9
|
+
[:tag_id, :taggable_id, :taggable_type, :context, :tagger_id, :tagger_type],
|
|
10
|
+
unique: true, name: 'taggings_idx'
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def self.down
|
|
14
|
+
remove_index :tags, :name
|
|
15
|
+
|
|
16
|
+
remove_index :taggings, name: 'tagging_idx'
|
|
17
|
+
add_index :taggings, :tag_id
|
|
18
|
+
add_index :taggings, [:taggable_id, :taggable_type, :context]
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
end
|