tagcloudbase 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/tagcloudbase.rb +6 -6
- data/lib/tagcloudbase.rb~ +15 -3
- metadata +1 -1
data/lib/tagcloudbase.rb
CHANGED
@@ -11,18 +11,18 @@ class TagCloudBase
|
|
11
11
|
attr_accessor :xsl
|
12
12
|
|
13
13
|
def initialize(all_tags={})
|
14
|
-
tags = all_tags.sort_by {|
|
15
|
-
biggest_tag = tags.first[1].to_i
|
16
|
-
|
14
|
+
tags = all_tags.sort_by {|x| -x[-1][-1].to_i}
|
15
|
+
biggest_tag = tags.first[-1][-1].to_i
|
17
16
|
# sort in alphabetical order
|
18
17
|
abc_tags = tags.sort_by &:first
|
19
18
|
|
20
19
|
@to_dynarex = Dynarex.new('tags/tag(word,href,gauge,count)')
|
21
|
-
abc_tags.each do |word,
|
20
|
+
abc_tags.each do |word, v|
|
21
|
+
href, word_size = v
|
22
22
|
weight = 100 / (biggest_tag / word_size.to_i)
|
23
23
|
gauge = (weight / 10).to_i
|
24
24
|
gauge = 8 if gauge > 8
|
25
|
-
@to_dynarex.create word: word, gauge: gauge.to_s, count: word_size
|
25
|
+
@to_dynarex.create word: word, href: href, gauge: gauge.to_s, count: word_size
|
26
26
|
end
|
27
27
|
end
|
28
28
|
|
@@ -36,4 +36,4 @@ class TagCloudBase
|
|
36
36
|
return {html: html, css: css}
|
37
37
|
end
|
38
38
|
|
39
|
-
end
|
39
|
+
end
|
data/lib/tagcloudbase.rb~
CHANGED
@@ -3,10 +3,12 @@
|
|
3
3
|
# file: tagcloudbase.rb
|
4
4
|
|
5
5
|
require 'dynarex'
|
6
|
+
require 'rexslt'
|
6
7
|
|
7
8
|
class TagCloudBase
|
8
9
|
|
9
10
|
attr_reader :to_dynarex
|
11
|
+
attr_accessor :xsl
|
10
12
|
|
11
13
|
def initialize(all_tags={})
|
12
14
|
tags = all_tags.sort_by {|name,count| -count.to_i}
|
@@ -15,13 +17,23 @@ class TagCloudBase
|
|
15
17
|
# sort in alphabetical order
|
16
18
|
abc_tags = tags.sort_by &:first
|
17
19
|
|
18
|
-
@to_dynarex = Dynarex.new('tags/tag(
|
20
|
+
@to_dynarex = Dynarex.new('tags/tag(word,href,gauge,count)')
|
19
21
|
abc_tags.each do |word, word_size|
|
20
22
|
weight = 100 / (biggest_tag / word_size.to_i)
|
21
23
|
gauge = (weight / 10).to_i
|
22
24
|
gauge = 8 if gauge > 8
|
23
|
-
@to_dynarex.create
|
25
|
+
@to_dynarex.create word: word, gauge: gauge.to_s, count: word_size
|
24
26
|
end
|
25
27
|
end
|
28
|
+
|
29
|
+
def to_webpage()
|
30
|
+
|
31
|
+
lib = File.dirname(__FILE__)
|
32
|
+
xsl = open(lib + '/tagcloud.xsl','UserAgent' => 'TagCloudBase').read
|
33
|
+
css = open(lib + '/tagcloud.css','UserAgent' => 'TagCloudBase').read
|
34
|
+
|
35
|
+
html = Rexslt.new(@xsl || xsl, @to_dynarex.to_xml).to_s
|
36
|
+
return {html: html, css: css}
|
37
|
+
end
|
26
38
|
|
27
|
-
end
|
39
|
+
end
|