Skip to content

Instantly share code, notes, and snippets.

@kmdsbng
Created February 24, 2010 11:41
Show Gist options
  • Save kmdsbng/313351 to your computer and use it in GitHub Desktop.
Save kmdsbng/313351 to your computer and use it in GitHub Desktop.
# will_paginateのリンク描画のみ行う
module WillPaginate
module ViewHelpers
def prepare_renderer(collection)
renderer = WillPaginate::LinkRenderer.new
options = {}.symbolize_keys.reverse_merge WillPaginate::ViewHelpers.pagination_options
renderer.prepare collection, options, self
renderer
end
def will_paginate_link_to(collection, page, text)
prepare_renderer(collection).render_link(page, text)
end
def will_paginate_link_or_span(collection, page, text, span_class='disabled_span')
prepare_renderer(collection).render_link_or_span(page, span_class, text)
end
end
class LinkRenderer
def render_link(page, text)
page_link(page, text)
end
def render_link_or_span(page, span_class, text)
page_link_or_span(page, span_class, text)
end
end
class Collection
def from_page
[1, self.current_page - 5].max
end
def to_page
[self.total_pages, self.current_page + 5].min
end
end
end
<div class="SearchNavi">-
<p class="Result">-
<span><%= posts.total_entries %>件</span>の検索結果
&nbsp;&nbsp;
<%= posts.offset + 1 %>~<%= posts.offset + posts.length %>件を表示中
</p>-
<div class="Pagination">-
<p class="Prev">-
<%= will_paginate_link_or_span posts, posts.previous_page, "&lt;&nbsp;前の#{posts.per_page}件" %>
</p>-
<ul>-
<% ((posts.from_page)..(posts.to_page)).each {|page_no| %>
<li>
<%= will_paginate_link_or_span posts, page_no, page_no %>
</li>
<% } %>
</ul>
<p class="Next">-
<%= will_paginate_link_or_span posts, posts.next_page, "次の#{posts.per_page}件&nbsp;&gt;" %>
</p>-
</div>-
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment