Class: TagCloudMaker

Inherits:
Object
  • Object
show all
Defined in:
lib/tRuTag.rb

Direct Known Subclasses

TagCloudPageMaker

Class Method Summary collapse

Class Method Details

.about(div_id) ⇒ Object



121
122
123
# File 'lib/tRuTag.rb', line 121

def TagCloudMaker.about(div_id)
	%{<div id="#{div_id}"><H2>About</H2>This page was created with the help of <a href="http://tRuTag.rubyforge.org">#{$agent}</a> an open source project created by <a href="mailto:jh[at]rubyyot[dot]com">Jamal Hansen</div>}
end

.addStyle(tag, count, phash) ⇒ Object



94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/tRuTag.rb', line 94

def TagCloudMaker.addStyle(tag, count, phash)
	style = phash.fetch('style', 'cloud')
	
	case style
		when 'sun'
			%{<span class="level#{TagCloudMaker.find_level(count)}" style="position: absolute; left:#{Integer((rand*9) * (rand*9))}%; top:#{Integer((rand*10) * (rand*10))}%;">#{yield}</span> }
		when 'pile'
			%{<span class="level#{TagCloudMaker.find_level(count)}" style="position: absolute; left:#{Integer((rand*20) + (rand*20) + (rand*20) + (rand*20))}%; top:#{Integer((rand*20) + (rand*20) + (rand*20) + (rand*20) + (rand*20))}%;">#{yield}</span> }
		when 'pile'
			%{<span class="level#{TagCloudMaker.find_level(count)}" style="position: absolute; left:#{Integer((rand*20) + (rand*20) + (rand*20) + (rand*20))}%; top:#{Integer((rand*20) + (rand*20) + (rand*20) + (rand*20) + (rand*20))}%;">#{yield}</span> }
		else
			%{<span class="level#{TagCloudMaker.find_level(count)}">#{yield}</span> }	
	end			
end

.all_tags_rails_href(tag, count, phash) ⇒ Object



86
87
88
89
90
91
92
# File 'lib/tRuTag.rb', line 86

def TagCloudMaker.all_tags_rails_href(tag, count, phash)
	if phash.has_key?(:url)
		addStyle(tag, count, phash) {%{<a href="#{phash[:url]}/#{phash[:controller]}/#{phash[:action]}/#{CGI.escapeElement(tag)}" title="#{tag} : #{count} tag(s)" rel="tag">#{tag}</a>}}
	else
		addStyle(tag, count, phash) {%{<a href="##{tag}" onclick="go('#{tag}')" title="#{tag} : #{count} tag(s)">#{tag}</a>}}
	end
end

.find_level(count) ⇒ Object



109
110
111
112
113
114
115
# File 'lib/tRuTag.rb', line 109

def TagCloudMaker.find_level(count)
	out = Integer(count)./($css_level_ratio)
	if out > $css_level_max
		out = $css_level_max
	end
	String (out)
end

.space_to_plus(input, space_replacement) ⇒ Object



117
118
119
# File 'lib/tRuTag.rb', line 117

def TagCloudMaker.space_to_plus(input, space_replacement)
	input.gsub(/ /, space_replacement)
end

.tag(name, other) ⇒ Object



82
83
84
# File 'lib/tRuTag.rb', line 82

def TagCloudMaker.tag(name, other)
	%{<#{name}#{other}>#{yield}</#{name}>}
end