2019-05-02 18:17:27 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2015-06-09 10:28:01 -04:00
|
|
|
module ListHelper
|
|
|
|
def page_links(topic)
|
|
|
|
posts = topic.posts_count
|
|
|
|
max_pages = 10
|
|
|
|
total_pages = (posts / TopicView.chunk_size) + (posts == TopicView.chunk_size ? 0 : 1)
|
|
|
|
|
|
|
|
return if total_pages < 2
|
|
|
|
|
2017-07-27 21:20:09 -04:00
|
|
|
page = [total_pages - (max_pages + 1), 2].max
|
2015-06-09 10:28:01 -04:00
|
|
|
|
|
|
|
result = "("
|
|
|
|
while page <= total_pages
|
|
|
|
result << " <a href='#{topic.relative_url}?page=#{page}'>#{page}</a> "
|
|
|
|
page += 1
|
|
|
|
end
|
|
|
|
|
|
|
|
result << ")"
|
|
|
|
result.html_safe
|
|
|
|
end
|
|
|
|
end
|