Skip to content

Commit

Permalink
separated representation fom logic (moved html from tag cloud generat…
Browse files Browse the repository at this point in the history
…ion)
  • Loading branch information
5v3n committed Mar 24, 2012
1 parent b1a2b15 commit 195400f
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 15 deletions.
2 changes: 1 addition & 1 deletion .rvmrc
Original file line number Original file line Diff line number Diff line change
@@ -1 +1 @@
rvm 1.9.1@karakuri rvm 1.9.1@karakuri --create
6 changes: 4 additions & 2 deletions README.md
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -95,10 +95,12 @@ Now, you did most likely implement a tag listing on your toto blog. Congrats!
Example usage: Example usage:


<ul> <ul>
<li class="nav-header">Tags</li> <li>Tags</li>
<% Karakuri::tag_cloud(@articles).each do |tag, freq| %> <% Karakuri::tag_cloud(@articles).each do |tag, freq| %>
<% size = (10 * freq) %> <% size = (10 * freq) %>
<li style="font-size:<%= size %>px"><%= tag %></li> <li style="font-size:<%= size %>px">
<%= %|<a href="/tagged?tag=#{tag}" alt="articles concerning #{tag}" >#{tag}</a>| %>
</li>
<% end %> <% end %>
</ul> </ul>


Expand Down
19 changes: 9 additions & 10 deletions lib/karakuri.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -110,17 +110,16 @@ def Karakuri.desired_tag(query_string)
def Karakuri.tag_cloud(articles) def Karakuri.tag_cloud(articles)
tag_cloud = {} tag_cloud = {}
if(articles) if(articles)
articles.select do |a| articles.select do |article|
tags = csv_to_array(a[:tags]) tags = csv_to_array(article[:tags])
if tags if tags
tags.each { |tag| tags.each do |tag|
tag_string = %&<a href="/tagged?tag=#{tag}" alt="articles concerning #{tag}" >#{tag}</a>& if tag_cloud.has_key? tag
if tag_cloud.has_key? tag_string tag_cloud[tag] += 1
tag_cloud[tag_string] += 1 else
else tag_cloud[tag] = 1
tag_cloud[tag_string] = 1 end
end end
}
end end
end end
end end
Expand Down
3 changes: 1 addition & 2 deletions test/karakuri_test.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -132,8 +132,7 @@ def test_tag_cloud


#test tags #test tags
tags = result.keys tags = result.keys
expected_tags = [ '<a href="/tagged?tag=tag_1" alt="articles concerning tag_1" >tag_1</a>', '<a href="/tagged?tag=tag_2" alt="articles concerning tag_2" >tag_2</a>', expected_tags = %w[ tag_1 tag_2 tag_3]
'<a href="/tagged?tag=tag_3" alt="articles concerning tag_3" >tag_3</a>']


assert(tags != nil && tags - expected_tags == [], "Wrong extracted tags. Expected #{expected_tags}, but was #{tags}") assert(tags != nil && tags - expected_tags == [], "Wrong extracted tags. Expected #{expected_tags}, but was #{tags}")


Expand Down

0 comments on commit 195400f

Please sign in to comment.