acts-as-taggable-on 0.0.0 → 1.0.6
Sign up to get free protection for your applications and to get access to all the features.
- 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
@@ -1,64 +0,0 @@
|
|
1
|
-
module ActsAsTaggableOn::Taggable
|
2
|
-
module Related
|
3
|
-
def self.included(base)
|
4
|
-
base.send :include, ActsAsTaggableOn::Taggable::Related::InstanceMethods
|
5
|
-
base.extend ActsAsTaggableOn::Taggable::Related::ClassMethods
|
6
|
-
end
|
7
|
-
|
8
|
-
module ClassMethods
|
9
|
-
def initialize_acts_as_taggable_on_related
|
10
|
-
tag_types.map(&:to_s).each do |tag_type|
|
11
|
-
class_eval %(
|
12
|
-
def find_related_#{tag_type}(options = {})
|
13
|
-
related_tags_for('#{tag_type}', self.class, options)
|
14
|
-
end
|
15
|
-
alias_method :find_related_on_#{tag_type}, :find_related_#{tag_type}
|
16
|
-
|
17
|
-
def find_related_#{tag_type}_for(klass, options = {})
|
18
|
-
related_tags_for('#{tag_type}', klass, options)
|
19
|
-
end
|
20
|
-
|
21
|
-
def find_matching_contexts(search_context, result_context, options = {})
|
22
|
-
matching_contexts_for(search_context.to_s, result_context.to_s, self.class, options)
|
23
|
-
end
|
24
|
-
|
25
|
-
def find_matching_contexts_for(klass, search_context, result_context, options = {})
|
26
|
-
matching_contexts_for(search_context.to_s, result_context.to_s, klass, options)
|
27
|
-
end
|
28
|
-
)
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
def acts_as_taggable_on(*args)
|
33
|
-
super(*args)
|
34
|
-
initialize_acts_as_taggable_on_related
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
module InstanceMethods
|
39
|
-
def matching_contexts_for(search_context, result_context, klass, options = {})
|
40
|
-
tags_to_find = tags_on(search_context).collect { |t| t.name }
|
41
|
-
|
42
|
-
exclude_self = "#{klass.table_name}.id != #{id} AND" if self.class == klass
|
43
|
-
|
44
|
-
klass.scoped({ :select => "#{klass.table_name}.*, COUNT(#{Tag.table_name}.id) AS count",
|
45
|
-
:from => "#{klass.table_name}, #{Tag.table_name}, #{Tagging.table_name}",
|
46
|
-
:conditions => ["#{exclude_self} #{klass.table_name}.id = #{Tagging.table_name}.taggable_id AND #{Tagging.table_name}.taggable_type = '#{klass.to_s}' AND #{Tagging.table_name}.tag_id = #{Tag.table_name}.id AND #{Tag.table_name}.name IN (?) AND #{Tagging.table_name}.context = ?", tags_to_find, result_context],
|
47
|
-
:group => grouped_column_names_for(klass),
|
48
|
-
:order => "count DESC" }.update(options))
|
49
|
-
end
|
50
|
-
|
51
|
-
def related_tags_for(context, klass, options = {})
|
52
|
-
tags_to_find = tags_on(context).collect { |t| t.name }
|
53
|
-
|
54
|
-
exclude_self = "#{klass.table_name}.id != #{id} AND" if self.class == klass
|
55
|
-
|
56
|
-
klass.scoped({ :select => "#{klass.table_name}.*, COUNT(#{Tag.table_name}.id) AS count",
|
57
|
-
:from => "#{klass.table_name}, #{Tag.table_name}, #{Tagging.table_name}",
|
58
|
-
:conditions => ["#{exclude_self} #{klass.table_name}.id = #{Tagging.table_name}.taggable_id AND #{Tagging.table_name}.taggable_type = '#{klass.to_s}' AND #{Tagging.table_name}.tag_id = #{Tag.table_name}.id AND #{Tag.table_name}.name IN (?)", tags_to_find],
|
59
|
-
:group => grouped_column_names_for(klass),
|
60
|
-
:order => "count DESC" }.update(options))
|
61
|
-
end
|
62
|
-
end
|
63
|
-
end
|
64
|
-
end
|
@@ -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,31 +0,0 @@
|
|
1
|
-
require 'rails/generators/migration'
|
2
|
-
|
3
|
-
module ActsAsTaggableOn
|
4
|
-
class MigrationGenerator < Rails::Generators::Base
|
5
|
-
include Rails::Generators::Migration
|
6
|
-
|
7
|
-
desc "Generates migration for Tag and Tagging models"
|
8
|
-
|
9
|
-
def self.orm
|
10
|
-
Rails::Generators.options[:rails][:orm]
|
11
|
-
end
|
12
|
-
|
13
|
-
def self.source_root
|
14
|
-
File.join(File.dirname(__FILE__), 'templates', orm)
|
15
|
-
end
|
16
|
-
|
17
|
-
def self.orm_has_migration?
|
18
|
-
[:active_record].include? orm
|
19
|
-
end
|
20
|
-
|
21
|
-
def self.next_migration_number(path)
|
22
|
-
Time.now.utc.strftime("%Y%m%d%H%M%S")
|
23
|
-
end
|
24
|
-
|
25
|
-
def create_migration_file
|
26
|
-
if self.class.orm_has_migration?
|
27
|
-
migration_template 'migration.rb', 'db/migrate/acts_as_taggable_on_migration'
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
@@ -1,28 +0,0 @@
|
|
1
|
-
class ActsAsTaggableOnMigration < ActiveRecord::Migration
|
2
|
-
def self.up
|
3
|
-
create_table :tags do |t|
|
4
|
-
t.string :name
|
5
|
-
end
|
6
|
-
|
7
|
-
create_table :taggings do |t|
|
8
|
-
t.references :tag
|
9
|
-
|
10
|
-
# You should make sure that the column created is
|
11
|
-
# long enough to store the required class names.
|
12
|
-
t.references :taggable, :polymorphic => true
|
13
|
-
t.references :tagger, :polymorphic => true
|
14
|
-
|
15
|
-
t.string :context
|
16
|
-
|
17
|
-
t.datetime :created_at
|
18
|
-
end
|
19
|
-
|
20
|
-
add_index :taggings, :tag_id
|
21
|
-
add_index :taggings, [:taggable_id, :taggable_type, :context]
|
22
|
-
end
|
23
|
-
|
24
|
-
def self.down
|
25
|
-
drop_table :taggings
|
26
|
-
drop_table :tags
|
27
|
-
end
|
28
|
-
end
|
@@ -1,28 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
-
|
3
|
-
describe TagsHelper do
|
4
|
-
before(:each) do
|
5
|
-
clean_database!
|
6
|
-
|
7
|
-
@bob = TaggableModel.create(:name => "Bob Jones", :language_list => "ruby, php")
|
8
|
-
@tom = TaggableModel.create(:name => "Tom Marley", :language_list => "ruby, java")
|
9
|
-
@eve = TaggableModel.create(:name => "Eve Nodd", :language_list => "ruby, c++")
|
10
|
-
|
11
|
-
@helper = class Helper
|
12
|
-
include TagsHelper
|
13
|
-
end.new
|
14
|
-
end
|
15
|
-
|
16
|
-
it "should yield the proper css classes" do
|
17
|
-
tags = { }
|
18
|
-
|
19
|
-
@helper.tag_cloud(TaggableModel.tag_counts_on(:languages), ["sucky", "awesome"]) do |tag, css_class|
|
20
|
-
tags[tag.name] = css_class
|
21
|
-
end
|
22
|
-
|
23
|
-
tags["ruby"].should == "awesome"
|
24
|
-
tags["java"].should == "sucky"
|
25
|
-
tags["c++"].should == "sucky"
|
26
|
-
tags["php"].should == "sucky"
|
27
|
-
end
|
28
|
-
end
|
data/spec/bm.rb
DELETED
@@ -1,52 +0,0 @@
|
|
1
|
-
require 'active_record'
|
2
|
-
require 'action_view'
|
3
|
-
require File.expand_path('../../lib/acts-as-taggable-on', __FILE__)
|
4
|
-
|
5
|
-
if defined?(ActiveRecord::Acts::TaggableOn)
|
6
|
-
ActiveRecord::Base.send :include, ActiveRecord::Acts::TaggableOn
|
7
|
-
ActiveRecord::Base.send :include, ActiveRecord::Acts::Tagger
|
8
|
-
ActionView::Base.send :include, TagsHelper if defined?(ActionView::Base)
|
9
|
-
end
|
10
|
-
|
11
|
-
TEST_DATABASE_FILE = File.join(File.dirname(__FILE__), '..', 'test.sqlite3')
|
12
|
-
File.unlink(TEST_DATABASE_FILE) if File.exist?(TEST_DATABASE_FILE)
|
13
|
-
ActiveRecord::Base.establish_connection :adapter => 'sqlite3', :database => TEST_DATABASE_FILE
|
14
|
-
|
15
|
-
ActiveRecord::Base.silence do
|
16
|
-
ActiveRecord::Migration.verbose = false
|
17
|
-
ActiveRecord::Schema.define :version => 0 do
|
18
|
-
create_table "taggings", :force => true do |t|
|
19
|
-
t.integer "tag_id", :limit => 11
|
20
|
-
t.integer "taggable_id", :limit => 11
|
21
|
-
t.string "taggable_type"
|
22
|
-
t.string "context"
|
23
|
-
t.datetime "created_at"
|
24
|
-
t.integer "tagger_id", :limit => 11
|
25
|
-
t.string "tagger_type"
|
26
|
-
end
|
27
|
-
|
28
|
-
add_index "taggings", ["tag_id"], :name => "index_taggings_on_tag_id"
|
29
|
-
add_index "taggings", ["taggable_id", "taggable_type", "context"], :name => "index_taggings_on_taggable_id_and_taggable_type_and_context"
|
30
|
-
|
31
|
-
create_table "tags", :force => true do |t|
|
32
|
-
t.string "name"
|
33
|
-
end
|
34
|
-
|
35
|
-
create_table :taggable_models, :force => true do |t|
|
36
|
-
t.column :name, :string
|
37
|
-
t.column :type, :string
|
38
|
-
t.column :cached_tag_list, :string
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
class TaggableModel < ActiveRecord::Base
|
43
|
-
acts_as_taggable
|
44
|
-
acts_as_taggable_on :languages
|
45
|
-
acts_as_taggable_on :skills
|
46
|
-
acts_as_taggable_on :needs, :offerings
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
puts Benchmark.measure {
|
51
|
-
1000.times { TaggableModel.create :tag_list => "awesome, epic, neat" }
|
52
|
-
}
|
data/spec/models.rb
DELETED
@@ -1,36 +0,0 @@
|
|
1
|
-
class TaggableModel < ActiveRecord::Base
|
2
|
-
acts_as_taggable
|
3
|
-
acts_as_taggable_on :languages
|
4
|
-
acts_as_taggable_on :skills
|
5
|
-
acts_as_taggable_on :needs, :offerings
|
6
|
-
end
|
7
|
-
|
8
|
-
class CachedModel < ActiveRecord::Base
|
9
|
-
acts_as_taggable
|
10
|
-
end
|
11
|
-
|
12
|
-
class OtherTaggableModel < ActiveRecord::Base
|
13
|
-
acts_as_taggable_on :tags, :languages
|
14
|
-
acts_as_taggable_on :needs, :offerings
|
15
|
-
end
|
16
|
-
|
17
|
-
class InheritingTaggableModel < TaggableModel
|
18
|
-
end
|
19
|
-
|
20
|
-
class AlteredInheritingTaggableModel < TaggableModel
|
21
|
-
acts_as_taggable_on :parts
|
22
|
-
end
|
23
|
-
|
24
|
-
class TaggableUser < ActiveRecord::Base
|
25
|
-
acts_as_tagger
|
26
|
-
end
|
27
|
-
|
28
|
-
class UntaggableModel < ActiveRecord::Base
|
29
|
-
end
|
30
|
-
|
31
|
-
# if ActiveRecord::VERSION::MAJOR < 3
|
32
|
-
# [TaggableModel, CachedModel, OtherTaggableModel, InheritingTaggableModel,
|
33
|
-
# AlteredInheritingTaggableModel, TaggableUser, UntaggableModel].each do |klass|
|
34
|
-
# klass.send(:include, ActsAsTaggableOn::ActiveRecord::Backports)
|
35
|
-
# end
|
36
|
-
# end
|