tagcloudbase 0.1.0 → 0.1.1

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/lib/tagcloud.css ADDED
@@ -0,0 +1,23 @@
1
+ /* file: tag_cloud.css */
2
+
3
+ .tag {
4
+ font-family: Arial,'Luxi Sans', Helvetica, Impact; line-height: 2em
5
+ }
6
+ .tag a {background-color: #444; padding: 0.3em; margin: 0.9em 0.2em;}
7
+ .tag a:link {background-color: #000; color: #fff; text-decoration: none}
8
+ .tag a:visited {background-color: #555;}
9
+ .tag a:hover {background-color: #000; text-decoration: none; color: #ccc}
10
+ .tag a:active {background-color: #666;}
11
+ .tag a:focus {background-color: #666;}
12
+
13
+ .s1 { background-color: transparent; color: #123; font-size: 1.13em }
14
+ .s2 { background-color: transparent; color: #123; font-size: 1.36em }
15
+ .s3 { background-color: transparent; color: #123; font-size: 1.59em }
16
+ .s4 { background-color: transparent; color: #123; font-size: 1.82em; font-weight: 300 }
17
+ .s5 { background-color: transparent; color: #123; font-size: 2.05em; font-weight: 400 }
18
+ .s6 { background-color: transparent; color: #123; font-size: 2.28em; font-weight: 500 }
19
+ .s7 { background-color: transparent; color: #123; font-size: 2.51em; font-weight: 600 }
20
+ .s8 { background-color: transparent; color: #123; font-size: 2.74em; font-weight: 700 }
21
+ .s9 { background-color: transparent; color: #123; font-size: 2.9em; font-weight: 800 }
22
+ .s10 { background-color: transparent; color: #123; font-size: 3.2em; font-weight: 900}
23
+
data/lib/tagcloud.xsl ADDED
@@ -0,0 +1,27 @@
1
+ <?xml version="1.0"?>
2
+
3
+ <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
4
+
5
+ <xsl:template match="tags">
6
+ <xsl:apply-templates select="summary"/>
7
+ <div id="articles">
8
+ <div id="records">
9
+ <xsl:apply-templates select="records/tag">
10
+ <xsl:sort order="ascending" select="word"/>
11
+ </xsl:apply-templates>
12
+ </div>
13
+ </div></xsl:template>
14
+
15
+ <xsl:template match="summary">
16
+ <h1><xsl:value-of select="title"/></h1>
17
+ </xsl:template>
18
+
19
+ <xsl:template match="records/tag">
20
+
21
+ <span class="tag s{gauge}">
22
+ <a href="{href}"><xsl:value-of select="word"/></a>
23
+ </span><xsl:text> </xsl:text>
24
+
25
+ </xsl:template>
26
+
27
+ </xsl:stylesheet>
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(name,gauge,count)')
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 name: word, gauge: gauge.to_s, count: word_size
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
@@ -0,0 +1,27 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # file: tagcloudbase.rb
4
+
5
+ require 'dynarex'
6
+
7
+ class TagCloudBase
8
+
9
+ attr_reader :to_dynarex
10
+
11
+ def initialize(all_tags={})
12
+ tags = all_tags.sort_by {|name,count| -count.to_i}
13
+ biggest_tag = tags.first[1].to_i
14
+
15
+ # sort in alphabetical order
16
+ abc_tags = tags.sort_by &:first
17
+
18
+ @to_dynarex = Dynarex.new('tags/tag(name,gauge,count)')
19
+ abc_tags.each do |word, word_size|
20
+ weight = 100 / (biggest_tag / word_size.to_i)
21
+ gauge = (weight / 10).to_i
22
+ gauge = 8 if gauge > 8
23
+ @to_dynarex.create name: word, gauge: gauge.to_s, count: word_size
24
+ end
25
+ end
26
+
27
+ end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: tagcloudbase
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.1.0
5
+ version: 0.1.1
6
6
  platform: ruby
7
7
  authors:
8
8
  - James Robertson
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2012-04-05 00:00:00 +01:00
13
+ date: 2012-04-08 00:00:00 +01:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -24,6 +24,17 @@ dependencies:
24
24
  version: "0"
25
25
  type: :runtime
26
26
  version_requirements: *id001
27
+ - !ruby/object:Gem::Dependency
28
+ name: rexslt
29
+ prerelease: false
30
+ requirement: &id002 !ruby/object:Gem::Requirement
31
+ none: false
32
+ requirements:
33
+ - - ">="
34
+ - !ruby/object:Gem::Version
35
+ version: "0"
36
+ type: :runtime
37
+ version_requirements: *id002
27
38
  description:
28
39
  email:
29
40
  executables: []
@@ -33,7 +44,10 @@ extensions: []
33
44
  extra_rdoc_files: []
34
45
 
35
46
  files:
47
+ - lib/tagcloud.css
36
48
  - lib/tagcloudbase.rb
49
+ - lib/tagcloudbase.rb~
50
+ - lib/tagcloud.xsl
37
51
  has_rdoc: true
38
52
  homepage:
39
53
  licenses: []