added popular exploration, added order:rank

This commit is contained in:
albert
2011-08-11 15:39:51 -04:00
parent bd51079fc1
commit e42ea9c608
25 changed files with 296 additions and 61 deletions

View File

@@ -0,0 +1,21 @@
module PostSetPresenters
class Base
def posts
raise NotImplementedError
end
def post_previews_html(template)
html = ""
if posts.empty?
return template.render(:partial => "post_sets/blank")
end
posts.each do |post|
html << PostPresenter.preview(post)
end
html.html_safe
end
end
end

View File

@@ -1,7 +1,7 @@
module PostSetPresenters
class Favorite
class Favorite < Base
attr_accessor :favorite_set, :tag_set_presenter
delegate :favorites, :posts, :to => :favorite_set
delegate :favorites, :to => :favorite_set
def initialize(favorite_set)
@favorite_set = favorite_set
@@ -15,19 +15,9 @@ module PostSetPresenters
def tag_list_html(template)
tag_set_presenter.tag_list_html(template)
end
def post_previews_html(template)
html = ""
if favorites.empty?
return template.render(:partial => "post_sets/blank")
end
favorites.each do |favorite|
html << PostPresenter.preview(favorite.post)
end
html.html_safe
def posts
favorites.map(&:post)
end
end
end

View File

@@ -1,12 +1,13 @@
module PostSetPresenters
class Pool
attr_reader :tag_set_presenter, :pool_set
class Pool < Base
attr_reader :tag_set_presenter, :post_set
delegate :posts, :to => :post_set
def initialize(pool_set)
@pool_set = pool_set
def initialize(post_set)
@post_set = post_set
@tag_set_presenter = TagSetPresenter.new(
RelatedTagCalculator.calculate_from_sample_to_array(
pool_set.tag_string
post_set.tag_string
).map {|x| x[0]}
)
end
@@ -14,19 +15,5 @@ module PostSetPresenters
def tag_list_html(template)
tag_set_presenter.tag_list_html(template)
end
def post_previews_html(template)
html = ""
if pool_set.posts.empty?
return template.render(:partial => "post_sets/blank")
end
pool_set.posts.each do |post|
html << PostPresenter.preview(post)
end
html.html_safe
end
end
end

View File

@@ -0,0 +1,34 @@
module PostSetPresenters
class Popular < Base
attr_accessor :post_set, :tag_set_presenter
delegate :posts, :date, :to => :post_set
def initialize(post_set)
@post_set = post_set
end
def prev_day
date - 1
end
def next_day
date + 1
end
def prev_week
date - 7
end
def next_week
date + 7
end
def prev_month
1.month.ago(date)
end
def next_month
1.month.since(date)
end
end
end

View File

@@ -1,6 +1,7 @@
module PostSetPresenters
class Post
class Post < Base
attr_accessor :post_set, :tag_set_presenter
delegate :posts, :to => :post_set
def initialize(post_set)
@post_set = post_set
@@ -18,26 +19,8 @@ module PostSetPresenters
RelatedTagCalculator.calculate_from_sample_to_array(post_set.tag_string).map(&:first)
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 = ""
if posts.empty?
return template.render(:partial => "post_sets/blank")
end
posts.each do |post|
html << PostPresenter.preview(post)
end
html.html_safe
end
end
end