fixed upload->post converion process

This commit is contained in:
albert
2010-03-17 19:20:44 -04:00
parent ca8be10ab9
commit dcf8d0df4c
20 changed files with 346 additions and 100 deletions

View File

@@ -1,2 +1,2 @@
class PaginatorPresenter
class PaginatorPresenter < Presenter
end

View File

@@ -0,0 +1,14 @@
class PostPresenter < Presenter
def initialize(post)
@post = post
end
def tag_list_html
end
def image_html
end
def note_html
end
end

View File

@@ -1,3 +1,5 @@
require 'pp'
class PostSetPresenter < Presenter
attr_accessor :post_set
@@ -17,7 +19,80 @@ class PostSetPresenter < Presenter
""
end
def pagination_html
def pagination_html(template)
if @post_set.use_sequential_paginator?
sequential_pagination_html(template)
else
numbered_pagination_html(template)
end
end
def sequential_pagination_html(template)
html = "<menu>"
prev_url = template.request.env["HTTP_REFERER"]
next_url = template.posts_path(:tags => template.params[:tags], before_id => @post_set.posts[-1].id, :page => nil)
html << %{<li><a href="#{prev_url}">&laquo; Previous</a></li>}
if @post_set.posts.any?
html << %{<li><a href="#{next_url}">Next &raquo;</a></li>}
end
html << "</menu>"
html.html_safe
end
def numbered_pagination_html(template)
total_pages = (@post_set.count.to_f / @post_set.limit.to_f).ceil
current_page = [1, @post_set.page].max
before_current_page = current_page - 1
after_current_page = current_page + 1
html = "<menu>"
current_page_min = [1, current_page - 2].max
current_page_max = [total_pages, current_page + 2].min
if current_page == 1
# do nothing
elsif current_page_min == 1
1.upto(before_current_page) do |i|
html << numbered_pagination_item(template, i)
end
else
1.upto(3) do |i|
html << numbered_pagination_item(template, i)
end
html << "<li>...</li>"
current_page_min.upto(before_current_page) do |i|
html << numbered_pagination_item(template, i)
end
end
html << %{<li class="current-page">#{current_page}</li>}
if current_page == total_pages
# do nothing
elsif current_page_max == total_pages
after_current_page.upto(total_pages) do|i|
html << numbered_pagination_item(template, i)
end
else
after_current_page.upto(after_current_page + 2) do |i|
html << numbered_pagination_item(template, i)
end
html << "<li>...</li>"
html << numbered_pagination_item(template, total_pages)
end
html << "</menu>"
html.html_safe
end
def numbered_pagination_item(template, page)
html = "<li>"
html << template.link_to(page, template.__send__(:posts_path, :tags => template.params[:tags], :page => page))
html << "</li>"
html.html_safe
end
def post_previews_html

View File

@@ -0,0 +1,15 @@
class UploadPresenter < Presenter
def initialize(upload)
@upload = upload
end
def status(template)
case @upload.status
when /duplicate: (\d+)/
template.link_to(@upload.status, template.__send__(:post_path, $1))
else
@upload.status
end
end
end