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
@@ -1 +1 @@
rvm 1.9.1@karakuri
rvm 1.9.1@karakuri --create
6 changes: 4 additions & 2 deletions README.md
Expand Up @@ -95,10 +95,12 @@ Now, you did most likely implement a tag listing on your toto blog. Congrats!
Example usage:

<ul>
<li class="nav-header">Tags</li>
<li>Tags</li>
<% Karakuri::tag_cloud(@articles).each do |tag, 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 %>
</ul>

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

#test tags
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>',
'<a href="/tagged?tag=tag_3" alt="articles concerning tag_3" >tag_3</a>']
expected_tags = %w[ tag_1 tag_2 tag_3]

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.