Permalink
Browse files

separated representation fom logic (moved html from tag cloud generat…

…ion)
  • Loading branch information...
1 parent b1a2b15 commit 195400fb3e7e860c8b5a5b292289e04597661c7e @5v3n committed Mar 24, 2012
Showing with 15 additions and 15 deletions.
  1. +1 −1 .rvmrc
  2. +4 −2 README.md
  3. +9 −10 lib/karakuri.rb
  4. +1 −2 test/karakuri_test.rb
View
2 .rvmrc
@@ -1 +1 @@
-rvm 1.9.1@karakuri
+rvm 1.9.1@karakuri --create
View
@@ -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>
View
@@ -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
View
@@ -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}")

0 comments on commit 195400f

Please sign in to comment.