acts_as_20ggable 1.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.
Files changed (49) hide show
  1. checksums.yaml +15 -0
  2. data/.gitignore +1 -0
  3. data/CHANGELOG +6 -0
  4. data/Gemfile +3 -0
  5. data/Gemfile.lock +61 -0
  6. data/README +76 -0
  7. data/Rakefile +24 -0
  8. data/acts_as_20ggable.gemspec +26 -0
  9. data/generators/acts_as_20ggable_migration/acts_as_20ggable_migration_generator.rb +11 -0
  10. data/generators/acts_as_20ggable_migration/templates/migration.rb +45 -0
  11. data/lib/acts_as_20ggable.rb +7 -0
  12. data/lib/acts_as_taggable.rb +201 -0
  13. data/lib/tag.rb +146 -0
  14. data/lib/tag_counts_extension.rb +3 -0
  15. data/lib/tag_hierarchy_builder.rb +201 -0
  16. data/lib/tag_list.rb +108 -0
  17. data/lib/tagging.rb +10 -0
  18. data/lib/tags_helper.rb +13 -0
  19. data/test/fixtures/magazine.rb +3 -0
  20. data/test/fixtures/magazines.yml +7 -0
  21. data/test/fixtures/photo.rb +8 -0
  22. data/test/fixtures/photos.yml +24 -0
  23. data/test/fixtures/post.rb +7 -0
  24. data/test/fixtures/posts.yml +34 -0
  25. data/test/fixtures/schema.rb +73 -0
  26. data/test/fixtures/special_post.rb +2 -0
  27. data/test/fixtures/subscription.rb +4 -0
  28. data/test/fixtures/subscriptions.yml +3 -0
  29. data/test/fixtures/taggings.yml +162 -0
  30. data/test/fixtures/tags.yml +75 -0
  31. data/test/fixtures/tags_hierarchy.yml +31 -0
  32. data/test/fixtures/tags_synonyms.yml +16 -0
  33. data/test/fixtures/tags_transitive_hierarchy.yml +96 -0
  34. data/test/fixtures/user.rb +9 -0
  35. data/test/fixtures/users.yml +7 -0
  36. data/test/fixtures/video.rb +3 -0
  37. data/test/fixtures/videos.yml +9 -0
  38. data/test/lib/acts_as_taggable_test.rb +359 -0
  39. data/test/lib/tag_hierarchy_builder_test.rb +109 -0
  40. data/test/lib/tag_list_test.rb +120 -0
  41. data/test/lib/tag_test.rb +45 -0
  42. data/test/lib/tagging_test.rb +14 -0
  43. data/test/lib/tags_helper_test.rb +28 -0
  44. data/test/lib/tags_hierarchy_test.rb +12 -0
  45. data/test/support/activerecord_test_connector.rb +129 -0
  46. data/test/support/custom_asserts.rb +35 -0
  47. data/test/support/database.yml +10 -0
  48. data/test/test_helper.rb +20 -0
  49. metadata +183 -0
