module Awestruct::Extensions::Paginator::Paginated
Attributes
current_page[RW]
current_page_index[RW]
next_page[RW]
pages[RW]
previous_page[RW]
window[RW]
Public Instance Methods
links()
click to toggle source
# File lib/awestruct/extensions/paginator.rb, line 13 def links html = %Q(<div class="pagination-links">) unless ( previous_page.nil? ) html += %Q(<a href="#{previous_page.url}" class="previous-link">Previous</a> ) end first_skip = false second_skip = false pages.each_with_index do |page, i| if ( i == current_page_index ) html += %Q(<span class="current-page">#{i+1}</span> ) elsif ( i <= window ) html += %Q(<a href="#{page.url}" class="page-link">#{i+1}</a> ) elsif ( ( i > window ) && ( i < ( current_page_index - window ) ) && ! first_skip ) html += %Q(<span class="skip">...</span>) first_skip = true elsif ( ( i > ( current_page_index + window ) ) && ( i < ( ( pages.size - window ) - 1 ) ) && ! second_skip ) html += %Q(<span class="skip">...</span>) second_skip = true elsif ( ( i >= ( current_page_index - window ) ) && ( i <= ( current_page_index + window ) ) ) html += %Q(<a href="#{page.url}" class="page-link">#{i+1}</a> ) elsif ( i >= ( ( pages.size - window ) - 1 ) ) html += %Q(<a href="#{page.url}" class="page-link">#{i+1}</a> ) end end unless ( next_page.nil? ) html += %Q(<a href="#{next_page.url}" class="next-link">Next</a> ) end html += %Q(</div>) html end