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

@@ -1,32 +0,0 @@
class PostSetPresenter < Presenter
attr_accessor :post_set, :tag_set_presenter
def initialize(post_set)
@post_set = post_set
@tag_set_presenter = TagSetPresenter.new(RelatedTagCalculator.calculate_from_sample_to_array(@post_set.tag_string).map {|x| x[0]})
end
def posts
post_set.posts
end
def tag_list_html(template)
tag_set_presenter.tag_list_html(template)
end
def post_previews_html(template)
html = "<div class='post-previews'>"
if posts.empty?
return template.render("post_sets/blank")
end
posts.each do |post|
html << PostPresenter.preview(post)
end
html << '</div>'
html.html_safe
end
end

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)

View File

@@ -12,7 +12,7 @@ class TagSetPresenter < Presenter
def tag_list_html(template, options = {})
html = ""
html << "<ul>"
@tags.flatten.each do |tag|
@tags.each do |tag|
html << build_list_item(tag, template, options)
end
html << "</ul>"