@@ -0,0 +1,10 @@
1
+ class Tagging < ActiveRecord::Base
2
+ belongs_to :tag
3
+ belongs_to :taggable, :polymorphic => true
4
+
5
+ after_destroy do
6
+ if Tag.destroy_unused && !tag.taggings.exists?
7
+ tag.destroy
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,13 @@
1
+ module TagsHelper
2
+ # See the README for an example using tag_cloud.
3
+ def tag_cloud(tags, classes)
4
+ return if tags.empty?
5
+
6
+ max_count = tags.sort_by(&:count).last.count.to_f
7
+
8
+ tags.each do |tag|
9
+ index = ((tag.count / max_count) * (classes.size - 1)).round
10
+ yield tag, classes[index]
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,3 @@
1
+ class Magazine < ActiveRecord::Base
2
+ acts_as_taggable
3
+ end
@@ -0,0 +1,7 @@
1
+ ruby:
2
+ id: 1
3
+ name: Ruby
4
+
5
+ rails:
6
+ id: 2
7
+ name: Rails
@@ -0,0 +1,8 @@
1
+ class Photo < ActiveRecord::Base
2
+ acts_as_taggable
3
+
4
+ belongs_to :user
5
+ end
6
+
7
+ class SpecialPhoto < Photo
8
+ end
@@ -0,0 +1,24 @@
1
+ jonathan_dog:
2
+ id: 1
3
+ user_id: 1
4
+ title: A small dog
5
+
6
+ jonathan_questioning_dog:
7
+ id: 2
8
+ user_id: 1
9
+ title: What does this dog want?
10
+
11
+ jonathan_bad_cat:
12
+ id: 3
13
+ user_id: 1
14
+ title: Bad cat
15
+
16
+ sam_flower:
17
+ id: 4
18
+ user_id: 2
19
+ title: Flower
20
+
21
+ sam_sky:
22
+ id: 5
23
+ user_id: 2
24
+ title: Sky
@@ -0,0 +1,7 @@
1
+ class Post < ActiveRecord::Base
2
+ acts_as_taggable
3
+
4
+ belongs_to :user
5
+
6
+ validates_presence_of :text
7
+ end
@@ -0,0 +1,34 @@
1
+ jonathan_sky:
2
+ id: 1
3
+ user_id: 1
4
+ text: The sky is particularly blue today
5
+
6
+ jonathan_grass:
7
+ id: 2
8
+ user_id: 1
9
+ text: The grass seems very green
10
+
11
+ jonathan_rain:
12
+ id: 3
13
+ user_id: 1
14
+ text: Why does the rain fall?
15
+
16
+ jonathan_cloudy:
17
+ id: 4
18
+ user_id: 1
19
+ text: Is it cloudy?
20
+
21
+ jonathan_still_cloudy:
22
+ id: 5
23
+ user_id: 1
24
+ text: Is it still cloudy?
25
+
26
+ sam_ground:
27
+ id: 6
28
+ user_id: 2
29
+ text: The ground is looking too brown
30
+
31
+ sam_flowers:
32
+ id: 7
33
+ user_id: 2
34
+ text: Why are the flowers dead?
@@ -0,0 +1,73 @@
1
+ ActiveRecord::Schema.define :version => 0 do
2
+ create_table :tags, :force => true do |t|
3
+ t.column :name, :string
4
+ end
5
+
6
+ create_table :tags_hierarchy, :force => true, :id => false do |t|
7
+ t.column :tag_id, :integer
8
+ t.column :child_id, :integer
9
+ end
10
+
11
+ create_table :tags_transitive_hierarchy, :force => true, :id => false do |t|
12
+ t.column :tag_id, :integer
13
+ t.column :child_id, :integer
14
+ end
15
+
16
+ create_table :tags_synonyms, :force => true, :id => false do |t|
17
+ t.column :tag_id, :integer
18
+ t.column :synonym_id, :integer
19
+ end
20
+
21
+ create_table :taggings, :force => true do |t|
22
+ t.column :tag_id, :integer
23
+ t.column :taggable_id, :integer
24
+ t.column :taggable_type, :string
25
+ t.column :created_at, :datetime
26
+ end
27
+
28
+ create_table :users, :force => true do |t|
29
+ t.column :name, :string
30
+ end
31
+
32
+ create_table :posts, :force => true do |t|
33
+ t.column :text, :text
34
+ t.column :cached_tag_list, :string
35
+ t.column :user_id, :integer
36
+ t.column :type, :string
37
+ end
38
+
39
+ create_table :photos, :force => true do |t|
40
+ t.column :title, :string
41
+ t.column :user_id, :integer
42
+ end
43
+
44
+ create_table :videos, :force => true do |t|
45
+ t.column :title, :string
46
+ t.column :user_id, :integer
47
+ end
48
+
49
+ create_table :subscriptions, :force => true do |t|
50
+ t.column :user_id, :integer
51
+ t.column :magazine_id, :integer
52
+ end
53
+
54
+ create_table :subscriptions, :force => true do |t|
55
+ t.column :user_id, :integer
56
+ t.column :magazine_id, :integer
57
+ end
58
+
59
+ create_table :magazines, :force => true do |t|
60
+ t.column :name, :string
61
+ end
62
+
63
+ create_table :categories, :force => true do |t|
64
+ t.column :name, :string
65
+ end
66
+
67
+ create_table :categorisations, :force => true do |t|
68
+ t.column :tag_id, :integer
69
+ t.column :taggable_id, :integer
70
+ t.column :taggable_type, :string
71
+ t.column :created_at, :datetime
72
+ end
73
+ end
@@ -0,0 +1,2 @@
1
+ class SpecialPost < Post
2
+ end
@@ -0,0 +1,4 @@
1
+ class Subscription < ActiveRecord::Base
2
+ belongs_to :user
3
+ belongs_to :magazine
4
+ end
@@ -0,0 +1,3 @@
1
+ jonathan_rails:
2
+ user_id: 1
3
+ magazine_id: 1
@@ -0,0 +1,162 @@
1
+ # Posts
2
+ jonathan_sky_good:
3
+ id: 1
4
+ tag_id: 1
5
+ taggable_id: 1
6
+ taggable_type: Post
7
+ created_at: 2006-08-01
8
+
9
+ jonathan_sky_nature:
10
+ id: 2
11
+ tag_id: 3
12
+ taggable_id: 1
13
+ taggable_type: Post
14
+ created_at: 2006-08-02
15
+
16
+ jonathan_grass_nature:
17
+ id: 3
18
+ tag_id: 3
19
+ taggable_id: 2
20
+ taggable_type: Post
21
+ created_at: 2006-08-03
22
+
23
+ jonathan_rain_question:
24
+ id: 4
25
+ tag_id: 4
26
+ taggable_id: 3
27
+ taggable_type: Post
28
+ created_at: 2006-08-04
29
+
30
+ jonathan_rain_nature:
31
+ id: 5
32
+ tag_id: 3
33
+ taggable_id: 3
34
+ taggable_type: Post
35
+ created_at: 2006-08-05
36
+
37
+ jonathan_cloudy_nature:
38
+ id: 6
39
+ tag_id: 3
40
+ taggable_id: 4
41
+ taggable_type: Post
42
+ created_at: 2006-08-06
43
+
44
+ jonathan_still_cloudy_nature:
45
+ id: 7
46
+ tag_id: 3
47
+ taggable_id: 5
48
+ taggable_type: Post
49
+ created_at: 2006-08-07
50
+
51
+ sam_ground_nature:
52
+ id: 8
53
+ tag_id: 3
54
+ taggable_id: 6
55
+ taggable_type: Post
56
+ created_at: 2006-08-08
57
+
58
+ sam_ground_bad:
59
+ id: 9
60
+ tag_id: 2
61
+ taggable_id: 6
62
+ taggable_type: Post
63
+ created_at: 2006-08-09
64
+
65
+ sam_flowers_good:
66
+ id: 10
67
+ tag_id: 1
68
+ taggable_id: 7
69
+ taggable_type: Post
70
+ created_at: 2006-08-10
71
+
72
+ sam_flowers_nature:
73
+ id: 11
74
+ tag_id: 3
75
+ taggable_id: 7
76
+ taggable_type: Post
77
+ created_at: 2006-08-11
78
+
79
+ # Photos
80
+ jonathan_dog_animal:
81
+ id: 12
82
+ tag_id: 5
83
+ taggable_id: 1
84
+ taggable_type: Photo
85
+ created_at: 2006-08-12
86
+
87
+ jonathan_dog_nature:
88
+ id: 13
89
+ tag_id: 3
90
+ taggable_id: 1
91
+ taggable_type: Photo
92
+ created_at: 2006-08-13
93
+
94
+ jonathan_questioning_dog_animal:
95
+ id: 14
96
+ tag_id: 5
97
+ taggable_id: 2
98
+ taggable_type: Photo
99
+ created_at: 2006-08-14
100
+
101
+ jonathan_questioning_dog_question:
102
+ id: 15
103
+ tag_id: 4
104
+ taggable_id: 2
105
+ taggable_type: Photo
106
+ created_at: 2006-08-15
107
+
108
+ jonathan_bad_cat_bad:
109
+ id: 16
110
+ tag_id: 2
111
+ taggable_id: 3
112
+ taggable_type: Photo
113
+ created_at: 2006-08-16
114
+
115
+ jonathan_bad_cat_animal:
116
+ id: 17
117
+ tag_id: 5
118
+ taggable_id: 3
119
+ taggable_type: Photo
120
+ created_at: 2006-08-17
121
+
122
+ sam_flower_nature:
123
+ id: 18
124
+ tag_id: 3
125
+ taggable_id: 4
126
+ taggable_type: Photo
127
+ created_at: 2006-08-18
128
+
129
+ sam_flower_good:
130
+ id: 19
131
+ tag_id: 1
132
+ taggable_id: 4
133
+ taggable_type: Photo
134
+ created_at: 2006-08-19
135
+
136
+ sam_sky_nature:
137
+ id: 20
138
+ tag_id: 3
139
+ taggable_id: 5
140
+ taggable_type: Photo
141
+ created_at: 2006-08-20
142
+
143
+ # Magazines
144
+ ruby_good:
145
+ id: 50
146
+ tag_id: 1
147
+ taggable_id: 1
148
+ taggable_type: Magazine
149
+ created_at: 2007-08-25
150
+
151
+ # Videos
152
+ jonathan_good_cat_cat:
153
+ id: 100
154
+ tag_id: 13
155
+ taggable_id: 1
156
+ taggable_type: Video
157
+
158
+ sam_kitten_kitten:
159
+ id: 101
160
+ tag_id: 14
161
+ taggable_id: 2
162
+ taggable_type: Video
@@ -0,0 +1,75 @@
1
+ good:
2
+ id: 1
3
+ name: Very good
4
+
5
+ bad:
6
+ id: 2
7
+ name: Bad
8
+
9
+ nature:
10
+ id: 3
11
+ name: Nature
12
+
13
+ question:
14
+ id: 4
15
+ name: Question
16
+
17
+ animal:
18
+ id: 5
19
+ name: Crazy animal
20
+
21
+ # Fixture based on http://spectator.ru/technology/web-building/tags2null
22
+ people:
23
+ id: 6
24
+ name: People
25
+
26
+ people_children:
27
+ id: 7
28
+ name: Children
29
+
30
+ people_nude:
31
+ id: 8
32
+ name: Nude
33
+
34
+ people_me:
35
+ id: 9
36
+ name: Me
37
+
38
+ nature_animals:
39
+ id: 10
40
+ name: Animals
41
+
42
+ nature_animals_horse:
43
+ id: 11
44
+ name: Horse
45
+
46
+ nature_animals_domestic:
47
+ id: 12
48
+ name: Domestic Animals
49
+
50
+ nature_animals_domestic_cat:
51
+ id: 13
52
+ name: Cat
53
+
54
+ nature_animals_domestic_cat_kitten:
55
+ id: 14
56
+ name: Kitten
57
+
58
+ cat_synonym_pussy:
59
+ id: 15
60
+ name: Pussy
61
+
62
+ horse_synonym_racehorse:
63
+ id: 16
64
+ name: Racehorse
65
+
66
+ question_synonym_problem:
67
+ id: 17
68
+ name: Problem
69
+
70
+ cat_synonym_kitty:
71
+ id: 18
72
+ name: Kitty
73
+
74
+
75
+
@@ -0,0 +1,31 @@
1
+ people_children:
2
+ tag_id: 6
3
+ child_id: 7
4
+
5
+ people_nude:
6
+ tag_id: 6
7
+ child_id: 8
8
+
9
+ people_me:
10
+ tag_id: 6
11
+ child_id: 9
12
+
13
+ nature_animals:
14
+ tag_id: 3
15
+ child_id: 10
16
+
17
+ nature_animals_horse:
18
+ tag_id: 10
19
+ child_id: 11
20
+
21
+ nature_animals_domestic:
22
+ tag_id: 10
23
+ child_id: 12
24
+
25
+ nature_animals_domestic_cat:
26
+ tag_id: 12
27
+ child_id: 13
28
+
29
+ nature_animals_domestic_cat_kitten:
30
+ tag_id: 13
31
+ child_id: 14