acts-as-taggable-on 0.0.0 → 1.0.6
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/CHANGELOG +2 -9
- data/README +196 -0
- data/Rakefile +10 -47
- data/VERSION +1 -1
- data/lib/acts-as-taggable-on.rb +6 -30
- data/lib/acts_as_taggable_on/acts_as_taggable_on.rb +313 -28
- data/lib/acts_as_taggable_on/acts_as_tagger.rb +45 -40
- data/lib/acts_as_taggable_on/tag.rb +6 -48
- data/lib/acts_as_taggable_on/tag_list.rb +29 -31
- data/lib/acts_as_taggable_on/tagging.rb +1 -18
- data/lib/acts_as_taggable_on/tags_helper.rb +2 -8
- data/rails/init.rb +6 -1
- data/spec/acts_as_taggable_on/acts_as_taggable_on_spec.rb +47 -148
- data/spec/acts_as_taggable_on/acts_as_tagger_spec.rb +4 -46
- data/spec/acts_as_taggable_on/tag_list_spec.rb +0 -29
- data/spec/acts_as_taggable_on/tag_spec.rb +7 -95
- data/spec/acts_as_taggable_on/taggable_spec.rb +48 -178
- data/spec/acts_as_taggable_on/tagger_spec.rb +5 -57
- data/spec/acts_as_taggable_on/tagging_spec.rb +1 -25
- data/spec/schema.rb +2 -12
- data/spec/spec.opts +6 -1
- data/spec/spec_helper.rb +34 -35
- metadata +7 -31
- data/Gemfile +0 -6
- data/README.rdoc +0 -212
- data/lib/acts_as_taggable_on/acts_as_taggable_on/cache.rb +0 -56
- data/lib/acts_as_taggable_on/acts_as_taggable_on/collection.rb +0 -97
- data/lib/acts_as_taggable_on/acts_as_taggable_on/core.rb +0 -220
- data/lib/acts_as_taggable_on/acts_as_taggable_on/dirty.rb +0 -29
- data/lib/acts_as_taggable_on/acts_as_taggable_on/ownership.rb +0 -101
- data/lib/acts_as_taggable_on/acts_as_taggable_on/related.rb +0 -64
- data/lib/acts_as_taggable_on/compatibility/Gemfile +0 -6
- data/lib/acts_as_taggable_on/compatibility/active_record_backports.rb +0 -17
- data/lib/generators/acts_as_taggable_on/migration/migration_generator.rb +0 -31
- data/lib/generators/acts_as_taggable_on/migration/templates/active_record/migration.rb +0 -28
- data/spec/acts_as_taggable_on/tags_helper_spec.rb +0 -28
- data/spec/bm.rb +0 -52
- data/spec/models.rb +0 -36
@@ -2,73 +2,21 @@ require File.dirname(__FILE__) + '/../spec_helper'
|
|
2
2
|
|
3
3
|
describe "Tagger" do
|
4
4
|
before(:each) do
|
5
|
-
|
6
|
-
@user = TaggableUser.
|
7
|
-
@taggable = TaggableModel.
|
5
|
+
[TaggableModel, Tag, Tagging, TaggableUser].each(&:delete_all)
|
6
|
+
@user = TaggableUser.new
|
7
|
+
@taggable = TaggableModel.new(:name => "Bob Jones")
|
8
8
|
end
|
9
|
-
|
9
|
+
|
10
10
|
it "should have taggings" do
|
11
11
|
@user.tag(@taggable, :with=>'ruby,scheme', :on=>:tags)
|
12
12
|
@user.owned_taggings.size == 2
|
13
13
|
end
|
14
|
-
|
14
|
+
|
15
15
|
it "should have tags" do
|
16
16
|
@user.tag(@taggable, :with=>'ruby,scheme', :on=>:tags)
|
17
17
|
@user.owned_tags.size == 2
|
18
18
|
end
|
19
19
|
|
20
|
-
it "should not overlap tags from different taggers" do
|
21
|
-
@user2 = TaggableUser.new
|
22
|
-
lambda{
|
23
|
-
@user.tag(@taggable, :with => 'ruby, scheme', :on => :tags)
|
24
|
-
@user2.tag(@taggable, :with => 'java, python, lisp, ruby', :on => :tags)
|
25
|
-
}.should change(Tagging, :count).by(6)
|
26
|
-
|
27
|
-
[@user, @user2, @taggable].each(&:reload)
|
28
|
-
|
29
|
-
@user.owned_tags.map(&:name).sort.should == %w(ruby scheme).sort
|
30
|
-
@user2.owned_tags.map(&:name).sort.should == %w(java python lisp ruby).sort
|
31
|
-
|
32
|
-
@taggable.tags_from(@user).sort.should == %w(ruby scheme).sort
|
33
|
-
@taggable.tags_from(@user2).sort.should == %w(java lisp python ruby).sort
|
34
|
-
|
35
|
-
@taggable.all_tags_list.sort.should == %w(ruby scheme java python lisp).sort
|
36
|
-
@taggable.all_tags_on(:tags).size.should == 5
|
37
|
-
end
|
38
|
-
|
39
|
-
it "should not lose tags from different taggers" do
|
40
|
-
@user2 = TaggableUser.create
|
41
|
-
@user2.tag(@taggable, :with => 'java, python, lisp, ruby', :on => :tags)
|
42
|
-
@user.tag(@taggable, :with => 'ruby, scheme', :on => :tags)
|
43
|
-
|
44
|
-
lambda {
|
45
|
-
@user2.tag(@taggable, :with => 'java, python, lisp', :on => :tags)
|
46
|
-
}.should change(Tagging, :count).by(-1)
|
47
|
-
|
48
|
-
[@user, @user2, @taggable].each(&:reload)
|
49
|
-
|
50
|
-
@taggable.tags_from(@user).sort.should == %w(ruby scheme).sort
|
51
|
-
@taggable.tags_from(@user2).sort.should == %w(java python lisp).sort
|
52
|
-
|
53
|
-
@taggable.all_tags_list.sort.should == %w(ruby scheme java python lisp).sort
|
54
|
-
@taggable.all_tags_on(:tags).length.should == 5
|
55
|
-
end
|
56
|
-
|
57
|
-
it "should not lose tags" do
|
58
|
-
@user2 = TaggableUser.create
|
59
|
-
|
60
|
-
@user.tag(@taggable, :with => 'awesome', :on => :tags)
|
61
|
-
@user2.tag(@taggable, :with => 'awesome, epic', :on => :tags)
|
62
|
-
|
63
|
-
lambda {
|
64
|
-
@user2.tag(@taggable, :with => 'epic', :on => :tags)
|
65
|
-
}.should change(Tagging, :count).by(-1)
|
66
|
-
|
67
|
-
@taggable.reload
|
68
|
-
@taggable.all_tags_list.should include('awesome')
|
69
|
-
@taggable.all_tags_list.should include('epic')
|
70
|
-
end
|
71
|
-
|
72
20
|
it "is tagger" do
|
73
21
|
@user.is_tagger?.should(be_true)
|
74
22
|
end
|
@@ -2,30 +2,6 @@ require File.dirname(__FILE__) + '/../spec_helper'
|
|
2
2
|
|
3
3
|
describe Tagging do
|
4
4
|
before(:each) do
|
5
|
-
clean_database!
|
6
5
|
@tagging = Tagging.new
|
7
6
|
end
|
8
|
-
|
9
|
-
it "should not be valid with a invalid tag" do
|
10
|
-
@tagging.taggable = TaggableModel.create(:name => "Bob Jones")
|
11
|
-
@tagging.tag = Tag.new(:name => "")
|
12
|
-
@tagging.context = "tags"
|
13
|
-
|
14
|
-
@tagging.should_not be_valid
|
15
|
-
|
16
|
-
if ActiveRecord::VERSION::MAJOR >= 3
|
17
|
-
@tagging.errors[:tag_id].should == ["can't be blank"]
|
18
|
-
else
|
19
|
-
@tagging.errors[:tag_id].should == "can't be blank"
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
it "should not create duplicate taggings" do
|
24
|
-
@taggable = TaggableModel.create(:name => "Bob Jones")
|
25
|
-
@tag = Tag.create(:name => "awesome")
|
26
|
-
|
27
|
-
lambda {
|
28
|
-
2.times { Tagging.create(:taggable => @taggable, :tag => @tag, :context => 'tags') }
|
29
|
-
}.should change(Tagging, :count).by(1)
|
30
|
-
end
|
31
|
-
end
|
7
|
+
end
|
data/spec/schema.rb
CHANGED
@@ -19,24 +19,14 @@ ActiveRecord::Schema.define :version => 0 do
|
|
19
19
|
create_table :taggable_models, :force => true do |t|
|
20
20
|
t.column :name, :string
|
21
21
|
t.column :type, :string
|
22
|
+
#t.column :cached_tag_list, :string
|
22
23
|
end
|
23
|
-
|
24
|
-
create_table :cached_models, :force => true do |t|
|
25
|
-
t.column :name, :string
|
26
|
-
t.column :type, :string
|
27
|
-
t.column :cached_tag_list, :string
|
28
|
-
end
|
29
|
-
|
30
24
|
create_table :taggable_users, :force => true do |t|
|
31
25
|
t.column :name, :string
|
32
26
|
end
|
33
|
-
|
34
27
|
create_table :other_taggable_models, :force => true do |t|
|
35
28
|
t.column :name, :string
|
36
29
|
t.column :type, :string
|
37
|
-
|
38
|
-
|
39
|
-
create_table :untaggable_models, :force => true do |t|
|
40
|
-
t.column :name, :string
|
30
|
+
#t.column :cached_tag_list, :string
|
41
31
|
end
|
42
32
|
end
|
data/spec/spec.opts
CHANGED
data/spec/spec_helper.rb
CHANGED
@@ -1,47 +1,46 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
1
|
+
# require File.dirname(__FILE__) + '/../../../../spec/spec_helper'
|
2
|
+
require 'rubygems'
|
3
|
+
require 'active_support'
|
4
|
+
require 'active_record'
|
5
|
+
require 'spec'
|
6
|
+
|
7
|
+
module Spec::Example::ExampleGroupMethods
|
8
|
+
alias :context :describe
|
9
9
|
end
|
10
10
|
|
11
|
-
|
12
|
-
|
11
|
+
TEST_DATABASE_FILE = File.join(File.dirname(__FILE__), '..', 'test.sqlite3')
|
12
|
+
|
13
|
+
File.unlink(TEST_DATABASE_FILE) if File.exist?(TEST_DATABASE_FILE)
|
14
|
+
ActiveRecord::Base.establish_connection(
|
15
|
+
"adapter" => "sqlite3", "database" => TEST_DATABASE_FILE
|
16
|
+
)
|
17
|
+
|
18
|
+
RAILS_DEFAULT_LOGGER = Logger.new(File.join(File.dirname(__FILE__), "debug.log"))
|
13
19
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
20
|
+
load(File.dirname(__FILE__) + '/schema.rb')
|
21
|
+
|
22
|
+
$: << File.join(File.dirname(__FILE__), '..', 'lib')
|
23
|
+
require File.join(File.dirname(__FILE__), '..', 'init')
|
24
|
+
|
25
|
+
class TaggableModel < ActiveRecord::Base
|
26
|
+
acts_as_taggable_on :tags, :languages
|
27
|
+
acts_as_taggable_on :skills
|
18
28
|
end
|
19
29
|
|
20
|
-
class
|
21
|
-
|
22
|
-
k=Hash.new(0)
|
23
|
-
each {|e| k[e]+=1}
|
24
|
-
k
|
25
|
-
end
|
30
|
+
class OtherTaggableModel < ActiveRecord::Base
|
31
|
+
acts_as_taggable_on :tags, :languages
|
26
32
|
end
|
27
33
|
|
28
|
-
|
29
|
-
|
30
|
-
File.unlink(TEST_DATABASE_FILE) if File.exist?(TEST_DATABASE_FILE)
|
31
|
-
ActiveRecord::Base.establish_connection :adapter => 'sqlite3', :database => TEST_DATABASE_FILE
|
34
|
+
class InheritingTaggableModel < TaggableModel
|
35
|
+
end
|
32
36
|
|
33
|
-
|
34
|
-
|
35
|
-
load(File.dirname(__FILE__) + '/schema.rb')
|
36
|
-
load(File.dirname(__FILE__) + '/models.rb')
|
37
|
+
class AlteredInheritingTaggableModel < TaggableModel
|
38
|
+
acts_as_taggable_on :parts
|
37
39
|
end
|
38
40
|
|
39
|
-
|
40
|
-
|
41
|
-
AlteredInheritingTaggableModel, TaggableUser, UntaggableModel]
|
42
|
-
models.each do |model|
|
43
|
-
model.destroy_all
|
44
|
-
end
|
41
|
+
class TaggableUser < ActiveRecord::Base
|
42
|
+
acts_as_tagger
|
45
43
|
end
|
46
44
|
|
47
|
-
|
45
|
+
class UntaggableModel < ActiveRecord::Base
|
46
|
+
end
|
metadata
CHANGED
@@ -1,12 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: acts-as-taggable-on
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
segments:
|
6
|
-
- 0
|
7
|
-
- 0
|
8
|
-
- 0
|
9
|
-
version: 0.0.0
|
4
|
+
version: 1.0.6
|
10
5
|
platform: ruby
|
11
6
|
authors:
|
12
7
|
- Michael Bleigh
|
@@ -14,7 +9,7 @@ autorequire:
|
|
14
9
|
bindir: bin
|
15
10
|
cert_chain: []
|
16
11
|
|
17
|
-
date:
|
12
|
+
date: 2009-10-14 00:00:00 -04:00
|
18
13
|
default_executable:
|
19
14
|
dependencies: []
|
20
15
|
|
@@ -25,31 +20,20 @@ executables: []
|
|
25
20
|
extensions: []
|
26
21
|
|
27
22
|
extra_rdoc_files:
|
28
|
-
- README
|
23
|
+
- README
|
29
24
|
files:
|
30
25
|
- CHANGELOG
|
31
|
-
- Gemfile
|
32
26
|
- MIT-LICENSE
|
33
|
-
- README
|
27
|
+
- README
|
34
28
|
- Rakefile
|
35
29
|
- VERSION
|
36
30
|
- lib/acts-as-taggable-on.rb
|
37
31
|
- lib/acts_as_taggable_on/acts_as_taggable_on.rb
|
38
|
-
- lib/acts_as_taggable_on/acts_as_taggable_on/cache.rb
|
39
|
-
- lib/acts_as_taggable_on/acts_as_taggable_on/collection.rb
|
40
|
-
- lib/acts_as_taggable_on/acts_as_taggable_on/core.rb
|
41
|
-
- lib/acts_as_taggable_on/acts_as_taggable_on/dirty.rb
|
42
|
-
- lib/acts_as_taggable_on/acts_as_taggable_on/ownership.rb
|
43
|
-
- lib/acts_as_taggable_on/acts_as_taggable_on/related.rb
|
44
32
|
- lib/acts_as_taggable_on/acts_as_tagger.rb
|
45
|
-
- lib/acts_as_taggable_on/compatibility/Gemfile
|
46
|
-
- lib/acts_as_taggable_on/compatibility/active_record_backports.rb
|
47
33
|
- lib/acts_as_taggable_on/tag.rb
|
48
34
|
- lib/acts_as_taggable_on/tag_list.rb
|
49
35
|
- lib/acts_as_taggable_on/tagging.rb
|
50
36
|
- lib/acts_as_taggable_on/tags_helper.rb
|
51
|
-
- lib/generators/acts_as_taggable_on/migration/migration_generator.rb
|
52
|
-
- lib/generators/acts_as_taggable_on/migration/templates/active_record/migration.rb
|
53
37
|
- rails/init.rb
|
54
38
|
- spec/acts_as_taggable_on/acts_as_taggable_on_spec.rb
|
55
39
|
- spec/acts_as_taggable_on/acts_as_tagger_spec.rb
|
@@ -58,9 +42,6 @@ files:
|
|
58
42
|
- spec/acts_as_taggable_on/taggable_spec.rb
|
59
43
|
- spec/acts_as_taggable_on/tagger_spec.rb
|
60
44
|
- spec/acts_as_taggable_on/tagging_spec.rb
|
61
|
-
- spec/acts_as_taggable_on/tags_helper_spec.rb
|
62
|
-
- spec/bm.rb
|
63
|
-
- spec/models.rb
|
64
45
|
- spec/schema.rb
|
65
46
|
- spec/spec.opts
|
66
47
|
- spec/spec_helper.rb
|
@@ -77,20 +58,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
77
58
|
requirements:
|
78
59
|
- - ">="
|
79
60
|
- !ruby/object:Gem::Version
|
80
|
-
segments:
|
81
|
-
- 0
|
82
61
|
version: "0"
|
62
|
+
version:
|
83
63
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
84
64
|
requirements:
|
85
65
|
- - ">="
|
86
66
|
- !ruby/object:Gem::Version
|
87
|
-
segments:
|
88
|
-
- 0
|
89
67
|
version: "0"
|
68
|
+
version:
|
90
69
|
requirements: []
|
91
70
|
|
92
71
|
rubyforge_project:
|
93
|
-
rubygems_version: 1.3.
|
72
|
+
rubygems_version: 1.3.5
|
94
73
|
signing_key:
|
95
74
|
specification_version: 3
|
96
75
|
summary: ActsAsTaggableOn is a tagging plugin for Rails that provides multiple tagging contexts on a single model.
|
@@ -102,8 +81,5 @@ test_files:
|
|
102
81
|
- spec/acts_as_taggable_on/taggable_spec.rb
|
103
82
|
- spec/acts_as_taggable_on/tagger_spec.rb
|
104
83
|
- spec/acts_as_taggable_on/tagging_spec.rb
|
105
|
-
- spec/acts_as_taggable_on/tags_helper_spec.rb
|
106
|
-
- spec/bm.rb
|
107
|
-
- spec/models.rb
|
108
84
|
- spec/schema.rb
|
109
85
|
- spec/spec_helper.rb
|
data/Gemfile
DELETED
data/README.rdoc
DELETED
@@ -1,212 +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
|
-
=== Plugin
|
19
|
-
|
20
|
-
Acts As Taggable On is available both as a gem and as a traditional plugin. For the
|
21
|
-
traditional plugin you can install like so (Rails 2.1 or later):
|
22
|
-
|
23
|
-
script/plugin install git://github.com/mbleigh/acts-as-taggable-on.git
|
24
|
-
|
25
|
-
=== GemPlugin
|
26
|
-
|
27
|
-
Acts As Taggable On is also available as a gem plugin using Rails 2.1's gem dependencies.
|
28
|
-
To install the gem, add this to your config/environment.rb:
|
29
|
-
|
30
|
-
config.gem "acts-as-taggable-on", :source => "http://gemcutter.org"
|
31
|
-
|
32
|
-
After that, you can run "rake gems:install" to install the gem if you don't already have it.
|
33
|
-
|
34
|
-
== Rails 3.0
|
35
|
-
|
36
|
-
Acts As Taggable On is now useable in Rails 3.0, thanks to the excellent work of Szymon Nowak
|
37
|
-
and Jelle Vandebeeck. Because backwards compatibility is hard to maintain, their work is available
|
38
|
-
in the feature/rails3_compatibility branch.
|
39
|
-
|
40
|
-
A Rails 3.0 compatible version of the gem is also available:
|
41
|
-
|
42
|
-
gem install acts-as-taggable-on -v=2.0.0.pre1
|
43
|
-
|
44
|
-
=== Post Installation (Rails)
|
45
|
-
|
46
|
-
1. script/generate acts_as_taggable_on_migration
|
47
|
-
2. rake db:migrate
|
48
|
-
|
49
|
-
=== Testing
|
50
|
-
|
51
|
-
Acts As Taggable On uses RSpec for its test coverage. Inside the plugin
|
52
|
-
directory, you can run the specs with:
|
53
|
-
|
54
|
-
rake spec
|
55
|
-
|
56
|
-
If you already have RSpec on your application, the specs will run while using:
|
57
|
-
|
58
|
-
rake spec:plugins
|
59
|
-
|
60
|
-
|
61
|
-
== Usage
|
62
|
-
|
63
|
-
class User < ActiveRecord::Base
|
64
|
-
acts_as_taggable_on :tags, :skills, :interests
|
65
|
-
end
|
66
|
-
|
67
|
-
@user = User.new(:name => "Bobby")
|
68
|
-
@user.tag_list = "awesome, slick, hefty" # this should be familiar
|
69
|
-
@user.skill_list = "joking, clowning, boxing" # but you can do it for any context!
|
70
|
-
@user.skill_list # => ["joking","clowning","boxing"] as TagList
|
71
|
-
@user.save
|
72
|
-
|
73
|
-
@user.tags # => [<Tag name:"awesome">,<Tag name:"slick">,<Tag name:"hefty">]
|
74
|
-
@user.skills # => [<Tag name:"joking">,<Tag name:"clowning">,<Tag name:"boxing">]
|
75
|
-
|
76
|
-
# The old way
|
77
|
-
User.find_tagged_with("awesome", :on => :tags) # => [@user]
|
78
|
-
User.find_tagged_with("awesome", :on => :skills) # => []
|
79
|
-
|
80
|
-
# The better way (utilizes named_scope)
|
81
|
-
User.tagged_with("awesome", :on => :tags) # => [@user]
|
82
|
-
User.tagged_with("awesome", :on => :skills) # => []
|
83
|
-
|
84
|
-
@frankie = User.create(:name => "Frankie", :skill_list => "joking, flying, eating")
|
85
|
-
User.skill_counts # => [<Tag name="joking" count=2>,<Tag name="clowning" count=1>...]
|
86
|
-
@frankie.skill_counts
|
87
|
-
|
88
|
-
=== Finding Tagged Objects
|
89
|
-
|
90
|
-
Acts As Taggable On utilizes Rails 2.1's named_scope to create an association
|
91
|
-
for tags. This way you can mix and match to filter down your results, and it
|
92
|
-
also improves compatibility with the will_paginate gem:
|
93
|
-
|
94
|
-
class User < ActiveRecord::Base
|
95
|
-
acts_as_taggable_on :tags
|
96
|
-
named_scope :by_join_date, :order => "created_at DESC"
|
97
|
-
end
|
98
|
-
|
99
|
-
User.tagged_with("awesome").by_date
|
100
|
-
User.tagged_with("awesome").by_date.paginate(:page => params[:page], :per_page => 20)
|
101
|
-
|
102
|
-
#Find a user with matching all tags, not just one
|
103
|
-
User.tagged_with(["awesome", "cool"], :match_all => :true)
|
104
|
-
|
105
|
-
=== Relationships
|
106
|
-
|
107
|
-
You can find objects of the same type based on similar tags on certain contexts.
|
108
|
-
Also, objects will be returned in descending order based on the total number of
|
109
|
-
matched tags.
|
110
|
-
|
111
|
-
@bobby = User.find_by_name("Bobby")
|
112
|
-
@bobby.skill_list # => ["jogging", "diving"]
|
113
|
-
|
114
|
-
@frankie = User.find_by_name("Frankie")
|
115
|
-
@frankie.skill_list # => ["hacking"]
|
116
|
-
|
117
|
-
@tom = User.find_by_name("Tom")
|
118
|
-
@tom.skill_list # => ["hacking", "jogging", "diving"]
|
119
|
-
|
120
|
-
@tom.find_related_skills # => [<User name="Bobby">,<User name="Frankie">]
|
121
|
-
@bobby.find_related_skills # => [<User name="Tom">]
|
122
|
-
@frankie.find_related_skills # => [<User name="Tom">]
|
123
|
-
|
124
|
-
=== Dynamic Tag Contexts
|
125
|
-
|
126
|
-
In addition to the generated tag contexts in the definition, it is also possible
|
127
|
-
to allow for dynamic tag contexts (this could be user generated tag contexts!)
|
128
|
-
|
129
|
-
@user = User.new(:name => "Bobby")
|
130
|
-
@user.set_tag_list_on(:customs, "same, as, tag, list")
|
131
|
-
@user.tag_list_on(:customs) # => ["same","as","tag","list"]
|
132
|
-
@user.save
|
133
|
-
@user.tags_on(:customs) # => [<Tag name='same'>,...]
|
134
|
-
@user.tag_counts_on(:customs)
|
135
|
-
User.find_tagged_with("same", :on => :customs) # => [@user]
|
136
|
-
|
137
|
-
=== Tag Ownership
|
138
|
-
|
139
|
-
Tags can have owners:
|
140
|
-
|
141
|
-
class User < ActiveRecord::Base
|
142
|
-
acts_as_tagger
|
143
|
-
end
|
144
|
-
|
145
|
-
class Photo < ActiveRecord::Base
|
146
|
-
acts_as_taggable_on :locations
|
147
|
-
end
|
148
|
-
|
149
|
-
@some_user.tag(@some_photo, :with => "paris, normandy", :on => :locations)
|
150
|
-
@some_user.owned_taggings
|
151
|
-
@some_user.owned_tags
|
152
|
-
@some_photo.locations_from(@some_user)
|
153
|
-
|
154
|
-
=== Tag cloud calculations
|
155
|
-
|
156
|
-
To construct tag clouds, the frequency of each tag needs to be calculated.
|
157
|
-
Because we specified +acts_as_taggable_on+ on the <tt>User</tt> class, we can
|
158
|
-
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
|
159
|
-
an single user's posts? To achieve this we call tag_counts on the association:
|
160
|
-
|
161
|
-
User.find(:first).posts.tag_counts_on(:tags)
|
162
|
-
|
163
|
-
A helper is included to assist with generating tag clouds.
|
164
|
-
|
165
|
-
Here is an example that generates a tag cloud.
|
166
|
-
|
167
|
-
Helper:
|
168
|
-
|
169
|
-
module PostsHelper
|
170
|
-
include TagsHelper
|
171
|
-
end
|
172
|
-
|
173
|
-
Controller:
|
174
|
-
|
175
|
-
class PostController < ApplicationController
|
176
|
-
def tag_cloud
|
177
|
-
@tags = Post.tag_counts_on(:tags)
|
178
|
-
end
|
179
|
-
end
|
180
|
-
|
181
|
-
View:
|
182
|
-
|
183
|
-
<% tag_cloud(@tags, %w(css1 css2 css3 css4)) do |tag, css_class| %>
|
184
|
-
<%= link_to tag.name, { :action => :tag, :id => tag.name }, :class => css_class %>
|
185
|
-
<% end %>
|
186
|
-
|
187
|
-
CSS:
|
188
|
-
|
189
|
-
.css1 { font-size: 1.0em; }
|
190
|
-
.css2 { font-size: 1.2em; }
|
191
|
-
.css3 { font-size: 1.4em; }
|
192
|
-
.css4 { font-size: 1.6em; }
|
193
|
-
|
194
|
-
== Contributors
|
195
|
-
|
196
|
-
* TomEric (i76) - Maintainer
|
197
|
-
* Michael Bleigh - Original Author
|
198
|
-
* Brendan Lim - Related Objects
|
199
|
-
* Pradeep Elankumaran - Taggers
|
200
|
-
* Sinclair Bain - Patch King
|
201
|
-
|
202
|
-
== Patch Contributors
|
203
|
-
|
204
|
-
* tristanzdunn - Related objects of other classes
|
205
|
-
* azabaj - Fixed migrate down
|
206
|
-
* Peter Cooper - named_scope fix
|
207
|
-
* slainer68 - STI fix
|
208
|
-
* harrylove - migration instructions and fix-ups
|
209
|
-
* lawrencepit - cached tag work
|
210
|
-
* sobrinho - fixed tag_cloud helper
|
211
|
-
|
212
|
-
Copyright (c) 2007-2009 Michael Bleigh (http://mbleigh.com/) and Intridea Inc. (http://intridea.com/), released under the MIT license
|