tag set presenter

This commit is contained in:
albert
2012-01-14 14:31:09 -05:00
parent bec405df95
commit 673ff02fcf
8 changed files with 37 additions and 40 deletions

View File

@@ -10,14 +10,38 @@ module PostSetPresenters
def related_tags
if post_set.is_single_tag?
tag = Tag.find_by_name(post_set.tag_string)
if tag
return tag.related_tag_array.map(&:first)
end
related_tags_for_single
elsif post_set.is_empty_tag?
popular_tags
else
related_tags_for_group
end
end
def popular_tags
n = 1
results = []
while results.empty? && n < 256
query = n.days.ago.strftime("date:>%Y-%m-%d")
results = RelatedTagCalculator.calculate_from_sample_to_array(query).map(&:first)
n *= 2
end
results
end
def related_tags_for_group
RelatedTagCalculator.calculate_from_sample_to_array(post_set.tag_string).map(&:first)
end
def related_tags_for_single
tag = Tag.find_by_name(post_set.tag_string)
if tag
return tag.related_tag_array.map(&:first)
end
end
def tag_list_html(template)
tag_set_presenter.tag_list_html(template)