enju_bookmark 0.0.20 → 0.0.21

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,37 @@
1
+ module EnjuBookmark
2
+ module BookmarkHelper
3
+ def link_to_tag(tag)
4
+ link_to tag, manifestations_path(:tag => tag.name)
5
+ end
6
+
7
+ def render_tag_cloud(tags, options = {})
8
+ return nil if tags.nil?
9
+ # TODO: add options to specify different limits and sorts
10
+ #tags = Tag.all(:limit => 100, :order => 'taggings_count DESC').sort_by(&:name)
11
+
12
+ # TODO: add option to specify which classes you want and overide this if you want?
13
+ classes = %w(popular v-popular vv-popular vvv-popular vvvv-popular)
14
+
15
+ max, min = 0, 0
16
+ tags.each do |tag|
17
+ #if options[:max] or options[:min]
18
+ # max = options[:max].to_i
19
+ # min = options[:min].to_i
20
+ #end
21
+ max = tag.taggings.size if tag.taggings.size > max
22
+ min = tag.taggings.size if tag.taggings.size < min
23
+ end
24
+ divisor = ((max - min).div(classes.size)) + 1
25
+
26
+ content_tag :div, :class => "hTagcloud" do
27
+ content_tag :ul, :class => "popularity" do
28
+ tags.each do |tag|
29
+ content_tag :li do
30
+ link_to(tag.name, manifestations_path(:tag => tag.name), :class => classes[(tag.taggings.size - min).div(divisor)])
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,15 @@
1
+ module SuggestTag
2
+ def suggest_tags
3
+ tags = []
4
+ threshold = (self.strip.split(//).size * 0.2).round
5
+ Bookmark.tag_counts(:limit => 100).each do |t|
6
+ distance = Text::Levenshtein.distance(t.name, self)
7
+ tags << t if distance <= threshold
8
+ end
9
+ tags
10
+ end
11
+ end
12
+
13
+ class String
14
+ include SuggestTag
15
+ end
@@ -0,0 +1,26 @@
1
+ module EnjuBookmark
2
+ module BookmarkUser
3
+ def self.included(base)
4
+ base.extend ClassMethods
5
+ end
6
+
7
+ module ClassMethods
8
+ def enju_bookmark_user
9
+ include InstanceMethods
10
+ has_many :bookmarks, :dependent => :destroy
11
+ acts_as_tagger
12
+ end
13
+ end
14
+
15
+ module InstanceMethods
16
+ def owned_tags_by_solr
17
+ bookmark_ids = bookmarks.collect(&:id)
18
+ if bookmark_ids.empty?
19
+ []
20
+ else
21
+ Tag.bookmarked(bookmark_ids)
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -1,3 +1,3 @@
1
1
  module EnjuBookmark
2
- VERSION = "0.0.20"
2
+ VERSION = "0.0.21"
3
3
  end
data/lib/enju_bookmark.rb CHANGED
@@ -1,7 +1,12 @@
1
1
  require "enju_bookmark/engine"
2
+ require "enju_bookmark/user"
2
3
  require "enju_bookmark/bookmark_url"
3
4
  require "enju_bookmark/calculate_stat"
4
5
  require "enju_bookmark/expire_tag_cloud"
6
+ #require "enju_bookmark/suggest_tag"
7
+ require "enju_bookmark/bookmark_helper"
5
8
 
6
9
  module EnjuBookmark
7
10
  end
11
+
12
+ ActiveRecord::Base.send :include, EnjuBookmark::BookmarkUser
@@ -10,16 +10,8 @@ class User < ActiveRecord::Base
10
10
  has_one :user_has_role
11
11
  has_one :role, :through => :user_has_role
12
12
  belongs_to :required_role, :class_name => 'Role', :foreign_key => 'required_role_id'
13
- has_many :bookmarks, :dependent => :destroy
14
13
 
15
- def owned_tags_by_solr
16
- bookmark_ids = bookmarks.collect(&:id)
17
- if bookmark_ids.empty?
18
- []
19
- else
20
- Tag.bookmarked(bookmark_ids)
21
- end
22
- end
14
+ enju_bookmark_user
23
15
 
24
16
  def has_role?(role_in_question)
25
17
  return false unless role
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: enju_bookmark
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.20
4
+ version: 0.0.21
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-06-19 00:00:00.000000000 Z
12
+ date: 2012-06-22 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -240,10 +240,13 @@ files:
240
240
  - db/migrate/20100222124420_add_allow_bookmark_external_url_to_library_group.rb
241
241
  - db/migrate/20100525171356_acts_as_taggable_on_migration.rb
242
242
  - db/migrate/20111231145823_add_share_bookmarks_to_user.rb
243
+ - lib/enju_bookmark/bookmark_helper.rb
243
244
  - lib/enju_bookmark/bookmark_url.rb
244
245
  - lib/enju_bookmark/calculate_stat.rb
245
246
  - lib/enju_bookmark/engine.rb
246
247
  - lib/enju_bookmark/expire_tag_cloud.rb
248
+ - lib/enju_bookmark/suggest_tag.rb
249
+ - lib/enju_bookmark/user.rb
247
250
  - lib/enju_bookmark/version.rb
248
251
  - lib/enju_bookmark.rb
249
252
  - lib/tasks/enju_bookmark_tasks.rake